blob: 1b2945a2166e10862937adae684d0eab042be50a [file] [log] [blame]
Serge Bazanski8ef457f2021-07-11 14:42:38 +00001package calendar
2
3import (
4 "os"
5 "testing"
6 "time"
7
8 "github.com/google/go-cmp/cmp"
9)
10
11func TestUpcomingEvents(t *testing.T) {
12 r, err := os.Open("test.ical")
13 if err != nil {
14 t.Fatalf("Could not open test ical: %v", err)
15 }
16 ti := time.Unix(1626011785, 0)
17
18 events, err := parseUpcomingEvents(ti, r)
19 if err != nil {
20 t.Fatalf("getUpcomingEvents: %v", err)
21 }
22
23 want := []*UpcomingEvent{
24 {
Serge Bazanski717aad42021-07-11 16:03:43 +000025 UID: "65cd51ba-2fd7-475e-a274-61d19c186b66",
26 Summary: "test event please ignore",
27 Description: "I am a description",
Serge Bazanski8ef457f2021-07-11 14:42:38 +000028 Start: &EventTime{
29 Time: time.Unix(1626091200, 0),
30 },
31 End: &EventTime{
32 Time: time.Unix(1626093000, 0),
33 },
34 },
35 {
Serge Bazanski717aad42021-07-11 16:03:43 +000036 UID: "2f874784-1e09-4cdc-8ae6-185c9ee36be0",
37 Summary: "many days",
38 Description: "I am a multiline\n\ndescription\n\nwith a link: https://example.com/foo\n\nbarfoo",
Serge Bazanski8ef457f2021-07-11 14:42:38 +000039 Start: &EventTime{
40 Time: time.Unix(1626134400, 0),
41 WholeDay: true,
42 },
43 End: &EventTime{
44 Time: time.Unix(1626393600, 0),
45 WholeDay: true,
46 },
47 },
48 }
49
50 if diff := cmp.Diff(events, want); diff != "" {
51 t.Errorf("%s", diff)
52 }
53}