-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_test.go
More file actions
91 lines (84 loc) · 2.36 KB
/
Copy pathbuild_test.go
File metadata and controls
91 lines (84 loc) · 2.36 KB
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
package icalendar
import (
"strings"
"testing"
"time"
)
func TestSerializeRoundTrip(t *testing.T) {
start := time.Date(2026, 5, 1, 9, 0, 0, 0, time.UTC)
orig := &Event{
UID: "rt@example.com",
Summary: "Roundtrip",
Description: "desc",
Location: "Room 1",
Start: start,
End: start.Add(time.Hour),
Organizer: "alice@example.com",
Status: string(StatusConfirmed),
Attendees: []Attendee{
{Email: "bob@example.com", Name: "Bob", PartStat: PartStatNeedsAction, RSVP: true},
},
}
data, err := NewRequest(orig).Serialize()
if err != nil {
t.Fatalf("Serialize: %v", err)
}
if !strings.Contains(string(data), "METHOD:REQUEST") {
t.Error("missing METHOD:REQUEST")
}
got, err := ParseICS(data)
if err != nil {
t.Fatalf("ParseICS: %v", err)
}
if got.UID != orig.UID || got.Summary != orig.Summary || got.Location != orig.Location {
t.Errorf("fields lost: %+v", got)
}
if !got.Start.Equal(orig.Start) || !got.End.Equal(orig.End) {
t.Errorf("times changed: %v–%v", got.Start, got.End)
}
if got.Organizer != orig.Organizer {
t.Errorf("Organizer = %q", got.Organizer)
}
if len(got.Attendees) != 1 || got.Attendees[0].Email != "bob@example.com" {
t.Errorf("attendees = %+v", got.Attendees)
}
}
func TestNewCancel(t *testing.T) {
ev := &Event{UID: "c@x", Summary: "Gone", Sequence: 2,
Start: time.Date(2026, 5, 1, 9, 0, 0, 0, time.UTC)}
data, err := NewCancel(ev).Serialize()
if err != nil {
t.Fatalf("Serialize: %v", err)
}
s := string(data)
if !strings.Contains(s, "METHOD:CANCEL") {
t.Error("missing METHOD:CANCEL")
}
if !strings.Contains(s, "STATUS:CANCELLED") {
t.Error("missing STATUS:CANCELLED")
}
if !strings.Contains(s, "SEQUENCE:3") {
t.Error("SEQUENCE not bumped to 3")
}
}
func TestSerializeAllDay(t *testing.T) {
ev := &Event{
UID: "ad@x",
Summary: "Holiday",
AllDay: true,
Start: time.Date(2026, 7, 4, 0, 0, 0, 0, time.UTC),
End: time.Date(2026, 7, 5, 0, 0, 0, 0, time.UTC),
}
data, err := NewCalendar().Add(ev).Serialize()
if err != nil {
t.Fatalf("Serialize: %v", err)
}
if !strings.Contains(string(data), "VALUE=DATE:20260704") {
t.Errorf("all-day DTSTART not date-only:\n%s", data)
}
}
func TestSerializeRequiresUID(t *testing.T) {
if _, err := NewCalendar().Add(&Event{Summary: "no uid"}).Serialize(); err == nil {
t.Error("want error for missing UID")
}
}