-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_test.go
126 lines (110 loc) · 3.01 KB
/
team_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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-Present Datadog, Inc.
package cloudcraft_test
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"path/filepath"
"reflect"
"testing"
"github.com/DataDog/cloudcraft-go"
"github.com/DataDog/cloudcraft-go/internal/xtesting"
)
const _testTeamDataPath string = "tests/data/team"
func TestTeamService_List(t *testing.T) {
t.Parallel()
var (
validTestData = xtesting.ReadFile(t, filepath.Join(_testTeamDataPath, "list-valid.json"))
invalidTestData = xtesting.ReadFile(t, filepath.Join(_testTeamDataPath, "list-invalid.json"))
ctx = context.Background()
)
tests := []struct {
name string
handler http.HandlerFunc
context context.Context
want []*cloudcraft.Team
wantErr bool
}{
{
name: "Valid team data",
handler: func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(validTestData)
},
context: ctx,
want: []*cloudcraft.Team{
{
ID: "2d2f9b4d-53ac-463f-9c7a-97249a22a7fa",
Name: "Team Cloudcraft SDKs",
Visible: true,
CrossOrganizational: false,
CustomerID: "e6d4ccd3-551e-425f-b415-637f9005ed2a",
UpdatedAt: xtesting.ParseTime(t, "2022-10-10T17:01:11.214Z"),
CreatedAt: xtesting.ParseTime(t, "2022-10-10T17:01:11.214Z"),
ExternalSharing: true,
Role: "owner",
Members: []cloudcraft.Members{
{
ID: "aa54884d-5c7b-4586-8139-7a6e39231cc9",
Role: "owner",
UserID: nil,
Name: nil,
Email: "hello@example.com",
MFAEnabled: true,
},
},
},
},
wantErr: false,
},
{
name: "Invalid team data",
handler: func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(invalidTestData)
},
context: ctx,
want: nil,
wantErr: true,
},
{
name: "API error response",
handler: func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
},
context: ctx,
want: nil,
wantErr: true,
},
{
name: "Nil context",
handler: func(_ http.ResponseWriter, _ *http.Request) {},
context: nil,
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(tt.handler)
defer ts.Close()
endpoint, err := url.Parse(ts.URL)
if err != nil {
t.Fatal(err)
}
client := xtesting.SetupMockClient(t, endpoint)
got, _, err := client.Team.List(tt.context)
if (err != nil) != tt.wantErr {
t.Fatalf("AzureTeam.List() error = %v, wantErr %v", err, tt.wantErr)
}
if !tt.wantErr && !reflect.DeepEqual(got, tt.want) {
t.Fatalf("AzureTeam.List() = %v, want %v", got, tt.want)
}
})
}
}