forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_test.go
158 lines (136 loc) · 4.8 KB
/
admin_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
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestAdminService_UpdateUserLDAPMapping(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &UserLDAPMapping{
LDAPDN: String("uid=asdf,ou=users,dc=github,dc=com"),
}
mux.HandleFunc("/admin/ldap/users/u/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(UserLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1,"ldap_dn":"uid=asdf,ou=users,dc=github,dc=com"}`)
})
ctx := context.Background()
mapping, _, err := client.Admin.UpdateUserLDAPMapping(ctx, "u", input)
if err != nil {
t.Errorf("Admin.UpdateUserLDAPMapping returned error: %v", err)
}
want := &UserLDAPMapping{
ID: Int64(1),
LDAPDN: String("uid=asdf,ou=users,dc=github,dc=com"),
}
if !reflect.DeepEqual(mapping, want) {
t.Errorf("Admin.UpdateUserLDAPMapping returned %+v, want %+v", mapping, want)
}
const methodName = "UpdateUserLDAPMapping"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Admin.UpdateUserLDAPMapping(ctx, "\n", input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Admin.UpdateUserLDAPMapping(ctx, "u", input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestAdminService_UpdateTeamLDAPMapping(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &TeamLDAPMapping{
LDAPDN: String("cn=Enterprise Ops,ou=teams,dc=github,dc=com"),
}
mux.HandleFunc("/admin/ldap/teams/1/mapping", func(w http.ResponseWriter, r *http.Request) {
v := new(TeamLDAPMapping)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id":1,"ldap_dn":"cn=Enterprise Ops,ou=teams,dc=github,dc=com"}`)
})
ctx := context.Background()
mapping, _, err := client.Admin.UpdateTeamLDAPMapping(ctx, 1, input)
if err != nil {
t.Errorf("Admin.UpdateTeamLDAPMapping returned error: %v", err)
}
want := &TeamLDAPMapping{
ID: Int64(1),
LDAPDN: String("cn=Enterprise Ops,ou=teams,dc=github,dc=com"),
}
if !reflect.DeepEqual(mapping, want) {
t.Errorf("Admin.UpdateTeamLDAPMapping returned %+v, want %+v", mapping, want)
}
const methodName = "UpdateTeamLDAPMapping"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Admin.UpdateTeamLDAPMapping(ctx, -1, input)
return err
})
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Admin.UpdateTeamLDAPMapping(ctx, 1, input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestAdminService_TeamLDAPMapping_String(t *testing.T) {
v := &TeamLDAPMapping{
ID: Int64(1),
LDAPDN: String("a"),
URL: String("b"),
Name: String("c"),
Slug: String("d"),
Description: String("e"),
Privacy: String("f"),
Permission: String("g"),
MembersURL: String("h"),
RepositoriesURL: String("i"),
}
want := `github.TeamLDAPMapping{ID:1, LDAPDN:"a", URL:"b", Name:"c", Slug:"d", Description:"e", Privacy:"f", Permission:"g", MembersURL:"h", RepositoriesURL:"i"}`
if got := v.String(); got != want {
t.Errorf("TeamLDAPMapping.String = `%v`, want `%v`", got, want)
}
}
func TestAdminService_UserLDAPMapping_String(t *testing.T) {
v := &UserLDAPMapping{
ID: Int64(1),
LDAPDN: String("a"),
Login: String("b"),
AvatarURL: String("c"),
GravatarID: String("d"),
Type: String("e"),
SiteAdmin: Bool(true),
URL: String("f"),
EventsURL: String("g"),
FollowingURL: String("h"),
FollowersURL: String("i"),
GistsURL: String("j"),
OrganizationsURL: String("k"),
ReceivedEventsURL: String("l"),
ReposURL: String("m"),
StarredURL: String("n"),
SubscriptionsURL: String("o"),
}
want := `github.UserLDAPMapping{ID:1, LDAPDN:"a", Login:"b", AvatarURL:"c", GravatarID:"d", Type:"e", SiteAdmin:true, URL:"f", EventsURL:"g", FollowingURL:"h", FollowersURL:"i", GistsURL:"j", OrganizationsURL:"k", ReceivedEventsURL:"l", ReposURL:"m", StarredURL:"n", SubscriptionsURL:"o"}`
if got := v.String(); got != want {
t.Errorf("UserLDAPMapping.String = `%v`, want `%v`", got, want)
}
}