forked from crewjam/saml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_test.go
57 lines (47 loc) · 1.51 KB
/
time_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
package saml
import (
"time"
. "gopkg.in/check.v1"
)
var _ = Suite(&TimeTest{})
type TimeTest struct {
}
func (test *TimeTest) TestFormat(c *C) {
t := time.Date(1981, 02, 03, 14, 15, 16, 17, time.UTC)
c.Assert(RelaxedTime(t).String(), Equals, "1981-02-03T14:15:16Z")
buf, err := RelaxedTime(t).MarshalText()
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, "1981-02-03T14:15:16Z")
loc, err := time.LoadLocation("America/New_York")
c.Assert(err, IsNil)
t = time.Date(1981, 02, 03, 9, 15, 16, 17, loc)
c.Assert(RelaxedTime(t).String(), Equals, "1981-02-03T14:15:16Z")
buf, err = RelaxedTime(t).MarshalText()
c.Assert(err, IsNil)
c.Assert(string(buf), Equals, "1981-02-03T14:15:16Z")
}
func (test *TimeTest) TestParse(c *C) {
{
var t RelaxedTime
err := t.UnmarshalText([]byte("1981-02-03T14:15:16Z"))
c.Assert(err, IsNil)
c.Assert(t, DeepEquals, RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 0, time.UTC)))
}
{
var t RelaxedTime
err := t.UnmarshalText([]byte("1981-02-03T14:15:16.178901234Z"))
c.Assert(err, IsNil)
c.Assert(t, DeepEquals, RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 179000000, time.UTC)))
}
{
var t RelaxedTime
err := t.UnmarshalText([]byte("1981-02-03T14:15:16.1717Z"))
c.Assert(err, IsNil)
c.Assert(t, DeepEquals, RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 172000000, time.UTC)))
}
{
var t RelaxedTime
err := t.UnmarshalText([]byte("1981-02-03T14:15:16Z04:00"))
c.Assert(err, ErrorMatches, "parsing time \"1981-02-03T14:15:16Z04:00\": extra text: 04:00")
}
}