forked from rickb777/period
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_test.go
58 lines (48 loc) · 1.25 KB
/
sql_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2015 Rick Beton. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package period
import (
"database/sql/driver"
"fmt"
"testing"
. "github.com/onsi/gomega"
)
func TestPeriodScan(t *testing.T) {
g := NewGomegaWithT(t)
cases := []struct {
v interface{}
expected Period
}{
{[]byte("P1Y3M"), MustParse("P1Y3M")},
{"P1Y3M", MustParse("P1Y3M")},
{[]byte("P48M"), MustParse("P48M")},
{"P48M", MustParse("P48M")},
{"P1YT-1S", MustParse("P1YT-1S")},
}
for i, c := range cases {
t.Run(fmt.Sprintf("%d %s", i, c.expected), func(t *testing.T) {
r := new(Period)
e := r.Scan(c.v)
g.Expect(e).NotTo(HaveOccurred())
g.Expect(*r).To(Equal(c.expected))
var d driver.Valuer = *r
q, e := d.Value()
g.Expect(e).NotTo(HaveOccurred())
g.Expect(q.(string)).To(Equal(c.expected.String()))
})
}
}
func TestPeriodScan_nil_value(t *testing.T) {
g := NewGomegaWithT(t)
r := new(Period)
e := r.Scan(nil)
g.Expect(e).NotTo(HaveOccurred())
}
func TestPeriodScan_problem_type(t *testing.T) {
g := NewGomegaWithT(t)
r := new(Period)
e := r.Scan(1)
g.Expect(e).To(HaveOccurred())
g.Expect(e.Error()).To(ContainSubstring("not a meaningful period"))
}