-
Notifications
You must be signed in to change notification settings - Fork 59
/
access_tokens_test.go
59 lines (46 loc) · 1.4 KB
/
access_tokens_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
package buildkite
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestAccessTokensService_Get(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/access-token", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"uuid": "b63254c0-3271-4a98-8270-7cfbd6c2f14e","scopes": ["read_build"]}`)
})
ats, _, err := client.AccessTokens.Get(context.Background())
if err != nil {
t.Errorf("AccessTokens.Get returned error: %v", err)
}
want := AccessToken{
UUID: "b63254c0-3271-4a98-8270-7cfbd6c2f14e",
Scopes: []string{"read_build"},
}
if diff := cmp.Diff(ats, want); diff != "" {
t.Errorf("AccessTokens.Get diff: (-got +want)\n%s", diff)
}
}
func TestAccessTokensService_Revoke(t *testing.T) {
t.Parallel()
server, client, teardown := newMockServerAndClient(t)
t.Cleanup(teardown)
server.HandleFunc("/v2/access-token", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})
resp, err := client.AccessTokens.Revoke(context.Background())
if err != nil {
t.Errorf("AccessTokens.Revoke returned error: %v", err)
}
want := http.StatusNoContent
got := resp.Response.StatusCode
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("AccessTokens.Revoke diff: (-got +want)\n%s", diff)
}
}