@@ -19,99 +19,62 @@ package cloud_test
19
19
import (
20
20
infrav1 "github.com/aws/cluster-api-provider-cloudstack/api/v1beta1"
21
21
"github.com/aws/cluster-api-provider-cloudstack/pkg/cloud"
22
- "github.com/golang/mock/gomock"
23
22
. "github.com/onsi/ginkgo"
24
23
. "github.com/onsi/gomega"
25
24
)
26
25
27
26
var _ = Describe ("Tag Unit Tests" , func () {
28
- var ( // Declare shared vars.
29
- mockCtrl * gomock.Controller
30
- // mockClient *cloudstack.CloudStackClient
31
- // ags *cloudstack.MockAffinityGroupServiceIface
32
- // fakeAG *cloud.AffinityGroup
27
+ var (
33
28
cluster * infrav1.CloudStackCluster
34
- // machine *infrav1.CloudStackMachine
35
- // capiMachine *capiv1.Machine
36
- // client cloud.Client
37
29
)
38
30
39
31
BeforeEach (func () {
40
- // // Setup new mock services.
41
- // mockCtrl = gomock.NewController(GinkgoT())
42
- // mockClient = cloudstack.NewMockClient(mockCtrl)
43
- // ags = mockClient.AffinityGroup.(*cloudstack.MockAffinityGroupServiceIface)
44
- // client = cloud.NewClientFromCSAPIClient(mockClient)
45
- // fakeAG = &cloud.AffinityGroup{
46
- // Name: "FakeAffinityGroup",
47
- // Type: cloud.AffinityGroupType}
48
32
cluster = & infrav1.CloudStackCluster {Spec : infrav1.CloudStackClusterSpec {
49
33
Zone : "Zone1" , Network : "SharedGuestNet1" }}
50
- // machine = &infrav1.CloudStackMachine{Spec: infrav1.CloudStackMachineSpec{
51
- // Offering: "Medium Instance", Template: "Ubuntu20"}}
52
- // machine.ObjectMeta.SetName("rejoshed-affinity-group-test-vm")
53
- // capiMachine = &capiv1.Machine{}
54
34
})
55
35
56
- AfterEach (func () {
57
- mockCtrl .Finish ()
58
- })
59
-
60
- // It("fetches an affinity group", func() {
61
- // ags.EXPECT().GetAffinityGroupByName(fakeAG.Name).Return(&cloudstack.AffinityGroup{}, 1, nil)
62
-
63
- // Ω(client.GetOrCreateAffinityGroup(cluster, fakeAG)).Should(Succeed())
64
- // })
65
- // It("creates an affinity group", func() {
66
- // fakeAG.Id = "FakeID"
67
- // cluster.Spec.Account = "FakeAccount"
68
- // cluster.Status.DomainID = "FakeDomainId"
69
- // ags.EXPECT().GetAffinityGroupByID(fakeAG.Id).Return(nil, -1, errors.New("FakeError"))
70
- // ags.EXPECT().NewCreateAffinityGroupParams(fakeAG.Name, fakeAG.Type).
71
- // Return(&cloudstack.CreateAffinityGroupParams{})
72
- // ags.EXPECT().CreateAffinityGroup(ParamMatch(And(AccountEquals("FakeAccount"), DomainIdEquals("FakeDomainId")))).
73
- // Return(&cloudstack.CreateAffinityGroupResponse{}, nil)
74
-
75
- // Ω(client.GetOrCreateAffinityGroup(cluster, fakeAG)).Should(Succeed())
76
- // })
77
-
78
36
Context ("Tag Integ Tests" , func () {
79
37
client , connectionErr := cloud .NewClient ("../../cloud-config" )
80
38
81
- var ( // Declare shared vars.
82
- arbitraryTag * map [string ]string
83
- networkId string
39
+ const (
40
+ tagKey = "TestTag"
41
+ tagValue = "ArbitraryValue"
42
+ )
43
+
44
+ var (
45
+ networkId string
84
46
)
85
47
86
48
BeforeEach (func () {
87
49
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
88
50
Skip ("Could not connect to ACS instance." )
89
51
}
90
- arbitraryTag = & map [ string ] string { "Arbitrary" : "Tag" }
52
+
91
53
if err := client .GetOrCreateNetwork (cluster ); err != nil {
92
54
Skip ("Could not find network." )
93
55
}
56
+
94
57
networkId = cluster .Status .NetworkID
95
58
})
96
59
97
- AfterEach (func () {
98
- mockCtrl .Finish ()
60
+ It ("Tags a network with an arbitrary tag." , func () {
61
+ tags := map [string ]string {tagKey : tagValue }
62
+ // Delete the tag if it already exists from a prior test run, otherwise the test will fail.
63
+ _ = client .DeleteNetworkTags (networkId , tags )
64
+ Ω (client .TagNetwork (networkId , tags )).Should (Succeed ())
99
65
})
100
66
101
- PIt ("Tags a network with an arbitrary tag." , func () {
102
- // https://cloudstack.apache.org/api/apidocs-4.16/apis/createTags.html
103
- Ω (client .TagNetwork (networkId , * arbitraryTag )).Should (Succeed ())
67
+ It ("Fetches said tag." , func () {
68
+ tags , err := client .GetNetworkTags (networkId )
69
+ Ω (err ).Should (BeNil ())
70
+ Ω (tags [tagKey ]).Should (Equal (tagValue ))
104
71
})
105
- PIt ("Fethes said tag." , func () {
106
- // It's hard to say what exactly the best method here is. I assume there are many ways to fetch a tag.
107
- // Maybe something like GetNetworkTags, GetLBTags, etc...
108
- // https://cloudstack.apache.org/api/apidocs-4.16/apis/listTags.html
109
- // Ω(client.FetchTag(*arbitraryTag)).Should(Succeed())
110
- })
111
- PIt ("Deletes said tag." , func () {
112
- // Same, need some design through around how to delete tags.
113
- // https://cloudstack.apache.org/api/apidocs-4.16/apis/deleteTags.html
114
- // Ω(client.DeleteTags(networkId, *arbitraryTag)).Should(Succeed())
72
+
73
+ It ("Deletes said tag." , func () {
74
+ Ω (client .DeleteNetworkTags (networkId , map [string ]string {tagKey : tagValue })).Should (Succeed ())
75
+ remainingTags , err := client .GetNetworkTags (networkId )
76
+ Ω (err ).Should (BeNil ())
77
+ Ω (remainingTags [tagKey ]).Should (Equal ("" ))
115
78
})
116
79
})
117
80
})
0 commit comments