@@ -15,6 +15,10 @@ func TestCalendarCreate(t *testing.T) {
1515 t .Skip ("Skipping test because the engine is not initialized" )
1616 }
1717
18+ // Only one blocked time calendar is allowed per user, so a leftover from an
19+ // interrupted run makes the "all fields" case fail until it is removed.
20+ deleteBlockedTimeCalendar (t )
21+
1822 tests := []struct {
1923 name string
2024 input projects.CalendarCreateRequest
@@ -55,6 +59,35 @@ func TestCalendarCreate(t *testing.T) {
5559 }
5660}
5761
62+ // deleteBlockedTimeCalendar removes the user's blocked time calendar if one
63+ // exists, so tests that create one start from a clean slate.
64+ func deleteBlockedTimeCalendar (t * testing.T ) {
65+ t .Helper ()
66+
67+ ctx , cancel := context .WithTimeout (t .Context (), 10 * time .Second )
68+ t .Cleanup (cancel )
69+
70+ for request := projects .NewCalendarListRequest (); ; {
71+ response , err := projects .CalendarList (ctx , engine , request )
72+ if err != nil {
73+ t .Fatalf ("failed to list calendars: %s" , err )
74+ }
75+ for _ , calendar := range response .Calendars {
76+ if calendar .Type != projects .CalendarTypeBlockedTime {
77+ continue
78+ }
79+ if _ , err := projects .CalendarDelete (ctx , engine , projects .NewCalendarDeleteRequest (calendar .ID )); err != nil {
80+ t .Fatalf ("failed to delete leftover blocked time calendar: %s" , err )
81+ }
82+ }
83+ next := response .Iterate ()
84+ if next == nil {
85+ return
86+ }
87+ request = * next
88+ }
89+ }
90+
5891func TestCalendarDelete (t * testing.T ) {
5992 if engine == nil {
6093 t .Skip ("Skipping test because the engine is not initialized" )
0 commit comments