forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapps_test.go
103 lines (91 loc) · 2.48 KB
/
apps_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
package scrape
import (
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-github/v58/github"
)
func Test_AppRestrictionsEnabled(t *testing.T) {
tests := []struct {
description string
testFile string
org string
want bool
}{
{
description: "return true for enabled orgs",
testFile: "access-restrictions-enabled.html",
want: true,
},
{
description: "return false for disabled orgs",
testFile: "access-restrictions-disabled.html",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
client, mux, cleanup := setup()
defer cleanup()
mux.HandleFunc("/organizations/o/settings/oauth_application_policy", func(w http.ResponseWriter, r *http.Request) {
copyTestFile(t, w, tt.testFile)
})
got, err := client.AppRestrictionsEnabled("o")
if err != nil {
t.Errorf("AppRestrictionsEnabled returned err: %v", err)
}
if want := tt.want; got != want {
t.Errorf("AppRestrictionsEnabled returned %t, want %t", got, want)
}
})
}
}
func Test_ListOAuthApps(t *testing.T) {
client, mux, cleanup := setup()
defer cleanup()
mux.HandleFunc("/organizations/e/settings/oauth_application_policy", func(w http.ResponseWriter, r *http.Request) {
copyTestFile(t, w, "access-restrictions-enabled.html")
})
got, err := client.ListOAuthApps("e")
if err != nil {
t.Errorf("ListOAuthApps(e) returned err: %v", err)
}
want := []OAuthApp{
{
ID: 22222,
Name: "Coveralls",
Description: "Test coverage history and statistics.",
State: OAuthAppRequested,
RequestedBy: "willnorris",
},
{
ID: 530107,
Name: "Google Cloud Platform",
State: OAuthAppApproved,
},
{
ID: 231424,
Name: "GitKraken",
Description: "An intuitive, cross-platform Git client that doesn't suck, built by @axosoft and made with @nodegit & @ElectronJS.",
State: OAuthAppDenied,
},
}
if !cmp.Equal(got, want) {
t.Errorf("ListOAuthApps(o) returned %v, want %v", got, want)
}
}
func Test_CreateApp(t *testing.T) {
client, mux, cleanup := setup()
defer cleanup()
mux.HandleFunc("/apps/settings/new", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
})
if _, err := client.CreateApp(&AppManifest{
URL: github.String("https://example.com"),
HookAttributes: map[string]string{
"url": "https://example.com/hook",
},
}); err != nil {
t.Fatalf("CreateApp: %v", err)
}
}