/usr/share/gocode/src/github.com/onsi/gomega/matchers/be_temporally_matcher_test.go is in golang-gomega-dev 1.0+git20160910.d59fa0a-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | package matchers_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/matchers"
"time"
)
var _ = Describe("BeTemporally", func() {
var t0, t1, t2 time.Time
BeforeEach(func() {
t0 = time.Now()
t1 = t0.Add(time.Second)
t2 = t0.Add(-time.Second)
})
Context("When comparing times", func() {
It("should support ==", func() {
Ω(t0).Should(BeTemporally("==", t0))
Ω(t1).ShouldNot(BeTemporally("==", t0))
Ω(t0).ShouldNot(BeTemporally("==", t1))
Ω(t0).ShouldNot(BeTemporally("==", time.Time{}))
})
It("should support >", func() {
Ω(t0).Should(BeTemporally(">", t2))
Ω(t0).ShouldNot(BeTemporally(">", t0))
Ω(t2).ShouldNot(BeTemporally(">", t0))
})
It("should support <", func() {
Ω(t0).Should(BeTemporally("<", t1))
Ω(t0).ShouldNot(BeTemporally("<", t0))
Ω(t1).ShouldNot(BeTemporally("<", t0))
})
It("should support >=", func() {
Ω(t0).Should(BeTemporally(">=", t2))
Ω(t0).Should(BeTemporally(">=", t0))
Ω(t0).ShouldNot(BeTemporally(">=", t1))
})
It("should support <=", func() {
Ω(t0).Should(BeTemporally("<=", t1))
Ω(t0).Should(BeTemporally("<=", t0))
Ω(t0).ShouldNot(BeTemporally("<=", t2))
})
Context("when passed ~", func() {
Context("and there is no precision parameter", func() {
BeforeEach(func() {
t1 = t0.Add(time.Millisecond / 2)
t2 = t0.Add(-2 * time.Millisecond)
})
It("should approximate", func() {
Ω(t0).Should(BeTemporally("~", t0))
Ω(t0).Should(BeTemporally("~", t1))
Ω(t0).ShouldNot(BeTemporally("~", t2))
})
})
Context("and there is a precision parameter", func() {
BeforeEach(func() {
t2 = t0.Add(3 * time.Second)
})
It("should use precision paramter", func() {
d := 2 * time.Second
Ω(t0).Should(BeTemporally("~", t0, d))
Ω(t0).Should(BeTemporally("~", t1, d))
Ω(t0).ShouldNot(BeTemporally("~", t2, d))
})
})
})
})
Context("when passed a non-time", func() {
It("should error", func() {
success, err := (&BeTemporallyMatcher{Comparator: "==", CompareTo: t0}).Match("foo")
Ω(success).Should(BeFalse())
Ω(err).Should(HaveOccurred())
success, err = (&BeTemporallyMatcher{Comparator: "=="}).Match(nil)
Ω(success).Should(BeFalse())
Ω(err).Should(HaveOccurred())
})
})
Context("when passed an unsupported comparator", func() {
It("should error", func() {
success, err := (&BeTemporallyMatcher{Comparator: "!=", CompareTo: t0}).Match(t2)
Ω(success).Should(BeFalse())
Ω(err).Should(HaveOccurred())
})
})
})
|