-
Notifications
You must be signed in to change notification settings - Fork 7
/
update_test.go
76 lines (70 loc) · 1.49 KB
/
update_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
package devicecheck
import (
"context"
"io"
"net/http"
"strings"
"testing"
)
func TestClient_UpdateTwoBits(t *testing.T) {
t.Parallel()
cases := map[string]struct {
client Client
noErr bool
}{
"invalid key": {
client: Client{
api: newAPI(Development),
cred: NewCredentialFile("unknown_file.p8"),
jwt: newJWT("issuer", "keyID"),
},
noErr: false,
},
"invalid url": {
client: Client{
api: api{
client: new(http.Client),
baseURL: "invalid url",
},
cred: NewCredentialFile("revoked_private_key.p8"),
jwt: newJWT("issuer", "keyID"),
},
noErr: false,
},
"invalid device token": {
client: Client{
api: newAPI(Development),
cred: NewCredentialFile("revoked_private_key.p8"),
jwt: newJWT("issuer", "keyID"),
},
noErr: false,
},
"status ok": {
client: Client{
api: newAPIWithHTTPClient(newMockHTTPClient(&http.Response{
StatusCode: http.StatusOK,
Body: io.NopCloser(strings.NewReader("success")),
}), Development),
cred: NewCredentialFile("revoked_private_key.p8"),
jwt: newJWT("issuer", "keyID"),
},
noErr: true,
},
}
for name, c := range cases {
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()
err := c.client.UpdateTwoBits(context.Background(), "device_token", true, true)
if c.noErr {
if err != nil {
t.Errorf("want 'nil', got '%+v'", err)
}
} else {
if err == nil {
t.Error("want 'not nil', got 'nil'")
}
}
})
}
}