Skip to content

Commit 3ed31ff

Browse files
committed
Fix invalid domain/account tests
Add error messages when failing
1 parent 6ed691d commit 3ed31ff

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pkg/cloud/user_credentials.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ func (c *client) ResolveAccount(account *Account) error {
140140
resp, retErr := c.cs.Account.ListAccounts(p)
141141
if retErr != nil {
142142
return retErr
143+
} else if resp.Count == 0 {
144+
return errors.Errorf("could not find account %s", account.Name)
143145
} else if resp.Count != 1 {
144146
return errors.Errorf("expected 1 Account with account name %s in domain ID %s, but got %d",
145147
account.Name, account.Domain.ID, resp.Count)

test/e2e/common.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func DestroyOneMachine(clusterName string, machineType string) {
206206
Byf("Listing machines with %q", matcher)
207207
listResp, err := client.VirtualMachine.ListVirtualMachines(client.VirtualMachine.NewListVirtualMachinesParams())
208208
if err != nil {
209-
Fail("Failed to list machines")
209+
Fail("Failed to list machines: " + err.Error())
210210
}
211211
var vmToDestroy *cloudstack.VirtualMachine
212212
originalCount := 0
@@ -224,13 +224,13 @@ func DestroyOneMachine(clusterName string, machineType string) {
224224
stopParams.SetForced(true)
225225
_, err = client.VirtualMachine.StopVirtualMachine(stopParams)
226226
if err != nil {
227-
Fail("Failed to stop machine")
227+
Fail("Failed to stop machine: " + err.Error())
228228
}
229229
destroyParams := client.VirtualMachine.NewDestroyVirtualMachineParams(vmToDestroy.Id)
230230
destroyParams.SetExpunge(true)
231231
_, err = client.VirtualMachine.DestroyVirtualMachine(destroyParams)
232232
if err != nil {
233-
Fail("Failed to destroy machine")
233+
Fail("Failed to destroy machine: " + err.Error())
234234
}
235235
}
236236

@@ -252,7 +252,7 @@ func CheckAffinityGroup(clusterName string, affinityType string) []string {
252252
By("Listing all machines")
253253
listResp, err := client.VirtualMachine.ListVirtualMachines(client.VirtualMachine.NewListVirtualMachinesParams())
254254
if err != nil {
255-
Fail("Failed to list machines")
255+
Fail("Failed to list machines: " + err.Error())
256256
}
257257
affinityTypeString := strings.Title(fmt.Sprintf("%sAffinity", affinityType))
258258
cpHostIdSet := make(map[string]bool)
@@ -271,7 +271,7 @@ func CheckAffinityGroup(clusterName string, affinityType string) []string {
271271
affinityIds = append(affinityIds, affinity.Id)
272272
affinity, _, _ := client.AffinityGroup.GetAffinityGroupByID(affinity.Id)
273273
if err != nil {
274-
Fail("Failed to get affinity group for " + affinity.Id)
274+
Fail("Failed to get affinity group for " + affinity.Id + " : " + err.Error())
275275
}
276276
if !strings.Contains(affinity.Name, affinityTypeString) {
277277
Fail(affinity.Name + " does not contain " + affinityTypeString)
@@ -307,11 +307,11 @@ func createCloudStackClient() *cloudstack.CloudStackClient {
307307
encodedSecret := os.Getenv("CLOUDSTACK_B64ENCODED_SECRET")
308308
secret, err := base64.StdEncoding.DecodeString(encodedSecret)
309309
if err != nil {
310-
Fail("Failed ")
310+
Fail("Failed to decode: " + err.Error())
311311
}
312312
cfg := &cloudConfig{VerifySSL: true}
313313
if rawCfg, err := ini.Load(secret); err != nil {
314-
Fail("Failed to load INI file")
314+
Fail("Failed to load INI file: " + err.Error())
315315
} else if g := rawCfg.Section("Global"); len(g.Keys()) == 0 {
316316
Fail("Global section not found")
317317
} else if err = rawCfg.Section("Global").StrictMapTo(cfg); err != nil {
@@ -448,7 +448,7 @@ func CheckDiskOfferingOfVmInstances(clusterName string, diskOfferingName string)
448448
Byf("Listing machines with %q", clusterName)
449449
listResp, err := client.VirtualMachine.ListVirtualMachines(client.VirtualMachine.NewListVirtualMachinesParams())
450450
if err != nil {
451-
Fail("Failed to list machines")
451+
Fail("Failed to list machines: " + err.Error())
452452
}
453453
for _, vm := range listResp.VirtualMachines {
454454
if strings.Contains(vm.Name, clusterName) {
@@ -462,7 +462,7 @@ func CheckVolumeSizeofVmInstances(clusterName string, volumeSize int64) {
462462
Byf("Listing machines with %q", clusterName)
463463
listResp, err := client.VirtualMachine.ListVirtualMachines(client.VirtualMachine.NewListVirtualMachinesParams())
464464
if err != nil {
465-
Fail("Failed to list machines")
465+
Fail("Failed to list machines: " + err.Error())
466466
}
467467
for _, vm := range listResp.VirtualMachines {
468468
if strings.Contains(vm.Name, clusterName) {

test/e2e/invalid_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func InvalidResourceSpec(ctx context.Context, inputGetter func() CommonSpecInput
6666
})
6767

6868
It("Should fail due to the specified domain is not found [TC4b]", func() {
69-
testInvalidResource(ctx, input, "invalid-domain", "domain not found for domain path "+input.E2EConfig.GetVariable(InvalidDomainName))
69+
testInvalidResource(ctx, input, "invalid-domain", "domain not found for domain path"))
7070
})
7171

7272
It("Should fail due to the specified control plane offering is not found [TC7]", func() {

0 commit comments

Comments
 (0)