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