forked from streamrail/vast-1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
offset_test.go
39 lines (33 loc) · 1001 Bytes
/
offset_test.go
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
package vast
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("Offset", func() {
DescribeTable("marshal",
func(o *Offset, exp string) {
b, err := o.MarshalText()
Expect(err).NotTo(HaveOccurred())
Expect(string(b)).To(Equal(exp))
},
Entry("0%", &Offset{}, "0%"),
Entry("10%", &Offset{Percent: 0.1}, "10%"),
Entry("00:00:00", &Offset{Duration: durationPtr(0)}, "00:00:00"),
)
DescribeTable("unmarshal",
func(s string, pc float64, dur *Duration) {
o := Offset{}
Expect(o.UnmarshalText([]byte(s))).To(Succeed())
Expect(o.Percent).To(BeNumerically("~", pc, 0.001))
Expect(o.Duration).To(Equal(dur))
},
Entry("0%", "0%", 0.0, nil),
Entry("10%", "10%", 0.1, nil),
Entry("00:00:00", "00:00:00", 0.0, durationPtr(0)),
)
It("should fail to unmarshal bad inputs", func() {
o := new(Offset)
Expect(o.UnmarshalText([]byte("abc%"))).To(MatchError("invalid offset: abc%"))
})
})