This repository was archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 953
/
Copy pathlicense_test.go
172 lines (155 loc) · 4.01 KB
/
license_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
package gitlab
import (
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestLicenseService_GetLicense(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/license", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `
{
"id": 2,
"plan": "gold",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
"active_users": 300,
"licensee": {
"Name": "Venkatesh Thalluri"
},
"add_ons": {
"GitLab_FileLocks": 1,
"GitLab_Auditor_User": 1
}
}
`)
})
want := &License{
ID: 2,
Plan: "gold",
HistoricalMax: 300,
MaximumUserCount: 300,
Expired: false,
Overage: 200,
UserLimit: 100,
ActiveUsers: 300,
Licensee: struct {
Name string `json:"Name"`
Company string `json:"Company"`
Email string `json:"Email"`
}{
Name: "Venkatesh Thalluri",
Company: "",
Email: "",
},
AddOns: struct {
GitLabAuditorUser int `json:"GitLab_Auditor_User"`
GitLabDeployBoard int `json:"GitLab_DeployBoard"`
GitLabFileLocks int `json:"GitLab_FileLocks"`
GitLabGeo int `json:"GitLab_Geo"`
GitLabServiceDesk int `json:"GitLab_ServiceDesk"`
}{
GitLabAuditorUser: 1,
GitLabDeployBoard: 0,
GitLabFileLocks: 1,
GitLabGeo: 0,
GitLabServiceDesk: 0,
},
}
l, resp, err := client.License.GetLicense()
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, l)
}
func TestLicenseService_GetLicense_StatusNotFound(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/license", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusNotFound)
})
l, resp, err := client.License.GetLicense()
require.Error(t, err)
require.Nil(t, l)
require.Equal(t, http.StatusNotFound, resp.StatusCode)
}
func TestLicenseService_AddLicense(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/license", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprintf(w, `
{
"id": 2,
"plan": "gold",
"historical_max": 300,
"maximum_user_count": 300,
"expired": false,
"overage": 200,
"user_limit": 100,
"active_users": 300,
"licensee": {
"Name": "Venkatesh Thalluri"
},
"add_ons": {
"GitLab_FileLocks": 1,
"GitLab_Auditor_User": 1
}
}
`)
})
want := &License{
ID: 2,
Plan: "gold",
HistoricalMax: 300,
MaximumUserCount: 300,
Expired: false,
Overage: 200,
UserLimit: 100,
ActiveUsers: 300,
Licensee: struct {
Name string `json:"Name"`
Company string `json:"Company"`
Email string `json:"Email"`
}{
Name: "Venkatesh Thalluri",
Company: "",
Email: "",
},
AddOns: struct {
GitLabAuditorUser int `json:"GitLab_Auditor_User"`
GitLabDeployBoard int `json:"GitLab_DeployBoard"`
GitLabFileLocks int `json:"GitLab_FileLocks"`
GitLabGeo int `json:"GitLab_Geo"`
GitLabServiceDesk int `json:"GitLab_ServiceDesk"`
}{
GitLabAuditorUser: 1,
GitLabDeployBoard: 0,
GitLabFileLocks: 1,
GitLabGeo: 0,
GitLabServiceDesk: 0,
},
}
l, resp, err := client.License.AddLicense(nil)
require.NoError(t, err)
require.NotNil(t, resp)
require.Equal(t, want, l)
l, resp, err = client.License.AddLicense(nil, errorOption)
require.EqualError(t, err, "RequestOptionFunc returns an error")
require.Nil(t, resp)
require.Nil(t, l)
}
func TestLicenseService_AddLicense_StatusNotFound(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/license", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
w.WriteHeader(http.StatusNotFound)
})
l, resp, err := client.License.AddLicense(nil)
require.Error(t, err)
require.Nil(t, l)
require.Equal(t, http.StatusNotFound, resp.StatusCode)
}