@@ -17,131 +17,103 @@ import (
17
17
)
18
18
19
19
func TestVariableValidation (t * testing.T ) {
20
- testImageName := "fake-image"
21
- testPEClusterName := "fake-pe-cluster"
22
- testProject := ptr .To (v1alpha1.NutanixResourceIdentifier {
20
+ requiredFields := minimumClusterConfigSpec ()
21
+
22
+ withAdditionalCategories := minimumClusterConfigSpec ()
23
+ withAdditionalCategories .ControlPlane .Nutanix .MachineDetails .AdditionalCategories = []v1alpha1.NutanixCategoryIdentifier {
24
+ {
25
+ Key : "fake-key" ,
26
+ Value : "fake-value1" ,
27
+ },
28
+ {
29
+ Key : "fake-key" ,
30
+ Value : "fake-value2" ,
31
+ },
32
+ }
33
+
34
+ withProject := minimumClusterConfigSpec ()
35
+ withProject .ControlPlane .Nutanix .MachineDetails .Project = ptr .To (v1alpha1.NutanixResourceIdentifier {
23
36
Type : capxv1 .NutanixIdentifierName ,
24
37
Name : ptr .To ("fake-project" ),
25
38
})
39
+
40
+ invalidBootType := minimumClusterConfigSpec ()
41
+ invalidBootType .ControlPlane .Nutanix .MachineDetails .BootType = "invalid-boot-type"
42
+
43
+ invalidImageType := minimumClusterConfigSpec ()
44
+ invalidImageType .ControlPlane .Nutanix .MachineDetails .Image .Type = "invalid-image-type"
45
+
46
+ invalidClusterType := minimumClusterConfigSpec ()
47
+ invalidClusterType .ControlPlane .Nutanix .MachineDetails .Cluster .Type = "invalid-cluster-type"
48
+
49
+ invalidProjectType := minimumClusterConfigSpec ()
50
+ invalidProjectType .ControlPlane .Nutanix .MachineDetails .Project = ptr .To (v1alpha1.NutanixResourceIdentifier {
51
+ Type : "invalid-project-type" ,
52
+ Name : ptr .To ("fake-project" ),
53
+ })
54
+
26
55
capitest .ValidateDiscoverVariables (
27
56
t ,
28
57
clusterconfig .MetaVariableName ,
29
58
ptr .To (v1alpha1.ClusterConfigSpec {Nutanix : & v1alpha1.NutanixSpec {}}.VariableSchema ()),
30
59
true ,
31
60
nutanixclusterconfig .NewVariable ,
32
61
capitest.VariableTestDef {
33
- Name : "all fields set" ,
34
- Vals : v1alpha1.ClusterConfigSpec {
35
- ControlPlane : & v1alpha1.NodeConfigSpec {
36
- Nutanix : & v1alpha1.NutanixNodeSpec {
37
- MachineDetails : v1alpha1.NutanixMachineDetails {
38
- BootType : v1alpha1 .NutanixBootType (capxv1 .NutanixBootTypeLegacy ),
39
- VCPUSockets : 2 ,
40
- VCPUsPerSocket : 1 ,
41
- Image : v1alpha1.NutanixResourceIdentifier {
42
- Type : capxv1 .NutanixIdentifierName ,
43
- Name : & testImageName ,
44
- },
45
- Cluster : v1alpha1.NutanixResourceIdentifier {
46
- Type : capxv1 .NutanixIdentifierName ,
47
- Name : & testPEClusterName ,
48
- },
49
- MemorySize : resource .MustParse ("8Gi" ),
50
- Project : testProject ,
51
- SystemDiskSize : resource .MustParse ("40Gi" ),
52
- Subnets : []v1alpha1.NutanixResourceIdentifier {},
53
- AdditionalCategories : []v1alpha1.NutanixCategoryIdentifier {
54
- {
55
- Key : "fake-key" ,
56
- Value : "fake-value1" ,
57
- },
58
- {
59
- Key : "fake-key" ,
60
- Value : "fake-value2" ,
61
- },
62
- },
63
- },
64
- },
65
- },
66
- },
62
+ Name : "required fields set" ,
63
+ Vals : requiredFields ,
67
64
},
68
65
capitest.VariableTestDef {
69
- Name : "invalid boot type" ,
70
- Vals : v1alpha1.ClusterConfigSpec {
71
- ControlPlane : & v1alpha1.NodeConfigSpec {
72
- Nutanix : & v1alpha1.NutanixNodeSpec {
73
- MachineDetails : v1alpha1.NutanixMachineDetails {
74
- BootType : "invalid" ,
75
- VCPUSockets : 2 ,
76
- VCPUsPerSocket : 1 ,
77
- Image : v1alpha1.NutanixResourceIdentifier {
78
- Type : capxv1 .NutanixIdentifierName ,
79
- Name : & testImageName ,
80
- },
81
- Cluster : v1alpha1.NutanixResourceIdentifier {
82
- Type : capxv1 .NutanixIdentifierName ,
83
- Name : & testPEClusterName ,
84
- },
85
- MemorySize : resource .MustParse ("8Gi" ),
86
- SystemDiskSize : resource .MustParse ("40Gi" ),
87
- Subnets : []v1alpha1.NutanixResourceIdentifier {},
88
- },
89
- },
90
- },
91
- },
66
+ Name : "additional categories set" ,
67
+ Vals : withAdditionalCategories ,
68
+ },
69
+ capitest.VariableTestDef {
70
+ Name : "project set" ,
71
+ Vals : withProject ,
72
+ },
73
+ capitest.VariableTestDef {
74
+ Name : "invalid boot type" ,
75
+ Vals : invalidBootType ,
92
76
ExpectError : true ,
93
77
},
94
78
capitest.VariableTestDef {
95
- Name : "invalid image type" ,
96
- Vals : v1alpha1.ClusterConfigSpec {
97
- ControlPlane : & v1alpha1.NodeConfigSpec {
98
- Nutanix : & v1alpha1.NutanixNodeSpec {
99
- MachineDetails : v1alpha1.NutanixMachineDetails {
100
- BootType : v1alpha1 .NutanixBootType (capxv1 .NutanixBootTypeLegacy ),
101
- VCPUSockets : 2 ,
102
- VCPUsPerSocket : 1 ,
103
- Image : v1alpha1.NutanixResourceIdentifier {
104
- Type : "invalid" ,
105
- Name : & testImageName ,
106
- },
107
- Cluster : v1alpha1.NutanixResourceIdentifier {
108
- Type : capxv1 .NutanixIdentifierName ,
109
- Name : & testPEClusterName ,
110
- },
111
- MemorySize : resource .MustParse ("8Gi" ),
112
- SystemDiskSize : resource .MustParse ("40Gi" ),
113
- Subnets : []v1alpha1.NutanixResourceIdentifier {},
114
- },
115
- },
116
- },
117
- },
79
+ Name : "invalid image type" ,
80
+ Vals : invalidImageType ,
81
+ ExpectError : true ,
82
+ },
83
+ capitest.VariableTestDef {
84
+ Name : "invalid cluster type" ,
85
+ Vals : invalidClusterType ,
118
86
ExpectError : true ,
119
87
},
120
88
capitest.VariableTestDef {
121
- Name : "invalid cluster type" ,
122
- Vals : v1alpha1.ClusterConfigSpec {
123
- ControlPlane : & v1alpha1.NodeConfigSpec {
124
- Nutanix : & v1alpha1.NutanixNodeSpec {
125
- MachineDetails : v1alpha1.NutanixMachineDetails {
126
- BootType : v1alpha1 .NutanixBootType (capxv1 .NutanixBootTypeLegacy ),
127
- VCPUSockets : 2 ,
128
- VCPUsPerSocket : 1 ,
129
- Image : v1alpha1.NutanixResourceIdentifier {
130
- Type : capxv1 .NutanixIdentifierName ,
131
- Name : & testImageName ,
132
- },
133
- Cluster : v1alpha1.NutanixResourceIdentifier {
134
- Type : "invalid" ,
135
- Name : & testPEClusterName ,
136
- },
137
- MemorySize : resource .MustParse ("8Gi" ),
138
- SystemDiskSize : resource .MustParse ("40Gi" ),
139
- Subnets : []v1alpha1.NutanixResourceIdentifier {},
140
- },
89
+ Name : "invalid project type" ,
90
+ Vals : invalidProjectType ,
91
+ ExpectError : true ,
92
+ },
93
+ )
94
+ }
95
+
96
+ func minimumClusterConfigSpec () v1alpha1.ClusterConfigSpec {
97
+ return v1alpha1.ClusterConfigSpec {
98
+ ControlPlane : & v1alpha1.NodeConfigSpec {
99
+ Nutanix : & v1alpha1.NutanixNodeSpec {
100
+ MachineDetails : v1alpha1.NutanixMachineDetails {
101
+ BootType : v1alpha1 .NutanixBootType (capxv1 .NutanixBootTypeLegacy ),
102
+ VCPUSockets : 2 ,
103
+ VCPUsPerSocket : 1 ,
104
+ Image : v1alpha1.NutanixResourceIdentifier {
105
+ Type : capxv1 .NutanixIdentifierName ,
106
+ Name : ptr .To ("fake-image" ),
107
+ },
108
+ Cluster : v1alpha1.NutanixResourceIdentifier {
109
+ Type : capxv1 .NutanixIdentifierName ,
110
+ Name : ptr .To ("fake-pe-cluster" ),
141
111
},
112
+ MemorySize : resource .MustParse ("8Gi" ),
113
+ SystemDiskSize : resource .MustParse ("40Gi" ),
114
+ Subnets : []v1alpha1.NutanixResourceIdentifier {},
142
115
},
143
116
},
144
- ExpectError : true ,
145
117
},
146
- )
118
+ }
147
119
}
0 commit comments