forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_users_test.go
57 lines (46 loc) · 1.43 KB
/
admin_users_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
// Copyright 2019 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 TestAdminUsers_Create(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/admin/users", func(w http.ResponseWriter, r *http.Request) {
v := new(createUserRequest)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
want := &createUserRequest{Login: String("github"), Email: String("[email protected]")}
if !reflect.DeepEqual(v, want) {
t.Errorf("Request body = %+v, want %+v", v, want)
}
fmt.Fprint(w, `{"login":"github","id":1}`)
})
org, _, err := client.Admin.CreateUser(context.Background(), "github", "[email protected]")
if err != nil {
t.Errorf("Admin.CreateUser returned error: %v", err)
}
want := &User{ID: Int64(1), Login: String("github")}
if !reflect.DeepEqual(org, want) {
t.Errorf("Admin.CreateUser returned %+v, want %+v", org, want)
}
}
func TestAdminUsers_Delete(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/admin/users/github", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
})
_, err := client.Admin.DeleteUser(context.Background(), "github")
if err != nil {
t.Errorf("Admin.DeleteUser returned error: %v", err)
}
}