Skip to content

Commit

Permalink
Remove skips in semi-integ unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Reed committed May 23, 2022
1 parent a3675cf commit 0d013bc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 105 deletions.
32 changes: 25 additions & 7 deletions test/unit/cloud/affinity_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cloud_test

import (
"errors"
"fmt"

"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/aws/cluster-api-provider-cloudstack-staging/test/unit/dummies"
Expand Down Expand Up @@ -71,22 +72,39 @@ var _ = Describe("The AffinityGroup interface", func() {

When("using a real CloudStack client", func() {
BeforeEach(func() {
fmt.Println("blah2oomuch")
client = realCloudClient
dummies.AffinityGroup.ID = "" // Force name fetching.
})
It("creates an affinity group.", func() {
Ω(client.GetOrCreateAffinityGroup(dummies.AffinityGroup)).Should(Succeed())
})
It("associates an affinity group.", func() {
Ω(client.GetOrCreateVMInstance(
dummies.CSMachine1, dummies.CAPIMachine, dummies.CSCluster, dummies.CSZone1, dummies.CSAffinityGroup, "",
)).Should(Succeed())
Ω(client.GetOrCreateAffinityGroup(dummies.AffinityGroup)).Should(Succeed())
Ω(client.AssociateAffinityGroup(dummies.CSMachine1, *dummies.AffinityGroup)).Should(Succeed())
})
// Context("with an existing VM", func() {
// BeforeEach(func() {
// Ω(client.ResolveZone(dummies.CSZone1)).Should(Succeed())
// Ω(dummies.CSZone1.Spec.ID).ShouldNot(BeEmpty())
// dummies.CSMachine1.Status.ZoneID = dummies.CSZone1.Spec.ID
// dummies.CSMachine1.Spec.DiskOffering.Name = ""
// dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = ""
// Ω(client.GetOrCreateIsolatedNetwork(dummies.CSZone1, dummies.CSISONet1, dummies.CSCluster)).Should(Succeed())
// dummies.CSZone1.Spec.Network.ID = dummies.CSISONet1.Spec.ID
// Ω(client.GetOrCreateVMInstance(
// dummies.CSMachine1, dummies.CAPIMachine, dummies.CSCluster, dummies.CSZone1, dummies.CSAffinityGroup, "",
// )).Should(Succeed())
// })
// AfterEach(func() {
// Ω(client.DestroyVMInstance(dummies.CSMachine1)).Should(MatchError("VM deletion in progress"))
// })
// It("associates an affinity group and disassociates it", func() {
// Ω(client.GetOrCreateAffinityGroup(dummies.AffinityGroup)).Should(Succeed())
// Ω(client.AssociateAffinityGroup(dummies.CSMachine1, *dummies.AffinityGroup)).Should(Succeed())
// Ω(client.DisassociateAffinityGroup(dummies.CSMachine1, *dummies.AffinityGroup)).Should(Succeed())
// })
// })
It("deletes an affinity group.", func() {
Ω(client.DeleteAffinityGroup(dummies.AffinityGroup)).Should(Succeed())
Ω(client.FetchAffinityGroup(dummies.AffinityGroup)).ShouldNot(Succeed())
})
Context("del", func() {})
})
})
14 changes: 14 additions & 0 deletions test/unit/cloud/cloud_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"testing"

"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/aws/cluster-api-provider-cloudstack-staging/test/unit/dummies"
"github.com/aws/cluster-api-provider-cloudstack/pkg/cloud"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var (
realCloudClient cloud.Client
client cloud.Client
realCSClient *cloudstack.CloudStackClient
)

Expand All @@ -36,9 +38,21 @@ var _ = BeforeSuite(func() {
var connectionErr error
realCloudClient, connectionErr = cloud.NewClient(projDir + "/cloud-config")
Ω(connectionErr).ShouldNot(HaveOccurred())

Ω().Should(Succeed())
})

func TestCloud(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cloud Suite")
}

// FetchIntegTestResources runs through basic CloudStack Client setup methods needed to test others.
func FetchIntegTestResources() {
Ω(client.ResolveZone(dummies.CSZone1)).Should(Succeed())
Ω(dummies.CSZone1.Spec.ID).ShouldNot(BeEmpty())
dummies.CSMachine1.Status.ZoneID = dummies.CSZone1.Spec.ID
dummies.CSMachine1.Spec.DiskOffering.Name = ""
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = ""
Ω(client.GetOrCreateIsolatedNetwork(dummies.CSZone1, dummies.CSISONet1, dummies.CSCluster)).Should(Succeed())
}
43 changes: 12 additions & 31 deletions test/unit/cloud/isolated_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,8 @@ var _ = Describe("Network", func() {
})

Context("Networking Integ Tests", func() {
client, connectionErr := cloud.NewClient("../../cloud-config")

BeforeEach(func() {
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
Skip("Could not connect to ACS instance.")
}
if err := client.ResolveNetwork(&dummies.Net1); err != nil {
Skip("Could not find network.")
}

client = realCloudClient
// Delete any existing tags
existingTags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)
if err != nil {
Expand All @@ -213,6 +205,17 @@ var _ = Describe("Network", func() {
Fail("Failed to delete existing tags. Error: " + err.Error())
}
}
dummies.SetDummyVars()

// Setup Isolated Network Dummy Vars.
dummies.CSISONet1.Spec.ID = "" // Make CAPC methods resolve this.
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = "" // Make CAPC methods resolve this.
dummies.CSZone1.Spec.ID = "" // Make CAPC methods resolve this.
dummies.CSCluster.Status.Zones = capcv1.ZoneStatusMap{}

// Get Zone info needed for network testing.
Ω(client.ResolveZone(dummies.CSZone1)).Should(Succeed())
dummies.CSISONet1.Spec.ID = ""
})

It("fetches an isolated network", func() {
Expand All @@ -231,28 +234,6 @@ var _ = Describe("Network", func() {
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = ""
Ω(client.ResolveNetwork(&dummies.ISONet1)).Should(Succeed())
})
})

Context("Network Semi-Integ Tests", func() {
client, connectionErr := cloud.NewClient("../../cloud-config")

BeforeEach(func() {
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
Skip("Could not connect to ACS instance.")
}

dummies.SetDummyVars()

// Setup Isolated Network Dummy Vars.
dummies.CSISONet1.Spec.ID = "" // Make CAPC methods resolve this.
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = "" // Make CAPC methods resolve this.
dummies.CSZone1.Spec.ID = "" // Make CAPC methods resolve this.
dummies.CSCluster.Status.Zones = capcv1.ZoneStatusMap{}

// Get Zone info needed for network testing.
Ω(client.ResolveZone(dummies.CSZone1)).Should(Succeed())
dummies.CSISONet1.Spec.ID = ""
})

It("adds an isolated network and doesn't fail when asked to GetOrCreateIsolatedNetwork multiple times", func() {
Ω(client.GetOrCreateIsolatedNetwork(dummies.CSZone1, dummies.CSISONet1, dummies.CSCluster)).Should(Succeed())
Expand Down
75 changes: 34 additions & 41 deletions test/unit/cloud/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,111 +29,104 @@ var _ = Describe("Tag Unit Tests", func() {
})

Context("Tag Integ Tests", func() {
client, connectionErr := cloud.NewClient("../../cloud-config")

BeforeEach(func() {
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
Skip("Could not connect to ACS instance.")
}
if err := client.ResolveNetwork(&dummies.Net1); err != nil {
Skip("Could not find network.")
}
client = realCloudClient
FetchIntegTestResources()

// Delete any existing tags
existingTags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)
existingTags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
if err != nil {
Fail("Failed to get existing tags. Error: " + err.Error())
}
if len(existingTags) > 0 {
err = client.DeleteTags(cloud.ResourceTypeNetwork, dummies.Net1.ID, existingTags)
err = client.DeleteTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, existingTags)
if err != nil {
Fail("Failed to delete existing tags. Error: " + err.Error())
}
}
})

It("adds and gets a resource tag", func() {
Ω(client.AddTags(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.Tags)).Should(Succeed())
Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Equal(dummies.Tags))
Ω(client.AddTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.Tags)).Should(Succeed())
Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Equal(dummies.Tags))
})

It("deletes a resource tag", func() {
Ω(client.AddTags(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.Tags)).Should(Succeed())
Ω(client.DeleteTags(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.Tags)).Should(Succeed())
Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Equal(map[string]string{}))
Ω(client.AddTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.Tags)).Should(Succeed())
Ω(client.DeleteTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.Tags)).Should(Succeed())
Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Equal(map[string]string{}))
})

It("returns an error when you delete a tag that doesn't exist", func() {
Ω(client.DeleteTags(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.Tags)).Should(Succeed())
Ω(client.DeleteTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.Tags)).Should(Succeed())
})

It("adds the tags for a cluster (resource created by CAPC)", func() {
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).
Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).
Should(Succeed())

// Verify tags
tags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)
tags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
Ω(err).ShouldNot(HaveOccurred())

Ω(tags[dummies.CSClusterTagKey]).Should(Equal(dummies.CSClusterTagVal))
})

It("does not fail when the cluster tags are added twice", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
})

It("doesn't adds the tags for a cluster (resource NOT created by CAPC)", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())

// Verify tags
tags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)
tags, err := client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
Ω(err).Should(BeNil())
Ω(tags[dummies.CreatedByCapcKey]).Should(Equal(""))
Ω(tags[dummies.CSClusterTagKey]).Should(Equal(""))
})

It("deletes a cluster tag", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())

Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.Net1.ID)).ShouldNot(HaveKey(dummies.CSClusterTagKey))
Ω(client.GetTags(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).ShouldNot(HaveKey(dummies.CSClusterTagKey))
})

It("adds and deletes a created by capc tag", func() {
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Succeed())
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Succeed())
})

It("does not fail when cluster and CAPC created tags are deleted twice", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Succeed())
Ω(client.DeleteCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Succeed())
})

It("does not allow a resource to be deleted when there are no tags", func() {
tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.Net1.ID)
tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
Ω(err).Should(BeNil())
Ω(tagsAllowDisposal).Should(BeFalse())
})

It("does not allow a resource to be deleted when there is a cluster tag", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.Net1.ID)
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
Ω(err).Should(BeNil())
Ω(tagsAllowDisposal).Should(BeFalse())
})

It("does allow a resource to be deleted when there are no cluster tags and there is a CAPC created tag", func() {
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.Net1.ID)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.Net1.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())
Ω(client.AddCreatedByCAPCTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)).Should(Succeed())
Ω(client.DeleteClusterTag(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID, dummies.CSCluster)).Should(Succeed())

tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.Net1.ID)
tagsAllowDisposal, err := client.DoClusterTagsAllowDisposal(cloud.ResourceTypeNetwork, dummies.CSISONet1.Spec.ID)
Ω(err).Should(BeNil())
Ω(tagsAllowDisposal).Should(BeTrue())
})
Expand Down
8 changes: 2 additions & 6 deletions test/unit/cloud/user_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/aws/cluster-api-provider-cloudstack-staging/test/unit/dummies"
"github.com/aws/cluster-api-provider-cloudstack/pkg/cloud"
. "github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"

. "github.com/onsi/gomega"
)
Expand All @@ -37,17 +36,14 @@ var _ = Describe("User Credentials", func() {
})

Context("UserCred Semi-Integ Tests", func() {
client, connectionErr := cloud.NewClient("../../cloud-config")
var domain cloud.Domain
var account cloud.Account
var user cloud.User

BeforeEach(func() {
if connectionErr != nil { // Only do these tests if an actual ACS instance is available via cloud-config.
Skip(errors.Wrapf(connectionErr, "Could not connect to ACS instance").Error())
}
client = realCloudClient

// Settup dummies.
// Setup dummies.
// TODO: move these to the test dummies package.
domain = cloud.Domain{Path: "ROOT/blah/blah/subsub"}
account = cloud.Account{Name: "SuperNested", Domain: domain}
Expand Down
Loading

0 comments on commit 0d013bc

Please sign in to comment.