-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathparse_test.go
725 lines (592 loc) · 19.8 KB
/
parse_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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
package ics
import (
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"
"time"
)
func TestLoadCalendar(t *testing.T) {
parser := New()
calBytes, err := ioutil.ReadFile("testCalendars/2eventsCal.ics")
if err != nil {
t.Errorf("Failed to read calendar file ( %s )", err)
}
parser.Load(string(calBytes))
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
for i, pErr := range parseErrors {
t.Errorf("Parsing Error №%d: %s", i, pErr)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
}
}
func TestNewParser(t *testing.T) {
parser := New()
rType := fmt.Sprintf("%v", reflect.TypeOf(parser))
if rType != "*ics.Parser" {
t.Errorf("Failed to create a Parser !")
}
}
func TestNewParserChans(t *testing.T) {
parser := New()
input := parser.GetInputChan()
output := parser.GetOutputChan()
rType := fmt.Sprintf("%v", reflect.TypeOf(input))
if rType != "chan string" {
t.Errorf("Failed to create a input chan! Received: Type %s Value %v", rType, input)
}
rType = fmt.Sprintf("%v", reflect.TypeOf(output))
if rType != "chan *ics.Event" {
t.Errorf("Failed to create a output chan! Received: Type %s Value %v", rType, output)
}
}
func TestParsing0Calendars(t *testing.T) {
parser := New()
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
for i, pErr := range parseErrors {
t.Errorf("Parsing Error №%d: %s", i, pErr)
}
}
func TestParsing1Calendars(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/2eventsCal.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
for i, pErr := range parseErrors {
t.Errorf("Parsing Error №%d: %s", i, pErr)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
}
}
func TestParsing2Calendars(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/2eventsCal.ics"
input <- "testCalendars/3eventsNoAttendee.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
for i, pErr := range parseErrors {
t.Errorf("Parsing Error №%d: %s", i, pErr)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 2 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
}
}
func TestParsingNotExistingCalendar(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/notFound.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 1 {
t.Errorf("Expected 1 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
}
func TestParsingNotExistingAndExistingCalendars(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/3eventsNoAttendee.ics"
input <- "testCalendars/notFound.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 1 {
t.Errorf("Expected 1 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
}
}
func TestParsingWrongCalendarUrls(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "http://localhost/goTestFails"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 1 {
t.Errorf("Expected 1 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 0 {
t.Errorf("Expected 0 calendar, found %d calendars", len(calendars))
}
}
func TestCreatingTempDir(t *testing.T) {
FilePath = "testingTempDir/"
parser := New()
input := parser.GetInputChan()
input <- "https://www.google.com/calendar/ical/yordanpulov%40gmail.com/private-81525ac0eb14cdc2e858c15e1b296a1c/basic.ics"
parser.Wait()
_, err := os.Stat(FilePath)
if err != nil {
t.Errorf("Failed to create %s", FilePath)
}
// remove the new dir
os.Remove(FilePath)
// return the var to default
FilePath = "tmp/"
}
func TestCalendarInfo(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/2eventsCal.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
return
}
calendar := calendars[0]
if calendar.GetName() != "2 Events Cal" {
t.Errorf("Expected name '%s' calendar, got '%s' calendars", "2 Events Cal", calendar.GetName())
}
if calendar.GetDesc() != "The cal has 2 events(1st with attendees and second without)" {
t.Errorf("Expected description '%s' calendar, got '%s' calendars", "The cal has 2 events(1st with attendees and second without)", calendar.GetDesc())
}
if calendar.GetVersion() != 2.0 {
t.Errorf("Expected version %v calendar, got %v calendars", 2.0, calendar.GetVersion())
}
events := calendar.GetEvents()
if len(events) != 2 {
t.Errorf("Expected %d events in calendar, got %d events", 2, len(events))
}
eventsByDates := calendar.GetEventsByDates()
if len(eventsByDates) != 2 {
t.Errorf("Expected %d events by date in calendar, got %d events", 2, len(eventsByDates))
}
geometryExamIcsFormat, errICS := time.Parse(IcsFormat, "20140616T060000Z")
if err != nil {
t.Errorf("(ics time format) Unexpected error %s", errICS)
}
geometryExamYmdHis, errYMD := time.Parse(YmdHis, "2014-06-16 06:00:00")
if err != nil {
t.Errorf("(YmdHis time format) Unexpected error %s", errYMD)
}
eventsByDate, err := calendar.GetEventsByDate(geometryExamIcsFormat)
if err != nil {
t.Errorf("(ics time format) Unexpected error %s", err)
}
if len(eventsByDate) != 1 {
t.Errorf("(ics time format) Expected %d events in calendar for the date 2014-06-16, got %d events", 1, len(eventsByDate))
}
eventsByDate, err = calendar.GetEventsByDate(geometryExamYmdHis)
if err != nil {
t.Errorf("(YmdHis time format) Unexpected error %s", err)
}
if len(eventsByDate) != 1 {
t.Errorf("(YmdHis time format) Expected %d events in calendar for the date 2014-06-16, got %d events", 1, len(eventsByDate))
}
}
func TestOutlookCalendarEventTimes(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/outlook.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Fatalf("Failed to retrieve calendars: %s", err.Error())
}
if len(calendars) < 1 {
t.Fatalf("The test calendar file should have at least included one calendar")
}
evts := calendars[0].GetEvents()
if len(evts) < 1 {
t.Fatalf("The test calendar should have included at least one event")
}
// Sadly, expectedStart and expectedEnd are actually wrong given the TZID:
evt := evts[0]
expectedStart, err := time.Parse(time.RFC3339, "2017-10-24T08:00:00+02:00")
if err != nil {
t.Fatalf("Failed to parse reference start: %s", err.Error())
}
start := evt.GetStart()
expectedEnd, err := time.Parse(time.RFC3339, "2017-10-24T10:00:00+02:00")
if err != nil {
t.Fatalf("Failed to parse reference end: %s", err.Error())
}
end := evt.GetEnd()
if !start.Equal(expectedStart) {
t.Fatalf("Start should be %s, but was %s", expectedStart, start)
}
if !end.Equal(expectedEnd) {
t.Fatalf("End should be %s, but was %s", expectedEnd, end)
}
expectedTZID := "Romance Standard Time"
if evt.GetStartTZID() != expectedTZID {
t.Fatalf("StartTZID should be %s, but was %s", expectedTZID, evt.GetStartTZID())
}
if evt.GetEndTZID() != expectedTZID {
t.Fatalf("EndTZID should be %s, but was %s", expectedTZID, evt.GetEndTZID())
}
}
func TestCalendarEvents(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/2eventsCal.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
return
}
calendar := calendars[0]
event, err := calendar.GetEventByImportedID("[email protected]")
if err != nil {
t.Errorf("Failed to get event by id with error %s", err)
}
// event must have
start, _ := time.Parse(IcsFormat, "20140714T100000Z")
end, _ := time.Parse(IcsFormat, "20140714T110000Z")
created, _ := time.Parse(IcsFormat, "20140515T075711Z")
modified, _ := time.Parse(IcsFormat, "20141125T074253Z")
location := "In The Office"
geo := NewGeo("39.620511", "-75.852557")
desc := "1. Report on previous weekly tasks. \\n2. Plan of the present weekly tasks."
seq := 1
status := "CONFIRMED"
summary := "General Operative Meeting"
rrule := ""
attendeesCount := 3
org := new(Attendee)
org.SetName("[email protected]")
org.SetEmail("[email protected]")
if event.GetStart() != start {
t.Errorf("Expected start %s, found %s", start, event.GetStart())
}
if event.GetEnd() != end {
t.Errorf("Expected end %s, found %s", end, event.GetEnd())
}
if event.GetCreated() != created {
t.Errorf("Expected created %s, found %s", created, event.GetCreated())
}
if event.GetLastModified() != modified {
t.Errorf("Expected modified %s, found %s", modified, event.GetLastModified())
}
if event.GetLocation() != location {
t.Errorf("Expected location %s, found %s", location, event.GetLocation())
}
if event.GetGeo().latStr != geo.latStr {
t.Errorf("Expected geo %s, found %s", geo.latStr, event.GetGeo().latStr)
}
if event.GetGeo().longStr != geo.longStr {
t.Errorf("Expected geo %s, found %s", geo.longStr, event.GetGeo().longStr)
}
if event.GetDescription() != desc {
t.Errorf("Expected description %s, found %s", desc, event.GetDescription())
}
if event.GetSequence() != seq {
t.Errorf("Expected sequence %d, found %d", seq, event.GetSequence())
}
if event.GetStatus() != status {
t.Errorf("Expected status %s, found %s", status, event.GetStatus())
}
if event.GetSummary() != summary {
t.Errorf("Expected status %s, found %s", summary, event.GetSummary())
}
if event.GetRRule() != rrule {
t.Errorf("Expected rrule %s, found %s", rrule, event.GetRRule())
}
if len(event.GetAttendees()) != attendeesCount {
t.Errorf("Expected attendeesCount %d, found %d", attendeesCount, len(event.GetAttendees()))
}
eventOrg := event.GetOrganizer()
if *eventOrg != *org {
t.Errorf("Expected organizer %s, found %s", org, event.GetOrganizer())
}
// SECOND EVENT WITHOUT ATTENDEES AND ORGANIZER
eventNoAttendees, errNoAttendees := calendar.GetEventByImportedID("[email protected]")
attendeesCount = 0
org = new(Attendee)
if errNoAttendees != nil {
t.Errorf("Failed to get event by id with error %s", errNoAttendees)
}
if len(eventNoAttendees.GetAttendees()) != attendeesCount {
t.Errorf("Expected attendeesCount %d, found %d", attendeesCount, len(event.GetAttendees()))
}
if eventNoAttendees.GetOrganizer() != nil {
t.Errorf("Expected organizer %s, found %s", org, eventNoAttendees.GetOrganizer())
}
}
func TestCalendarEventAttendees(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/2eventsCal.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
return
}
calendar := calendars[0]
event, err := calendar.GetEventByImportedID("[email protected]")
if err != nil {
t.Errorf("Failed to get event by id with error %s", err)
}
attendees := event.GetAttendees()
attendeesCount := 3
if len(attendees) != attendeesCount {
t.Errorf("Expected attendeesCount %d, found %d", attendeesCount, len(attendees))
return
}
john := attendees[0]
sue := attendees[1]
travis := attendees[2]
// check name
if john.GetName() != "John Smith" {
t.Errorf("Expected attendee name %s, found %s", "John Smith", john.GetName())
}
if sue.GetName() != "Sue Zimmermann" {
t.Errorf("Expected attendee name %s, found %s", "Sue Zimmermann", sue.GetName())
}
if travis.GetName() != "Travis M. Vollmer" {
t.Errorf("Expected attendee name %s, found %s", "Travis M. Vollmer", travis.GetName())
}
// check email
if john.GetEmail() != "[email protected]" {
t.Errorf("Expected attendee email %s, found %s", "[email protected]", john.GetEmail())
}
if sue.GetEmail() != "[email protected]" {
t.Errorf("Expected attendee email %s, found %s", "[email protected]", sue.GetEmail())
}
if travis.GetEmail() != "[email protected]" {
t.Errorf("Expected attendee email %s, found %s", "[email protected]", travis.GetEmail())
}
// check status
if john.GetStatus() != "ACCEPTED" {
t.Errorf("Expected attendee status %s, found %s", "ACCEPTED", john.GetStatus())
}
if sue.GetStatus() != "NEEDS-ACTION" {
t.Errorf("Expected attendee status %s, found %s", "NEEDS-ACTION", sue.GetStatus())
}
if travis.GetStatus() != "NEEDS-ACTION" {
t.Errorf("Expected attendee status %s, found %s", "NEEDS-ACTION", travis.GetStatus())
}
// check role
if john.GetRole() != "REQ-PARTICIPANT" {
t.Errorf("Expected attendee status %s, found %s", "REQ-PARTICIPANT", john.GetRole())
}
if sue.GetRole() != "REQ-PARTICIPANT" {
t.Errorf("Expected attendee status %s, found %s", "REQ-PARTICIPANT", sue.GetRole())
}
if travis.GetRole() != "REQ-PARTICIPANT" {
t.Errorf("Expected attendee status %s, found %s", "REQ-PARTICIPANT", travis.GetRole())
}
}
func TestCalendarMultidayEvent(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/multiday.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
return
}
calendar := calendars[0]
// Test a day before the start day
events, err := calendar.GetEventsByDate(time.Date(2016, 8, 31, 0, 0, 0, 0, time.UTC))
if err == nil {
t.Errorf("Expected no event before the start day, got %d", len(events))
}
// Test exact start day
events, err = calendar.GetEventsByDate(time.Date(2016, 9, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Errorf("Failed to get event: %s", err.Error())
}
if len(events) != 1 {
t.Errorf("Expected 1 event on the start day, got %d", len(events))
}
// Test a random day between start and end date
events, err = calendar.GetEventsByDate(time.Date(2016, 10, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Errorf("Failed to get event: %s", err.Error())
}
if len(events) != 1 {
t.Errorf("Expected 1 event between start and end, got %d", len(events))
}
// Test a day after the end day
events, err = calendar.GetEventsByDate(time.Date(2016, 11, 1, 0, 0, 0, 0, time.UTC))
if err == nil {
t.Errorf("Expected no event after the end day, got %d", len(events))
}
}
func TestCalendarMultidayEventWithDurationInsteadOfEndDate(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/multiday_duration.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Errorf("Failed to get calendars ( %s )", errCal)
}
if len(calendars) != 1 {
t.Errorf("Expected 1 calendar, found %d calendars", len(calendars))
return
}
calendar := calendars[0]
// Test a day before the start day
events, err := calendar.GetEventsByDate(time.Date(2016, 8, 31, 0, 0, 0, 0, time.UTC))
if err == nil {
t.Errorf("Expected no event before the start day, got %d", len(events))
}
// Test exact start day
events, err = calendar.GetEventsByDate(time.Date(2016, 9, 1, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Errorf("Failed to get event: %s", err.Error())
}
if len(events) != 1 {
t.Errorf("Expected 1 event on the start day, got %d", len(events))
}
// Test a random day between start and end date
events, err = calendar.GetEventsByDate(time.Date(2016, 9, 2, 0, 0, 0, 0, time.UTC))
if err != nil {
t.Errorf("Failed to get event: %s", err.Error())
}
if len(events) != 1 {
t.Errorf("Expected 1 event between start and end, got %d", len(events))
}
// Test a day after the end day
events, err = calendar.GetEventsByDate(time.Date(2016, 9, 4, 0, 0, 0, 0, time.UTC))
if err == nil {
t.Errorf("Expected no event after the end day, got %d", len(events))
}
}
func TestPagerDutyCalendarEventTimes(t *testing.T) {
parser := New()
input := parser.GetInputChan()
input <- "testCalendars/pagerduty.ics"
parser.Wait()
parseErrors, err := parser.GetErrors()
if err != nil {
t.Errorf("Failed to wait the parse of the calendars ( %s )", err)
}
if len(parseErrors) != 0 {
t.Errorf("Expected 0 error, found %d in :\n %#v", len(parseErrors), parseErrors)
}
calendars, errCal := parser.GetCalendars()
if errCal != nil {
t.Fatalf("Failed to retrieve calendars: %s", err.Error())
}
if len(calendars) < 1 {
t.Fatalf("The test calendar file should have at least included one calendar")
}
evts := calendars[0].GetEvents()
if len(evts) < 1 {
t.Fatalf("The test calendar should have included at least one event")
}
evt := evts[0]
expectedStart, err := time.Parse(time.RFC3339, "2019-06-14T17:00:00+00:00")
if err != nil {
t.Fatalf("Failed to parse reference start: %s", err.Error())
}
start := evt.GetStart()
expectedEnd, err := time.Parse(time.RFC3339, "2019-06-15T17:00:00+00:00")
if err != nil {
t.Fatalf("Failed to parse reference end: %s", err.Error())
}
end := evt.GetEnd()
if !start.Equal(expectedStart) {
t.Fatalf("Start should be %s, but was %s", expectedStart, start)
}
if !end.Equal(expectedEnd) {
t.Fatalf("End should be %s, but was %s", expectedEnd, end)
}
}