This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ability_test.go
75 lines (57 loc) · 1.74 KB
/
ability_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
package pagerduty
import (
"net/http"
"testing"
)
func TestAbility_ListAbilities(t *testing.T) {
t.Parallel()
setup()
defer teardown()
mux.HandleFunc("/abilities", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Write([]byte(`{"abilities": ["sso"]}`))
})
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
want := &ListAbilityResponse{Abilities: []string{"sso"}}
res, err := client.ListAbilities()
if err != nil {
t.Fatal(err)
}
testEqual(t, want, res)
}
func TestAbility_ListAbilitiesFailure(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/abilities", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusForbidden)
})
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
if _, err := client.ListAbilities(); err == nil {
t.Fatal("expected error; got nil")
}
}
func TestAbility_TestAbility(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/abilities/sso", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNoContent)
})
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
if err := client.TestAbility("sso"); err != nil {
t.Fatal(err)
}
}
func TestAbility_TestAbilityFailure(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/abilities/sso", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusForbidden)
})
var client = &Client{apiEndpoint: server.URL, authToken: "foo", HTTPClient: defaultHTTPClient}
if err := client.TestAbility("sso"); err == nil {
t.Fatal("expected error; got nil")
}
}