Skip to content

Commit 6a14a9a

Browse files
committed
fix backup create test
1 parent fc41358 commit 6a14a9a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

internal/cmd/volume/backup/create/create.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ func NewCmd(params *params.CmdParams) *cobra.Command {
118118
s.Stop()
119119
}
120120

121-
if model.Async {
122-
params.Printer.Info("Triggered backup of %q in %q. Backup ID: %s\n", sourceLabel, projectLabel, *resp.Id)
123-
} else {
124-
params.Printer.Info("Created backup of %q in %q. Backup ID: %s\n", sourceLabel, projectLabel, *resp.Id)
125-
}
126-
return nil
121+
return outputResult(params.Printer, model.OutputFormat, model.Async, sourceLabel, projectLabel, resp)
127122
},
128123
}
129124

@@ -203,8 +198,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
203198
Type: &model.SourceType,
204199
}
205200

206-
req = req.CreateBackupPayload(*createPayload)
207-
return req
201+
return req.CreateBackupPayload(*createPayload)
208202
}
209203

210204
func outputResult(p *print.Printer, outputFormat string, async bool, sourceLabel, projectLabel string, resp *iaas.Backup) error {

internal/cmd/volume/backup/create/create_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import (
1717
type testCtxKey struct{}
1818

1919
var (
20-
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
testClient = &iaas.APIClient{}
22-
testProjectId = uuid.NewString()
23-
testSourceId = uuid.NewString()
24-
testName = "my-backup"
25-
testLabels = map[string]string{"key1": "value1"}
20+
testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21+
testClient = &iaas.APIClient{}
22+
testProjectId = uuid.NewString()
23+
testSourceId = uuid.NewString()
24+
testName = "my-backup"
25+
testLabels = map[string]string{"key1": "value1"}
26+
testSourceType = "volume"
2627
)
2728

2829
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
@@ -58,6 +59,18 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
5859

5960
func fixtureRequest(mods ...func(request *iaas.ApiCreateBackupRequest)) iaas.ApiCreateBackupRequest {
6061
request := testClient.CreateBackup(testCtx, testProjectId)
62+
63+
createPayload := iaas.NewCreateBackupPayloadWithDefaults()
64+
createPayload.Name = &testName
65+
createPayload.Labels = &map[string]interface{}{
66+
"key1": "value1",
67+
}
68+
createPayload.Source = &iaas.BackupSource{
69+
Id: &testSourceId,
70+
Type: &testSourceType,
71+
}
72+
73+
request = request.CreateBackupPayload(*createPayload)
6174
for _, mod := range mods {
6275
mod(&request)
6376
}

0 commit comments

Comments
 (0)