@@ -17,76 +17,13 @@ limitations under the License.
17
17
package cloud_test
18
18
19
19
import (
20
- "fmt"
21
- "os"
22
20
"testing"
23
21
24
- "github.com/apache/cloudstack-go/v2/cloudstack"
25
22
. "github.com/onsi/ginkgo/v2"
26
23
. "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.
38
24
)
39
25
40
26
func TestCloud (t * testing.T ) {
41
27
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
- })
81
28
RunSpecs (t , "Cloud Suite" )
82
29
}
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