forked from kevholditch/gokong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certificates_test.go
156 lines (106 loc) · 4.02 KB
/
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package gokong
import (
"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_CertificatesGetById(t *testing.T) {
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
client := NewClient(NewDefaultConfig())
createdCertificate, err := client.Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate)
result, err := client.Certificates().GetById(createdCertificate.Id)
assert.NotNil(t, result)
assert.Equal(t, createdCertificate, result)
}
func Test_CertificatesGetNonExistentById(t *testing.T) {
result, err := NewClient(NewDefaultConfig()).Certificates().GetById("8df4d1ed-c973-4b9a-868d-3e67d5c417da")
assert.Nil(t, err)
assert.Nil(t, result)
}
func Test_CertificatesCreate(t *testing.T) {
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
result, err := NewClient(NewDefaultConfig()).Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, result)
assert.True(t, result.Id != "")
assert.Equal(t, certificateRequest.Cert, result.Cert)
assert.Equal(t, certificateRequest.Key, result.Key)
}
func Test_CertificatesCreateInvalid(t *testing.T) {
certificateRequest := &CertificateRequest{}
result, err := NewClient(NewDefaultConfig()).Certificates().Create(certificateRequest)
assert.NotNil(t, err)
assert.Nil(t, result)
}
func Test_CertificatesUpdateById(t *testing.T) {
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
client := NewClient(NewDefaultConfig())
createdCertificate, err := client.Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate)
certificateRequest.Cert = "public key-" + uuid.NewV4().String()
result, err := client.Certificates().UpdateById(createdCertificate.Id, certificateRequest)
assert.Equal(t, certificateRequest.Cert, result.Cert)
assert.Equal(t, certificateRequest.Key, result.Key)
}
func Test_CertificatesUpdateByIdInvalid(t *testing.T) {
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
client := NewClient(NewDefaultConfig())
createdCertificate, err := client.Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate)
certificateRequest.Cert = ""
certificateRequest.Key = ""
result, err := client.Certificates().UpdateById(createdCertificate.Id, certificateRequest)
assert.NotNil(t, err)
assert.Nil(t, result)
}
func Test_CertificatesDeleteById(t *testing.T) {
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
client := NewClient(NewDefaultConfig())
createdCertificate, err := client.Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate)
err = client.Certificates().DeleteById(createdCertificate.Id)
assert.Nil(t, err)
deletedCertificate, err := client.Certificates().GetById(createdCertificate.Id)
assert.Nil(t, err)
assert.Nil(t, deletedCertificate)
}
func Test_CertificatesList(t *testing.T) {
client := NewClient(NewDefaultConfig())
certificateRequest := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
createdCertificate, err := client.Certificates().Create(certificateRequest)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate)
certificateRequest2 := &CertificateRequest{
Cert: "public key-" + uuid.NewV4().String(),
Key: "private key-" + uuid.NewV4().String(),
}
createdCertificate2, err := client.Certificates().Create(certificateRequest2)
assert.Nil(t, err)
assert.NotNil(t, createdCertificate2)
results, err := client.Certificates().List()
assert.Nil(t, err)
assert.True(t, len(results.Results) > 1)
}