summaryrefslogtreecommitdiff
path: root/internal/state_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/state_test.go')
-rw-r--r--internal/state_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/internal/state_test.go b/internal/state_test.go
new file mode 100644
index 0000000..aacc023
--- /dev/null
+++ b/internal/state_test.go
@@ -0,0 +1,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)
+ }
+}