Skip to content

Commit 0dc5ab0

Browse files
author
Joshua Reed
committed
Fixup before and after suite to use the fail handler.
1 parent e314aae commit 0dc5ab0

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

test/unit/cloud/cloud_suite_test.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,44 @@ var (
3636
testDomainPath string // Needed in before and in after suite.
3737
)
3838

39-
var _ = BeforeSuite(func() {
40-
// Create a real cloud client.
41-
projDir := os.Getenv("PROJECT_DIR")
42-
var connectionErr error
43-
realCloudClient, connectionErr = cloud.NewClient(projDir + "/cloud-config")
44-
Ω(connectionErr).ShouldNot(HaveOccurred())
45-
46-
// Create a real CloudStack client.
47-
realCSClient, connectionErr = helpers.NewCSClient()
48-
Ω(connectionErr).ShouldNot(HaveOccurred())
49-
50-
// Create a new account and user to run tests that use a real ACS instance.
51-
uid := string(uuid.NewUUID())
52-
newAccount := cloud.Account{
53-
Name: "TestAccount-" + uid,
54-
Domain: cloud.Domain{Name: "TestDomain-" + uid, Path: "ROOT/TestDomain-" + uid}}
55-
newUser := cloud.User{Account: newAccount}
56-
Ω(helpers.GetOrCreateUserWithKey(realCSClient, &newUser)).Should(Succeed())
57-
testDomainPath = newAccount.Domain.Path
39+
func TestCloud(t *testing.T) {
40+
RegisterFailHandler(Fail)
41+
BeforeSuite(func() {
42+
// Create a real cloud client.
43+
projDir := os.Getenv("PROJECT_DIR")
44+
var connectionErr error
45+
realCloudClient, connectionErr = cloud.NewClient(projDir + "/cloud-config")
46+
Ω(connectionErr).ShouldNot(HaveOccured())
5847

59-
Ω(newUser.APIKey).ShouldNot(BeEmpty())
48+
// Create a real CloudStack client.
49+
realCSClient, connectionErr = helpers.NewCSClient()
50+
Ω(connectionErr).ShouldNot(HaveOccurred())
6051

61-
// Switch to test account user.
62-
cfg := cloud.Config{APIKey: newUser.APIKey, SecretKey: newUser.SecretKey}
63-
realCloudClient, connectionErr = realCloudClient.NewClientFromSpec(cfg)
64-
Ω(connectionErr).ShouldNot(HaveOccurred())
65-
})
52+
// Create a new account and user to run tests that use a real ACS instance.
53+
uid := string(uuid.NewUUID())
54+
newAccount := cloud.Account{
55+
Name: "TestAccount-" + uid,
56+
Domain: cloud.Domain{Name: "TestDomain-" + uid, Path: "ROOT/TestDomain-" + uid}}
57+
newUser := cloud.User{Account: newAccount}
58+
Ω(helpers.GetOrCreateUserWithKey(realCSClient, &newUser)).Should(Succeed())
59+
testDomainPath = newAccount.Domain.Path
6660

67-
var _ = AfterSuite(func() {
68-
// Delete created domain.
69-
id, err, found := helpers.GetDomainByPath(realCSClient, testDomainPath)
70-
Ω(err).ShouldNot(HaveOccurred())
71-
Ω(found).Should(BeTrue())
72-
Ω(helpers.DeleteDomain(realCSClient, id)).Should(Succeed())
73-
})
61+
Ω(newUser.APIKey).ShouldNot(BeEmpty())
7462

75-
func TestCloud(t *testing.T) {
76-
RegisterFailHandler(Fail)
63+
// Switch to test account user.
64+
cfg := cloud.Config{APIKey: newUser.APIKey, SecretKey: newUser.SecretKey}
65+
realCloudClient, connectionErr = realCloudClient.NewClientFromSpec(cfg)
66+
Ω(connectionErr).ShouldNot(HaveOccurred())
67+
})
68+
AfterSuite(func() {
69+
if realCSClient != nil { // Check for nil in case the before suite setup failed.
70+
// Delete created domain.
71+
id, err, found := helpers.GetDomainByPath(realCSClient, testDomainPath)
72+
Ω(err).ShouldNot(HaveOccurred())
73+
Ω(found).Should(BeTrue())
74+
Ω(helpers.DeleteDomain(realCSClient, id)).Should(Succeed())
75+
}
76+
})
7777
RunSpecs(t, "Cloud Suite")
7878
}
7979

0 commit comments

Comments
 (0)