Serge Bazanski | 8ef457f | 2021-07-11 14:42:38 +0000 | [diff] [blame] | 1 | package calendar |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/google/go-cmp/cmp" |
| 9 | ) |
| 10 | |
| 11 | func 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 Bazanski | 717aad4 | 2021-07-11 16:03:43 +0000 | [diff] [blame] | 25 | UID: "65cd51ba-2fd7-475e-a274-61d19c186b66", |
| 26 | Summary: "test event please ignore", |
| 27 | Description: "I am a description", |
Serge Bazanski | 8ef457f | 2021-07-11 14:42:38 +0000 | [diff] [blame] | 28 | Start: &EventTime{ |
| 29 | Time: time.Unix(1626091200, 0), |
| 30 | }, |
| 31 | End: &EventTime{ |
| 32 | Time: time.Unix(1626093000, 0), |
| 33 | }, |
| 34 | }, |
| 35 | { |
Serge Bazanski | 717aad4 | 2021-07-11 16:03:43 +0000 | [diff] [blame] | 36 | 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 Bazanski | 8ef457f | 2021-07-11 14:42:38 +0000 | [diff] [blame] | 39 | 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 | } |