forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ability_test.go
74 lines (57 loc) · 1.56 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
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"]}`))
})
client := defaultTestClient(server.URL, "foo")
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)
})
client := defaultTestClient(server.URL, "foo")
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)
})
client := defaultTestClient(server.URL, "foo")
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)
})
client := defaultTestClient(server.URL, "foo")
if err := client.TestAbility("sso"); err == nil {
t.Fatal("expected error; got nil")
}
}