forked from 0xch4z/dockerhub-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
organization_test.go
66 lines (52 loc) · 1.58 KB
/
organization_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
package dockerhub
import (
"context"
"net/http"
"reflect"
"testing"
)
func TestOrganizationService_CreateOrganization(t *testing.T) {
client, mux, teardown := makeMockClient()
defer teardown()
organizationName := "hamroOrg"
companyName := "hamroCompany"
newOrg := &Organization{}
uri := "/orgs/"
mux.HandleFunc(uri, func(w http.ResponseWriter, r *http.Request) {
assertMethod(t, r, http.MethodPost)
assertNoHeader(t, r, "Authorization")
assertBody(t, r, string(mustJSONMarshal(&CreateOrganizationRequest{
Orgname: organizationName,
Company: companyName,
},
)))
w.WriteHeader(http.StatusCreated)
w.Write(mustJSONMarshal(&CreateOrganizationRequest{}))
})
res, err := client.Organization.CreateOrganization(context.Background(), organizationName, companyName)
if err != nil {
t.Errorf("Organization.CreateOrganization returned error: %v", err)
}
if !reflect.DeepEqual(res, newOrg) {
t.Errorf("organization is %v; want %v", res, newOrg)
}
}
func TestOrganizationService_GetOrganizations(t *testing.T) {
client, mux, teardown := makeMockClient()
defer teardown()
orgs := &OrganizationList{}
pageSize := 100
uri := "/user/orgs/"
mux.HandleFunc(uri, func(w http.ResponseWriter, r *http.Request) {
assertMethod(t, r, http.MethodGet)
w.WriteHeader(http.StatusOK)
w.Write(mustJSONMarshal(orgs))
})
res, err := client.Organization.GetOrganizations(context.Background(), pageSize)
if err != nil {
t.Errorf("Organization.GetOrganizations returned error: %v", err)
}
if !reflect.DeepEqual(res, orgs) {
t.Errorf("organization is %v; want %v", res, orgs)
}
}