-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy patharbiter_test.go
More file actions
94 lines (87 loc) · 2.68 KB
/
Copy patharbiter_test.go
File metadata and controls
94 lines (87 loc) · 2.68 KB
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
package machine
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/tls"
"github.com/openshift/installer/pkg/ipnet"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
)
// TestArbiterGenerate tests generating the arbiter asset.
func TestArbiterGenerate(t *testing.T) {
testCases := []struct {
expectedIgnitionConfigNames []string
installConfig *installconfig.InstallConfig
description string
}{
{
description: "should generate with arbiter config",
expectedIgnitionConfigNames: []string{
"arbiter.ign",
},
installConfig: installconfig.MakeAsset(
&types.InstallConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
BaseDomain: "test-domain",
Networking: &types.Networking{
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")},
},
Platform: types.Platform{
AWS: &aws.Platform{
Region: "us-east",
},
},
Arbiter: &types.MachinePool{
Name: "arbiter",
Replicas: ptr.To(int64(1)),
},
}),
},
{
description: "should not generate arbiter ignition when no arbiter",
expectedIgnitionConfigNames: []string{},
installConfig: installconfig.MakeAsset(
&types.InstallConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cluster",
},
BaseDomain: "test-domain",
Networking: &types.Networking{
ServiceNetwork: []ipnet.IPNet{*ipnet.MustParseCIDR("10.0.1.0/24")},
},
Platform: types.Platform{
AWS: &aws.Platform{
Region: "us-east",
},
},
}),
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
rootCAParents := asset.Parents{}
rootCAParents.Add(tc.installConfig)
rootCA := &tls.RootCA{}
err := rootCA.Generate(context.Background(), rootCAParents)
assert.NoError(t, err, "unexpected error generating root CA")
parents := asset.Parents{}
parents.Add(tc.installConfig, rootCA)
arbiter := &Arbiter{}
err = arbiter.Generate(context.Background(), parents)
assert.NoError(t, err, "unexpected error generating arbiter asset")
actualFiles := arbiter.Files()
actualIgnitionConfigNames := make([]string, len(actualFiles))
for i, f := range actualFiles {
actualIgnitionConfigNames[i] = f.Filename
}
assert.Equal(t, tc.expectedIgnitionConfigNames, actualIgnitionConfigNames, "unexpected names for arbiter ignition configs")
})
}
}