forked from open-networks/go-msgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calendars_test.go
81 lines (75 loc) · 2.06 KB
/
Calendars_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
package msgraph
import (
"strings"
"testing"
)
// GetTestListCalendars tries to get a valid User from the User-test cases
// and then uses ListCalendars() for this instance.
func GetTestListCalendars(t *testing.T) Calendars {
t.Helper()
testUser := GetTestUser(t)
if skipCalendarTests {
t.Skip("Skipping due to missing 'MSGraphExistingCalendarsOfUser' value")
}
testCalendars, err := testUser.ListCalendars()
if err != nil {
t.Fatalf("Cannot User.ListCalendars() for user %v: %v", testUser, err)
}
if len(testCalendars) == 0 {
t.Fatalf("Cannot User.ListCalendars() for user %v, 0 calendars returned", testUser)
}
return testCalendars
}
func TestCalendars_GetByName(t *testing.T) {
testCalendars := GetTestListCalendars(t)
if skipCalendarTests {
t.Skip("Skipping due to missing 'MSGraphExistingCalendarsOfUser' value")
}
type args struct {
name string
}
tests := []struct {
name string
c Calendars
args args
wantErr bool
}{
{
name: "Find valid Calendar",
c: testCalendars,
args: args{name: msGraphExistingCalendarsOfUser[0]},
wantErr: false,
}, {
name: "non-existing calendar",
c: testCalendars,
args: args{name: "DSfk9sdf89io23rasdfasfasdfasdf"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := tt.c.GetByName(tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("Calendars.GetByName() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
func TestCalendars_String(t *testing.T) {
if skipCalendarTests {
t.Skip("Skipping due to missing 'MSGraphExistingCalendarsOfUser' value")
}
testCalendars := GetTestListCalendars(t)
// write custom string func
var calendars = make([]string, len(testCalendars))
for i, calendar := range testCalendars {
calendars[i] = calendar.String()
}
want := "Calendars(" + strings.Join(calendars, " | ") + ")"
t.Run("Test Calendars of TestUser", func(t *testing.T) {
if got := testCalendars.String(); got != want {
t.Errorf("Calendars.String() = %v, want %v", got, want)
}
})
}