summaryrefslogtreecommitdiff
path: root/internal/state_test.go
blob: aacc02373afaaed630c1a367ebebd436c2f9e97d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package internal

import (
	"testing"
	"time"
)

func TestAge(t *testing.T) {
	state := state{checks: make(map[string]checkState)}

	state.checks["Check Foo"] = checkState{Epoch: 0}
	minAge := time.Duration(time.Now().Unix())

	if reportedAge := state.age("Check Foo"); reportedAge < minAge {
		t.Errorf("expected age >= %v, got %v", minAge, reportedAge)
	}

	maxAge := time.Duration(time.Now().Unix())
	state.checks["Check Bar"] = checkState{Epoch: time.Now().Unix()}

	if reportedAge := state.age("Check Bar"); reportedAge >= minAge {
		t.Errorf("expected age < %v, got %v", maxAge, reportedAge)
	}
}