-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathics_test.go
95 lines (89 loc) · 1.84 KB
/
ics_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
package export
import (
"bytes"
"testing"
"github.com/orltom/on-call-schedule/pkg/apis"
)
func TestICSExporter_Write(t *testing.T) {
type args struct {
plan []apis.Shift
}
tests := []struct {
name string
args args
wantWriter string
wantErr bool
}{
{
name: "When plan is nil, throw an error",
args: args{
plan: nil,
},
wantWriter: "",
wantErr: true,
},
{
name: "Print ICS result according shift plan",
args: args{
plan: []apis.Shift{
{
Start: date("2024-12-25"),
End: date("2024-12-26"),
Primary: "a",
Secondary: "b",
},
},
},
wantWriter: `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//ocsctl//on-call-shift//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:primary-20241225
DTSTART:20241225T000000Z
DTEND:20241226T000000Z
SUMMARY:Primary On-Call: a
DESCRIPTION:Primary: a\nSecondary: b
CATEGORIES:Primary
ATTENDEE:mailto:a
X-COLOR:#FF5733
BEGIN:VALARM
TRIGGER:-PT8H
ACTION:DISPLAY
DESCRIPTION:Reminder: Primary On-Call: a starts in 8 hours.
END:VALARM
END:VEVENT
BEGIN:VEVENT
UID:secondary-20241225
DTSTART:20241225T000000Z
DTEND:20241226T000000Z
SUMMARY:Secondary On-Call: b
DESCRIPTION:Primary: a\nSecondary: b
CATEGORIES:Secondary
ATTENDEE:mailto:b
X-COLOR:#33FF57
BEGIN:VALARM
TRIGGER:-PT8H
ACTION:DISPLAY
DESCRIPTION:Reminder: Secondary On-Call: b starts in 8 hours.
END:VALARM
END:VEVENT
END:VCALENDAR`,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e := NewICSExporter()
writer := &bytes.Buffer{}
err := e.Write(tt.args.plan, writer)
if (err != nil) != tt.wantErr {
t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotWriter := writer.String(); gotWriter != tt.wantWriter {
t.Errorf("Write() gotWriter = %v, want %v", gotWriter, tt.wantWriter)
}
})
}
}