initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / be_temporally_matcher_test.go
1 package matchers_test
2
3 import (
4         . "github.com/onsi/ginkgo"
5         . "github.com/onsi/gomega"
6         . "github.com/onsi/gomega/matchers"
7         "time"
8 )
9
10 var _ = Describe("BeTemporally", func() {
11
12         var t0, t1, t2 time.Time
13         BeforeEach(func() {
14                 t0 = time.Now()
15                 t1 = t0.Add(time.Second)
16                 t2 = t0.Add(-time.Second)
17         })
18
19         Context("When comparing times", func() {
20
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{}))
26                 })
27
28                 It("should support >", func() {
29                         Ω(t0).Should(BeTemporally(">", t2))
30                         Ω(t0).ShouldNot(BeTemporally(">", t0))
31                         Ω(t2).ShouldNot(BeTemporally(">", t0))
32                 })
33
34                 It("should support <", func() {
35                         Ω(t0).Should(BeTemporally("<", t1))
36                         Ω(t0).ShouldNot(BeTemporally("<", t0))
37                         Ω(t1).ShouldNot(BeTemporally("<", t0))
38                 })
39
40                 It("should support >=", func() {
41                         Ω(t0).Should(BeTemporally(">=", t2))
42                         Ω(t0).Should(BeTemporally(">=", t0))
43                         Ω(t0).ShouldNot(BeTemporally(">=", t1))
44                 })
45
46                 It("should support <=", func() {
47                         Ω(t0).Should(BeTemporally("<=", t1))
48                         Ω(t0).Should(BeTemporally("<=", t0))
49                         Ω(t0).ShouldNot(BeTemporally("<=", t2))
50                 })
51
52                 Context("when passed ~", func() {
53                         Context("and there is no precision parameter", func() {
54                                 BeforeEach(func() {
55                                         t1 = t0.Add(time.Millisecond / 2)
56                                         t2 = t0.Add(-2 * time.Millisecond)
57                                 })
58                                 It("should approximate", func() {
59                                         Ω(t0).Should(BeTemporally("~", t0))
60                                         Ω(t0).Should(BeTemporally("~", t1))
61                                         Ω(t0).ShouldNot(BeTemporally("~", t2))
62                                 })
63                         })
64
65                         Context("and there is a precision parameter", func() {
66                                 BeforeEach(func() {
67                                         t2 = t0.Add(3 * time.Second)
68                                 })
69                                 It("should use precision paramter", func() {
70                                         d := 2 * time.Second
71                                         Ω(t0).Should(BeTemporally("~", t0, d))
72                                         Ω(t0).Should(BeTemporally("~", t1, d))
73                                         Ω(t0).ShouldNot(BeTemporally("~", t2, d))
74                                 })
75                         })
76                 })
77         })
78
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())
84
85                         success, err = (&BeTemporallyMatcher{Comparator: "=="}).Match(nil)
86                         Ω(success).Should(BeFalse())
87                         Ω(err).Should(HaveOccurred())
88                 })
89         })
90
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())
96                 })
97         })
98 })