-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdm_push_certificates_test.go
129 lines (113 loc) · 3.23 KB
/
mdm_push_certificates_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package goztl
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
var mpcListJSONResponse = `
[
{
"id": 4,
"provisioning_uid": null,
"name": "Default",
"topic": null,
"not_before": null,
"not_after": null,
"certificate": null,
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
]
`
var mpcGetJSONResponse = `
{
"id": 4,
"provisioning_uid": "YoLoFoMo",
"name": "Default",
"topic": "un-deux-trois",
"not_before": "2022-07-22T01:02:03.444444",
"not_after": "2022-07-22T01:02:03.444444",
"certificate": "CERT_PEM",
"created_at": "2022-07-22T01:02:03.444444",
"updated_at": "2022-07-22T01:02:03.444444"
}
`
func TestMDMPushCertificatesService_List(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/mdm/push_certificates/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
fmt.Fprint(w, mpcListJSONResponse)
})
ctx := context.Background()
got, _, err := client.MDMPushCertificates.List(ctx, nil)
if err != nil {
t.Errorf("MDMPushCertificates.List returned error: %v", err)
}
want := []MDMPushCertificate{
{
ID: 4,
Name: "Default",
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMPushCertificates.List returned %+v, want %+v", got, want)
}
}
func TestMDMPushCertificatesService_GetByID(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/mdm/push_certificates/4/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
fmt.Fprint(w, mpcGetJSONResponse)
})
ctx := context.Background()
got, _, err := client.MDMPushCertificates.GetByID(ctx, 4)
if err != nil {
t.Errorf("MDMPushCertificates.GetByID returned error: %v", err)
}
want := &MDMPushCertificate{
ID: 4,
ProvisioningUID: String("YoLoFoMo"),
Name: "Default",
Topic: String("un-deux-trois"),
Certificate: String("CERT_PEM"),
NotBefore: &Timestamp{referenceTime},
NotAfter: &Timestamp{referenceTime},
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMPushCertificates.GetByID returned %+v, want %+v", got, want)
}
}
func TestMDMPushCertificatesService_GetByName(t *testing.T) {
client, mux, teardown := setup()
defer teardown()
mux.HandleFunc("/mdm/push_certificates/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", "application/json")
testQueryArg(t, r, "name", "Default")
fmt.Fprint(w, mpcListJSONResponse)
})
ctx := context.Background()
got, _, err := client.MDMPushCertificates.GetByName(ctx, "Default")
if err != nil {
t.Errorf("MDMPushCertificates.GetByName returned error: %v", err)
}
want := &MDMPushCertificate{
ID: 4,
Name: "Default",
Created: Timestamp{referenceTime},
Updated: Timestamp{referenceTime},
}
if !cmp.Equal(got, want) {
t.Errorf("MDMPushCertificates.GetByName returned %+v, want %+v", got, want)
}
}