-
Notifications
You must be signed in to change notification settings - Fork 1
/
x509_test.go
76 lines (70 loc) · 1.61 KB
/
x509_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 xrhidgen
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
func TestNewX509(t *testing.T) {
type Test struct {
description string
seed int64
input X509
want *identity.X509
wantError error
}
tests := []Test{
{
description: "empty template",
seed: 100,
input: X509{},
want: &identity.X509{
SubjectDN: "gimwu7Re",
IssuerDN: "hCRM50",
},
},
{
description: "partial template",
seed: 100,
input: X509{
SubjectDN: pointy.String("CN = d6cde789-fbad-45ea-a542-30ba779aa870"),
},
want: &identity.X509{
SubjectDN: "CN = d6cde789-fbad-45ea-a542-30ba779aa870",
IssuerDN: "gimwu7Re",
},
},
{
description: "full template",
seed: 100,
input: X509{
SubjectDN: pointy.String("CN = d6cde789-fbad-45ea-a542-30ba779aa870"),
IssuerDN: pointy.String("O = Foo, Inc."),
},
want: &identity.X509{
SubjectDN: "CN = d6cde789-fbad-45ea-a542-30ba779aa870",
IssuerDN: "O = Foo, Inc.",
},
},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
faker.SetSeed(test.seed)
got, err := NewX509(test.input)
if test.wantError != nil {
if !cmp.Equal(err, test.wantError, cmpopts.EquateErrors()) {
t.Errorf("%#v != %#v", err, test.wantError)
}
} else {
if err != nil {
t.Fatal(err)
}
if !cmp.Equal(got, test.want) {
t.Errorf("%v", cmp.Diff(got, test.want))
}
}
})
}
}