@@ -16,17 +16,82 @@ func defaultPlatform() *vsphere.Platform {
1616 return & vsphere.Platform {}
1717}
1818
19+ func validPlatform () * vsphere.Platform {
20+ return & vsphere.Platform {
21+ VCenters : []vsphere.VCenter {
22+ {
23+ Server : "test-vcenter" ,
24+ Port : 443 ,
25+ Username : "test-username" ,
26+ Password : "test-password" ,
27+ Datacenters : []string {
28+ "test-datacenter" ,
29+ },
30+ },
31+ },
32+ FailureDomains : []vsphere.FailureDomain {
33+ {
34+ Name : "test-east-1a" ,
35+ Region : "test-east" ,
36+ Zone : "test-east-1a" ,
37+ Server : "test-vcenter" ,
38+ Topology : vsphere.Topology {
39+ Datacenter : "test-datacenter" ,
40+ ComputeCluster : "/test-datacenter/host/test-cluster" ,
41+ Datastore : "/test-datacenter/datastore/test-datastore" ,
42+ Networks : []string {"test-portgroup" },
43+ ResourcePool : "/test-datacenter/host/test-cluster/Resources" ,
44+ Folder : "/test-datacenter/vm/test-folder" ,
45+ },
46+ },
47+ {
48+ Name : "test-east-2a" ,
49+ Region : "test-east" ,
50+ Zone : "test-east-2a" ,
51+ Server : "test-vcenter" ,
52+ Topology : vsphere.Topology {
53+ Datacenter : "test-datacenter" ,
54+ ComputeCluster : "/test-datacenter/host/test-cluster" ,
55+ Datastore : "/test-datacenter/datastore/test-datastore" ,
56+ Networks : []string {"test-portgroup" },
57+ ResourcePool : "/test-datacenter/host/test-cluster/Resources" ,
58+ Folder : "/test-datacenter/vm/test-folder" ,
59+ },
60+ },
61+ },
62+ }
63+ }
64+
1965func TestSetPlatformDefaults (t * testing.T ) {
2066 cases := []struct {
21- name string
22- platform * vsphere.Platform
23- expected * vsphere.Platform
67+ name string
68+ platform * vsphere.Platform
69+ expected * vsphere.Platform
70+ expectedRP string
2471 }{
2572 {
2673 name : "empty" ,
2774 platform : & vsphere.Platform {},
2875 expected : defaultPlatform (),
2976 },
77+ {
78+ name : "completed" ,
79+ platform : validPlatform (),
80+ expected : validPlatform (),
81+ expectedRP : "/test-datacenter/host/test-cluster/Resources" ,
82+ },
83+ {
84+ name : "incomplete" ,
85+ platform : func () * vsphere.Platform {
86+ p := validPlatform ()
87+ for _ , fd := range p .FailureDomains {
88+ fd .Topology .ResourcePool = ""
89+ }
90+ return p
91+ }(),
92+ expected : validPlatform (),
93+ expectedRP : "/test-datacenter/host/test-cluster/Resources" ,
94+ },
3095 }
3196 for _ , tc := range cases {
3297 t .Run (tc .name , func (t * testing.T ) {
@@ -37,6 +102,10 @@ func TestSetPlatformDefaults(t *testing.T) {
37102 }
38103 SetPlatformDefaults (tc .platform , ic )
39104 assert .Equal (t , tc .expected , tc .platform , "unexpected platform" )
105+
106+ for _ , fd := range tc .platform .FailureDomains {
107+ assert .Equal (t , tc .expectedRP , fd .Topology .ResourcePool , "invalid resource pool" )
108+ }
40109 })
41110 }
42111}
0 commit comments