Debian Codegraph @

vdc_test.go

raw symbols SCIP
1 /*
2 * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
3 */
4
5 package govcd
6
7 import (
8 "github.com/hmrc/vmware-govcd/testutil"
9
10 . "gopkg.in/check.v1"
11 )
12
13 func (s *S) Test_FindVDCNetwork(c *C) {
14
15 testServer.Response(200, nil, orgvdcnetExample)
16
17 net, err := s.vdc.FindVDCNetwork("networkName")
18
19 _ = testServer.WaitRequest()
20
21 c.Assert(err, IsNil)
22 c.Assert(net, NotNil)
23 c.Assert(net.OrgVDCNetwork.HREF, Equals, "http://localhost:4444/api/network/cb0f4c9e-1a46-49d4-9fcb-d228000a6bc1")
24
25 // find Invalid Network
26 net, err = s.vdc.FindVDCNetwork("INVALID")
27 c.Assert(err, NotNil)
28 }
29
30 func (s *S) Test_GetVDCOrg(c *C) {
31
32 testServer.Response(200, nil, orgExample)
33
34 org, err := s.vdc.GetVDCOrg()
35
36 _ = testServer.WaitRequest()
37
38 c.Assert(err, IsNil)
39 c.Assert(org, NotNil)
40 c.Assert(org.Org.HREF, Equals, "http://localhost:4444/api/org/23bd2339-c55f-403c-baf3-13109e8c8d57")
41 }
42
43 func (s *S) Test_NewVdc(c *C) {
44
45 testServer.Response(200, nil, vdcExample)
46 err := s.vdc.Refresh()
47 _ = testServer.WaitRequest()
48 c.Assert(err, IsNil)
49
50 c.Assert(s.vdc.Vdc.Link[0].Rel, Equals, "up")
51 c.Assert(s.vdc.Vdc.Link[0].Type, Equals, "application/vnd.vmware.vcloud.org+xml")
52 c.Assert(s.vdc.Vdc.Link[0].HREF, Equals, "http://localhost:4444/api/org/11111111-1111-1111-1111-111111111111")
53
54 c.Assert(s.vdc.Vdc.AllocationModel, Equals, "AllocationPool")
55
56 for _, v := range s.vdc.Vdc.ComputeCapacity {
57 c.Assert(v.CPU.Units, Equals, "MHz")
58 c.Assert(v.CPU.Allocated, Equals, int64(30000))
59 c.Assert(v.CPU.Limit, Equals, int64(30000))
60 c.Assert(v.CPU.Reserved, Equals, int64(15000))
61 c.Assert(v.CPU.Used, Equals, int64(0))
62 c.Assert(v.CPU.Overhead, Equals, int64(0))
63 c.Assert(v.Memory.Units, Equals, "MB")
64 c.Assert(v.Memory.Allocated, Equals, int64(61440))
65 c.Assert(v.Memory.Limit, Equals, int64(61440))
66 c.Assert(v.Memory.Reserved, Equals, int64(61440))
67 c.Assert(v.Memory.Used, Equals, int64(6144))
68 c.Assert(v.Memory.Overhead, Equals, int64(95))
69 }
70
71 c.Assert(s.vdc.Vdc.ResourceEntities[0].ResourceEntity[0].Name, Equals, "vAppTemplate")
72 c.Assert(s.vdc.Vdc.ResourceEntities[0].ResourceEntity[0].Type, Equals, "application/vnd.vmware.vcloud.vAppTemplate+xml")
73 c.Assert(s.vdc.Vdc.ResourceEntities[0].ResourceEntity[0].HREF, Equals, "http://localhost:4444/api/vAppTemplate/vappTemplate-22222222-2222-2222-2222-222222222222")
74
75 for _, v := range s.vdc.Vdc.AvailableNetworks {
76 for _, v2 := range v.Network {
77 c.Assert(v2.Name, Equals, "networkName")
78 c.Assert(v2.Type, Equals, "application/vnd.vmware.vcloud.network+xml")
79 c.Assert(v2.HREF, Equals, "http://localhost:4444/api/network/44444444-4444-4444-4444-4444444444444")
80 }
81 }
82
83 c.Assert(s.vdc.Vdc.NicQuota, Equals, 0)
84 c.Assert(s.vdc.Vdc.NetworkQuota, Equals, 20)
85 c.Assert(s.vdc.Vdc.UsedNetworkCount, Equals, 0)
86 c.Assert(s.vdc.Vdc.VMQuota, Equals, 0)
87 c.Assert(s.vdc.Vdc.IsEnabled, Equals, true)
88
89 for _, v := range s.vdc.Vdc.VdcStorageProfiles {
90 for _, v2 := range v.VdcStorageProfile {
91 c.Assert(v2.Name, Equals, "storageProfile")
92 c.Assert(v2.Type, Equals, "application/vnd.vmware.vcloud.vdcStorageProfile+xml")
93 c.Assert(v2.HREF, Equals, "http://localhost:4444/api/vdcStorageProfile/88888888-8888-8888-8888-888888888888")
94 }
95 }
96
97 }
98
99 func (s *S) Test_FindVApp(c *C) {
100
101 // testServer.Response(200, nil, vappExample)
102
103 // vapp, err := s.vdc.FindVAppByID("")
104
105 // _ = testServer.WaitRequest()
106 // testServer.Flush()
107 // c.Assert(err, IsNil)
108
109 testServer.ResponseMap(2, testutil.ResponseMap{
110 "/api/vdc/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vdcExample},
111 "/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
112 })
113
114 _, err := s.vdc.FindVAppByName("myVApp")
115
116 _ = testServer.WaitRequests(2)
117
118 c.Assert(err, IsNil)
119
120 testServer.ResponseMap(2, testutil.ResponseMap{
121 "/api/vdc/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vdcExample},
122 "/api/vApp/vapp-00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, vappExample},
123 })
124
125 _, err = s.vdc.FindVAppByID("urn:vcloud:vapp:00000000-0000-0000-0000-000000000000")
126
127 _ = testServer.WaitRequests(2)
128
129 c.Assert(err, IsNil)
130
131 }
132
133 var vdcExample = `
134 <?xml version="1.0" ?>
135 <Vdc href="http://localhost:4444/api/vdc/00000000-0000-0000-0000-000000000000" id="urn:vcloud:vdc:00000000-0000-0000-0000-000000000000" name="M916272752-5793" status="1" type="application/vnd.vmware.vcloud.vdc+xml" xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in stance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.6.32.3/api/v1.5/schema/master.xsd">
136 <Link href="http://localhost:4444/api/org/11111111-1111-1111-1111-111111111111" rel="up" type="application/vnd.vmware.vcloud.org+xml"/>
137 <Link href="http://localhost:4444/api/vdc/00000000-0000-0000-0000-000000000000/edgeGateways" rel="edgeGateways" type="application/vnd.vmware.vcloud.query.records+xml"/>
138 <AllocationModel>AllocationPool</AllocationModel>
139 <ComputeCapacity>
140 <Cpu>
141 <Units>MHz</Units>
142 <Allocated>30000</Allocated>
143 <Limit>30000</Limit>
144 <Reserved>15000</Reserved>
145 <Used>0</Used>
146 <Overhead>0</Overhead>
147 </Cpu>
148 <Memory>
149 <Units>MB</Units>
150 <Allocated>61440</Allocated>
151 <Limit>61440</Limit>
152 <Reserved>61440</Reserved>
153 <Used>6144</Used>
154 <Overhead>95</Overhead>
155 </Memory>
156 </ComputeCapacity>
157 <ResourceEntities>
158 <ResourceEntity href="http://localhost:4444/api/vAppTemplate/vappTemplate-22222222-2222-2222-2222-222222222222" name="vAppTemplate" type="application/vnd.vmware.vcloud.vAppTemplate+xml"/>
159 <ResourceEntity href="http://localhost:4444/api/vApp/vapp-00000000-0000-0000-0000-000000000000" name="myVApp" type="application/vnd.vmware.vcloud.vApp+xml"/>
160 </ResourceEntities>
161 <AvailableNetworks>
162 <Network href="http://localhost:4444/api/network/44444444-4444-4444-4444-4444444444444" name="networkName" type="application/vnd.vmware.vcloud.network+xml"/>
163 </AvailableNetworks>
164 <Capabilities>
165 <SupportedHardwareVersions>
166 <SupportedHardwareVersion>vmx-10</SupportedHardwareVersion>
167 </SupportedHardwareVersions>
168 </Capabilities>
169 <NicQuota>0</NicQuota>
170 <NetworkQuota>20</NetworkQuota>
171 <UsedNetworkCount>0</UsedNetworkCount>
172 <VmQuota>0</VmQuota>
173 <IsEnabled>true</IsEnabled>
174 <VdcStorageProfiles>
175 <VdcStorageProfile href="http://localhost:4444/api/vdcStorageProfile/88888888-8888-8888-8888-888888888888" name="storageProfile" type="application/vnd.vmware.vcloud.vdcStorageProfile+xml"/>
176 </VdcStorageProfiles>
177 </Vdc>
178 `