4 . "github.com/onsi/ginkgo"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/matchers"
10 var _ = Describe("BeTemporally", func() {
12 var t0, t1, t2 time.Time
15 t1 = t0.Add(time.Second)
16 t2 = t0.Add(-time.Second)
19 Context("When comparing times", func() {
21 It("should support ==", func() {
22 Ω(t0).Should(BeTemporally("==", t0))
23 Ω(t1).ShouldNot(BeTemporally("==", t0))
24 Ω(t0).ShouldNot(BeTemporally("==", t1))
25 Ω(t0).ShouldNot(BeTemporally("==", time.Time{}))
28 It("should support >", func() {
29 Ω(t0).Should(BeTemporally(">", t2))
30 Ω(t0).ShouldNot(BeTemporally(">", t0))
31 Ω(t2).ShouldNot(BeTemporally(">", t0))
34 It("should support <", func() {
35 Ω(t0).Should(BeTemporally("<", t1))
36 Ω(t0).ShouldNot(BeTemporally("<", t0))
37 Ω(t1).ShouldNot(BeTemporally("<", t0))
40 It("should support >=", func() {
41 Ω(t0).Should(BeTemporally(">=", t2))
42 Ω(t0).Should(BeTemporally(">=", t0))
43 Ω(t0).ShouldNot(BeTemporally(">=", t1))
46 It("should support <=", func() {
47 Ω(t0).Should(BeTemporally("<=", t1))
48 Ω(t0).Should(BeTemporally("<=", t0))
49 Ω(t0).ShouldNot(BeTemporally("<=", t2))
52 Context("when passed ~", func() {
53 Context("and there is no precision parameter", func() {
55 t1 = t0.Add(time.Millisecond / 2)
56 t2 = t0.Add(-2 * time.Millisecond)
58 It("should approximate", func() {
59 Ω(t0).Should(BeTemporally("~", t0))
60 Ω(t0).Should(BeTemporally("~", t1))
61 Ω(t0).ShouldNot(BeTemporally("~", t2))
65 Context("and there is a precision parameter", func() {
67 t2 = t0.Add(3 * time.Second)
69 It("should use precision paramter", func() {
71 Ω(t0).Should(BeTemporally("~", t0, d))
72 Ω(t0).Should(BeTemporally("~", t1, d))
73 Ω(t0).ShouldNot(BeTemporally("~", t2, d))
79 Context("when passed a non-time", func() {
80 It("should error", func() {
81 success, err := (&BeTemporallyMatcher{Comparator: "==", CompareTo: t0}).Match("foo")
82 Ω(success).Should(BeFalse())
83 Ω(err).Should(HaveOccurred())
85 success, err = (&BeTemporallyMatcher{Comparator: "=="}).Match(nil)
86 Ω(success).Should(BeFalse())
87 Ω(err).Should(HaveOccurred())
91 Context("when passed an unsupported comparator", func() {
92 It("should error", func() {
93 success, err := (&BeTemporallyMatcher{Comparator: "!=", CompareTo: t0}).Match(t2)
94 Ω(success).Should(BeFalse())
95 Ω(err).Should(HaveOccurred())