forked from arran4/golang-ical
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents_test.go
110 lines (96 loc) · 2.22 KB
/
components_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
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
99
100
101
102
103
104
105
106
107
108
109
110
package ics
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestSetDuration(t *testing.T) {
date, _ := time.Parse(time.RFC822, time.RFC822)
duration := time.Duration(float64(time.Hour) * 2)
testCases := []struct {
name string
start time.Time
end time.Time
output string
}{
{
name: "test set duration - start",
start: date,
output: `BEGIN:VEVENT
UID:test-duration
DTSTART:20060102T150400Z
DTEND:20060102T170400Z
END:VEVENT
`,
},
{
name: "test set duration - end",
end: date,
output: `BEGIN:VEVENT
UID:test-duration
DTEND:20060102T150400Z
DTSTART:20060102T130400Z
END:VEVENT
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := NewEvent("test-duration")
if !tc.start.IsZero() {
e.SetStartAt(tc.start)
}
if !tc.end.IsZero() {
e.SetEndAt(tc.end)
}
err := e.SetDuration(duration)
// we're not testing for encoding here so lets make the actual output line breaks == expected line breaks
text := strings.Replace(e.Serialize(), "\r\n", "\n", -1)
assert.Equal(t, tc.output, text)
assert.Equal(t, nil, err)
})
}
}
func TestSetAllDay(t *testing.T) {
date, _ := time.Parse(time.RFC822, time.RFC822)
testCases := []struct {
name string
start time.Time
end time.Time
output string
}{
{
name: "test set duration - start",
start: date,
output: `BEGIN:VEVENT
UID:test-duration
DTSTART;VALUE=DATE:20060102
DTEND;VALUE=DATE:20060103
END:VEVENT
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := NewEvent("test-duration")
e.SetAllDayStartAt(date)
e.SetAllDayEndAt(date.AddDate(0, 0, 1))
// we're not testing for encoding here so lets make the actual output line breaks == expected line breaks
text := strings.Replace(e.Serialize(), "\r\n", "\n", -1)
assert.Equal(t, tc.output, text)
})
}
}
func TestGetLastModifiedAt(t *testing.T) {
e := NewEvent("test-last-modified")
lastModified := time.Unix(123456789, 0)
e.SetLastModifiedAt(lastModified)
got, err := e.GetLastModifiedAt()
if err != nil {
t.Fatalf("e.GetLastModifiedAt: %v", err)
}
if !got.Equal(lastModified) {
t.Errorf("got last modified = %q, want %q", got, lastModified)
}
}