From cf03bc587ca6a94c1bba748fd39d0158e1de4a59 Mon Sep 17 00:00:00 2001 From: Michal Schott Date: Tue, 5 May 2020 22:37:18 +0200 Subject: [PATCH] Adding unit tests for ttlExpired. --- pkg/daemonsetlock/daemonsetlock_test.go | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pkg/daemonsetlock/daemonsetlock_test.go diff --git a/pkg/daemonsetlock/daemonsetlock_test.go b/pkg/daemonsetlock/daemonsetlock_test.go new file mode 100644 index 0000000..3afd57e --- /dev/null +++ b/pkg/daemonsetlock/daemonsetlock_test.go @@ -0,0 +1,28 @@ +package daemonsetlock + +import ( + "testing" + "time" +) + +func TestTtlExpired(t *testing.T) { + d := time.Date(2020, 05, 05, 14, 15, 0, 0, time.UTC) + second, _ := time.ParseDuration("1s") + zero, _ := time.ParseDuration("0m") + + tests := []struct { + created time.Time + ttl time.Duration + result bool + }{ + {d, second, true}, + {time.Now(), second, false}, + {d, zero, false}, + } + + for i, tst := range tests { + if ttlExpired(tst.created, tst.ttl) != tst.result { + t.Errorf("Test %d failed, expected %v but got %v", i, tst.result, !tst.result) + } + } +}