Skip to content

Commit 89bac06

Browse files
committed
fix(git): remove Id from inputModel
1 parent c153566 commit 89bac06

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

internal/cmd/git/instance/create/create.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const (
2727

2828
type inputModel struct {
2929
*globalflags.GlobalFlagModel
30-
Id *string
3130
Name string
3231
Flavor string
3332
Acl []string
@@ -79,20 +78,19 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7978
if err != nil {
8079
return fmt.Errorf("create stackit git instance: %w", err)
8180
}
82-
model.Id = result.Id
8381

8482
// Wait for async operation, if async mode not enabled
8583
if !model.Async {
8684
s := spinner.New(params.Printer)
8785
s.Start("Creating stackit git instance")
88-
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *model.Id).WaitWithContext(ctx)
86+
_, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *result.Id).WaitWithContext(ctx)
8987
if err != nil {
9088
return fmt.Errorf("wait for stackit git Instance creation: %w", err)
9189
}
9290
s.Stop()
9391
}
9492

95-
return outputResult(params.Printer, model.OutputFormat, model.Async, model.Name, *model.Id, result)
93+
return outputResult(params.Printer, model.OutputFormat, model.Async, model.Name, result)
9694
},
9795
}
9896

@@ -142,17 +140,20 @@ func createPayload(model *inputModel) git.CreateInstancePayload {
142140
}
143141
}
144142

145-
func outputResult(p *print.Printer, outputFormat string, async bool, instanceName, modelId string, resp *git.Instance) error {
143+
func outputResult(p *print.Printer, outputFormat string, async bool, instanceName string, resp *git.Instance) error {
146144
if resp == nil {
147145
return fmt.Errorf("API resp is nil")
148146
}
147+
if resp.Id == nil {
148+
return fmt.Errorf("API resp is missing instance id")
149+
}
149150

150151
return p.OutputResult(outputFormat, resp, func() error {
151152
operationState := "Created"
152153
if async {
153154
operationState = "Triggered creation of"
154155
}
155-
p.Outputf("%s instance %q with id %s\n", operationState, instanceName, modelId)
156+
p.Outputf("%s instance %q with id %s\n", operationState, instanceName, *resp.Id)
156157
return nil
157158
})
158159
}

internal/cmd/git/instance/create/create_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func TestOutputResult(t *testing.T) {
178178
outputFormat string
179179
async bool
180180
instanceName string
181-
modelId string
182181
resp *git.Instance
183182
}
184183
tests := []struct {
@@ -192,7 +191,6 @@ func TestOutputResult(t *testing.T) {
192191
outputFormat: "",
193192
async: false,
194193
instanceName: "",
195-
modelId: "",
196194
resp: nil,
197195
},
198196
wantErr: true,
@@ -203,8 +201,7 @@ func TestOutputResult(t *testing.T) {
203201
outputFormat: "",
204202
async: false,
205203
instanceName: "",
206-
modelId: "",
207-
resp: &git.Instance{},
204+
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
208205
},
209206
wantErr: false,
210207
},
@@ -214,8 +211,7 @@ func TestOutputResult(t *testing.T) {
214211
outputFormat: print.JSONOutputFormat,
215212
async: true,
216213
instanceName: testName,
217-
modelId: uuid.NewString(),
218-
resp: &git.Instance{},
214+
resp: &git.Instance{Id: utils.Ptr(uuid.NewString())},
219215
},
220216
wantErr: false,
221217
},
@@ -224,7 +220,7 @@ func TestOutputResult(t *testing.T) {
224220
p.Cmd = NewCmd(&types.CmdParams{Printer: p})
225221
for _, tt := range tests {
226222
t.Run(tt.name, func(t *testing.T) {
227-
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.instanceName, tt.args.modelId, tt.args.resp); (err != nil) != tt.wantErr {
223+
if err := outputResult(p, tt.args.outputFormat, tt.args.async, tt.args.instanceName, tt.args.resp); (err != nil) != tt.wantErr {
228224
t.Errorf("outputResult() error = %v, wantErr %v", err, tt.wantErr)
229225
}
230226
})

0 commit comments

Comments
 (0)