Skip to content

Commit ca656c3

Browse files
author
Joshua Reed
committed
Updated file. Git knows it was moved and updated now.
1 parent e9ffe54 commit ca656c3

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/unit/cloud/cloud_suite_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,76 @@ limitations under the License.
1717
package cloud_test
1818

1919
import (
20+
"fmt"
21+
"os"
2022
"testing"
2123

24+
"github.com/apache/cloudstack-go/v2/cloudstack"
2225
. "github.com/onsi/ginkgo/v2"
2326
. "github.com/onsi/gomega"
27+
"k8s.io/apimachinery/pkg/util/uuid"
28+
"sigs.k8s.io/cluster-api-provider-cloudstack/pkg/cloud"
29+
"sigs.k8s.io/cluster-api-provider-cloudstack/test/dummies"
30+
"sigs.k8s.io/cluster-api-provider-cloudstack/test/helpers"
31+
)
32+
33+
var (
34+
realCloudClient cloud.Client
35+
client cloud.Client
36+
realCSClient *cloudstack.CloudStackClient
37+
testDomainPath string // Needed in before and in after suite.
2438
)
2539

2640
func TestCloud(t *testing.T) {
2741
RegisterFailHandler(Fail)
42+
BeforeSuite(func() {
43+
// Create a real cloud client.
44+
projDir := os.Getenv("PROJECT_DIR")
45+
fmt.Println(projDir)
46+
fmt.Println(projDir)
47+
fmt.Println(projDir)
48+
var connectionErr error
49+
realCloudClient, connectionErr = cloud.NewClient(projDir + "/cloud-config")
50+
Ω(connectionErr).ShouldNot(HaveOccurred())
51+
52+
// Create a real CloudStack client.
53+
realCSClient, connectionErr = helpers.NewCSClient()
54+
Ω(connectionErr).ShouldNot(HaveOccurred())
55+
56+
// Create a new account and user to run tests that use a real ACS instance.
57+
uid := string(uuid.NewUUID())
58+
newAccount := cloud.Account{
59+
Name: "TestAccount-" + uid,
60+
Domain: cloud.Domain{Name: "TestDomain-" + uid, Path: "ROOT/TestDomain-" + uid}}
61+
newUser := cloud.User{Account: newAccount}
62+
Ω(helpers.GetOrCreateUserWithKey(realCSClient, &newUser)).Should(Succeed())
63+
testDomainPath = newAccount.Domain.Path
64+
65+
Ω(newUser.APIKey).ShouldNot(BeEmpty())
66+
67+
// Switch to test account user.
68+
cfg := cloud.Config{APIKey: newUser.APIKey, SecretKey: newUser.SecretKey}
69+
realCloudClient, connectionErr = realCloudClient.NewClientFromSpec(cfg)
70+
Ω(connectionErr).ShouldNot(HaveOccurred())
71+
})
72+
AfterSuite(func() {
73+
if realCSClient != nil { // Check for nil in case the before suite setup failed.
74+
// Delete created domain.
75+
id, err, found := helpers.GetDomainByPath(realCSClient, testDomainPath)
76+
Ω(err).ShouldNot(HaveOccurred())
77+
Ω(found).Should(BeTrue())
78+
Ω(helpers.DeleteDomain(realCSClient, id)).Should(Succeed())
79+
}
80+
})
2881
RunSpecs(t, "Cloud Suite")
2982
}
83+
84+
// FetchIntegTestResources runs through basic CloudStack Client setup methods needed to test others.
85+
func FetchIntegTestResources() {
86+
realCloudClient.ResolveZone(dummies.CSZone1)
87+
Ω(dummies.CSZone1.Spec.ID).ShouldNot(BeEmpty())
88+
dummies.CSMachine1.Status.ZoneID = dummies.CSZone1.Spec.ID
89+
dummies.CSMachine1.Spec.DiskOffering.Name = ""
90+
dummies.CSCluster.Spec.ControlPlaneEndpoint.Host = ""
91+
Ω(realCloudClient.GetOrCreateIsolatedNetwork(dummies.CSZone1, dummies.CSISONet1, dummies.CSCluster)).Should(Succeed())
92+
}

0 commit comments

Comments
 (0)