Skip to content

Commit 99259ae

Browse files
committed
remove app key from struct
1 parent 2cbe025 commit 99259ae

File tree

5 files changed

+21
-140
lines changed

5 files changed

+21
-140
lines changed

apptrust/commands/version/update_app_version_cmd.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (uv *updateAppVersionCommand) Run() error {
3535
return err
3636
}
3737

38-
err = uv.versionService.UpdateAppVersion(ctx, uv.requestPayload)
38+
err = uv.versionService.UpdateAppVersion(ctx, uv.applicationKey, uv.version, uv.requestPayload)
3939
if err != nil {
4040
log.Error("Failed to update application version:", err)
4141
return err
@@ -85,10 +85,7 @@ func (uv *updateAppVersionCommand) parseFlagsAndSetFields(ctx *components.Contex
8585
}
8686

8787
func (uv *updateAppVersionCommand) buildRequestPayload(ctx *components.Context) (*model.UpdateAppVersionRequest, error) {
88-
request := &model.UpdateAppVersionRequest{
89-
ApplicationKey: uv.applicationKey,
90-
Version: uv.version,
91-
}
88+
request := &model.UpdateAppVersionRequest{}
9289

9390
if ctx.IsFlagSet(commands.TagFlag) {
9491
request.Tag = ctx.GetStringFlagValue(commands.TagFlag)

apptrust/commands/version/update_app_version_cmd_test.go

Lines changed: 9 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"testing"
66

7-
"github.com/jfrog/jfrog-cli-application/apptrust/commands/utils"
87
mockversions "github.com/jfrog/jfrog-cli-application/apptrust/service/versions/mocks"
98
"go.uber.org/mock/gomock"
109

@@ -25,9 +24,7 @@ func TestUpdateAppVersionCommand_Run(t *testing.T) {
2524
{
2625
name: "success",
2726
request: &model.UpdateAppVersionRequest{
28-
ApplicationKey: "app-key",
29-
Version: "1.0.0",
30-
Tag: "release/1.2.3",
27+
Tag: "release/1.2.3",
3128
Properties: map[string][]string{
3229
"status": {"rc", "validated"},
3330
},
@@ -36,9 +33,7 @@ func TestUpdateAppVersionCommand_Run(t *testing.T) {
3633
{
3734
name: "context error",
3835
request: &model.UpdateAppVersionRequest{
39-
ApplicationKey: "app-key",
40-
Version: "1.0.0",
41-
Tag: "test-tag",
36+
Tag: "test-tag",
4237
},
4338
shouldError: true,
4439
errorMessage: "context error",
@@ -52,10 +47,10 @@ func TestUpdateAppVersionCommand_Run(t *testing.T) {
5247

5348
mockVersionService := mockversions.NewMockVersionService(ctrl)
5449
if tt.shouldError {
55-
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any()).
50+
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
5651
Return(errors.New(tt.errorMessage)).Times(1)
5752
} else {
58-
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any()).
53+
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
5954
Return(nil).Times(1)
6055
}
6156

@@ -93,9 +88,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
9388
ctx.AddStringFlag(commands.TagFlag, "release/1.2.3")
9489
},
9590
expectsPayload: &model.UpdateAppVersionRequest{
96-
ApplicationKey: "app-key",
97-
Version: "1.0.0",
98-
Tag: "release/1.2.3",
91+
Tag: "release/1.2.3",
9992
},
10093
},
10194
{
@@ -105,8 +98,6 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
10598
ctx.AddStringFlag(commands.PropertiesFlag, "status=rc")
10699
},
107100
expectsPayload: &model.UpdateAppVersionRequest{
108-
ApplicationKey: "app-key",
109-
Version: "1.0.0",
110101
Properties: map[string][]string{
111102
"status": {"rc"},
112103
},
@@ -119,8 +110,6 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
119110
ctx.AddStringFlag(commands.PropertiesFlag, "status=rc,validated")
120111
},
121112
expectsPayload: &model.UpdateAppVersionRequest{
122-
ApplicationKey: "app-key",
123-
Version: "1.0.0",
124113
Properties: map[string][]string{
125114
"status": {"rc", "validated"},
126115
},
@@ -133,8 +122,6 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
133122
ctx.AddStringFlag(commands.PropertiesFlag, "status=rc,validated;deployed_to=staging-A,staging-B")
134123
},
135124
expectsPayload: &model.UpdateAppVersionRequest{
136-
ApplicationKey: "app-key",
137-
Version: "1.0.0",
138125
Properties: map[string][]string{
139126
"status": {"rc", "validated"},
140127
"deployed_to": {"staging-A", "staging-B"},
@@ -148,8 +135,6 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
148135
ctx.AddStringFlag(commands.DeletePropertyFlag, "legacy_param;toBeDeleted")
149136
},
150137
expectsPayload: &model.UpdateAppVersionRequest{
151-
ApplicationKey: "app-key",
152-
Version: "1.0.0",
153138
DeleteProperties: []string{"legacy_param", "toBeDeleted"},
154139
},
155140
},
@@ -160,8 +145,6 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
160145
ctx.AddStringFlag(commands.PropertiesFlag, "old_feature_flag=")
161146
},
162147
expectsPayload: &model.UpdateAppVersionRequest{
163-
ApplicationKey: "app-key",
164-
Version: "1.0.0",
165148
Properties: map[string][]string{
166149
"old_feature_flag": {},
167150
},
@@ -176,9 +159,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
176159
ctx.AddStringFlag(commands.DeletePropertyFlag, "old_param")
177160
},
178161
expectsPayload: &model.UpdateAppVersionRequest{
179-
ApplicationKey: "app-key",
180-
Version: "1.0.0",
181-
Tag: "release/1.2.3",
162+
Tag: "release/1.2.3",
182163
Properties: map[string][]string{
183164
"status": {"rc", "validated"},
184165
},
@@ -192,9 +173,7 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
192173
ctx.AddStringFlag(commands.TagFlag, "")
193174
},
194175
expectsPayload: &model.UpdateAppVersionRequest{
195-
ApplicationKey: "app-key",
196-
Version: "1.0.0",
197-
Tag: "",
176+
Tag: "",
198177
},
199178
},
200179
{
@@ -229,8 +208,8 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
229208
var actualPayload *model.UpdateAppVersionRequest
230209
mockVersionService := mockversions.NewMockVersionService(ctrl)
231210
if !tt.expectsError {
232-
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any()).
233-
DoAndReturn(func(_ interface{}, req *model.UpdateAppVersionRequest) error {
211+
mockVersionService.EXPECT().UpdateAppVersion(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
212+
DoAndReturn(func(_ interface{}, _ string, _ string, req *model.UpdateAppVersionRequest) error {
234213
actualPayload = req
235214
return nil
236215
}).Times(1)
@@ -253,82 +232,3 @@ func TestUpdateAppVersionCommand_FlagsSuite(t *testing.T) {
253232
})
254233
}
255234
}
256-
257-
func TestParseProperties(t *testing.T) {
258-
tests := []struct {
259-
name string
260-
input string
261-
expected map[string][]string
262-
expectErr bool
263-
}{
264-
{
265-
name: "empty string",
266-
input: "",
267-
expected: nil,
268-
},
269-
{
270-
name: "single property with single value",
271-
input: "status=rc",
272-
expected: map[string][]string{
273-
"status": {"rc"},
274-
},
275-
},
276-
{
277-
name: "single property with multiple values",
278-
input: "status=rc,validated",
279-
expected: map[string][]string{
280-
"status": {"rc", "validated"},
281-
},
282-
},
283-
{
284-
name: "multiple properties",
285-
input: "status=rc,validated;deployed_to=staging-A,staging-B",
286-
expected: map[string][]string{
287-
"status": {"rc", "validated"},
288-
"deployed_to": {"staging-A", "staging-B"},
289-
},
290-
},
291-
{
292-
name: "empty values (clears values)",
293-
input: "old_feature_flag=",
294-
expected: map[string][]string{
295-
"old_feature_flag": {},
296-
},
297-
},
298-
{
299-
name: "with spaces",
300-
input: " status = rc , validated ; deployed_to = staging-A , staging-B ",
301-
expected: map[string][]string{
302-
"status": {"rc", "validated"},
303-
"deployed_to": {"staging-A", "staging-B"},
304-
},
305-
},
306-
{
307-
name: "invalid format - missing =",
308-
input: "invalid-format",
309-
expectErr: true,
310-
},
311-
{
312-
name: "empty key",
313-
input: "=value",
314-
expectErr: true,
315-
},
316-
{
317-
name: "empty key with spaces",
318-
input: " =value",
319-
expectErr: true,
320-
},
321-
}
322-
323-
for _, tt := range tests {
324-
t.Run(tt.name, func(t *testing.T) {
325-
result, err := utils.ParseListPropertiesFlag(tt.input)
326-
if tt.expectErr {
327-
assert.Error(t, err)
328-
} else {
329-
assert.NoError(t, err)
330-
assert.Equal(t, tt.expected, result)
331-
}
332-
})
333-
}
334-
}

apptrust/model/update_app_version_request.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package model
22

33
type UpdateAppVersionRequest struct {
4-
ApplicationKey string `json:"application_key"`
5-
Version string `json:"version"`
64
Tag string `json:"tag,omitempty"`
75
Properties map[string][]string `json:"properties,omitempty"`
86
DeleteProperties []string `json:"delete_properties,omitempty"`

apptrust/service/versions/version_service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type VersionService interface {
1717
PromoteAppVersion(ctx service.Context, applicationKey string, version string, payload *model.PromoteAppVersionRequest, sync bool) error
1818
ReleaseAppVersion(ctx service.Context, applicationKey string, version string, request *model.ReleaseAppVersionRequest, sync bool) error
1919
DeleteAppVersion(ctx service.Context, applicationKey string, version string) error
20-
UpdateAppVersion(ctx service.Context, request *model.UpdateAppVersionRequest) error
20+
UpdateAppVersion(ctx service.Context, applicationKey string, version string, request *model.UpdateAppVersionRequest) error
2121
}
2222

2323
type versionService struct{}
@@ -86,8 +86,8 @@ func (vs *versionService) DeleteAppVersion(ctx service.Context, applicationKey,
8686
return nil
8787
}
8888

89-
func (vs *versionService) UpdateAppVersion(ctx service.Context, request *model.UpdateAppVersionRequest) error {
90-
endpoint := fmt.Sprintf("/v1/applications/%s/versions/%s", request.ApplicationKey, request.Version)
89+
func (vs *versionService) UpdateAppVersion(ctx service.Context, applicationKey string, version string, request *model.UpdateAppVersionRequest) error {
90+
endpoint := fmt.Sprintf("/v1/applications/%s/versions/%s", applicationKey, version)
9191
response, responseBody, err := ctx.GetHttpClient().Patch(endpoint, request)
9292
if err != nil {
9393
return err

apptrust/service/versions/version_service_test.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ func TestUpdateAppVersion(t *testing.T) {
312312
{
313313
name: "success - tag only",
314314
request: &model.UpdateAppVersionRequest{
315-
ApplicationKey: "test-app",
316-
Version: "1.0.0",
317-
Tag: "release/1.2.3",
315+
Tag: "release/1.2.3",
318316
},
319317
mockResponse: &http.Response{StatusCode: http.StatusAccepted},
320318
mockResponseBody: "{}",
@@ -325,8 +323,6 @@ func TestUpdateAppVersion(t *testing.T) {
325323
{
326324
name: "success - properties only",
327325
request: &model.UpdateAppVersionRequest{
328-
ApplicationKey: "test-app",
329-
Version: "1.0.0",
330326
Properties: map[string][]string{
331327
"status": {"rc", "validated"},
332328
},
@@ -340,8 +336,6 @@ func TestUpdateAppVersion(t *testing.T) {
340336
{
341337
name: "success - delete properties only",
342338
request: &model.UpdateAppVersionRequest{
343-
ApplicationKey: "test-app",
344-
Version: "1.0.0",
345339
DeleteProperties: []string{"legacy_param", "toBeDeleted"},
346340
},
347341
mockResponse: &http.Response{StatusCode: http.StatusAccepted},
@@ -353,9 +347,7 @@ func TestUpdateAppVersion(t *testing.T) {
353347
{
354348
name: "success - combined update",
355349
request: &model.UpdateAppVersionRequest{
356-
ApplicationKey: "test-app",
357-
Version: "1.0.0",
358-
Tag: "release/1.2.3",
350+
Tag: "release/1.2.3",
359351
Properties: map[string][]string{
360352
"status": {"rc", "validated"},
361353
},
@@ -370,9 +362,7 @@ func TestUpdateAppVersion(t *testing.T) {
370362
{
371363
name: "failure - 400",
372364
request: &model.UpdateAppVersionRequest{
373-
ApplicationKey: "test-app",
374-
Version: "1.0.0",
375-
Tag: "invalid-tag",
365+
Tag: "invalid-tag",
376366
},
377367
mockResponse: &http.Response{StatusCode: http.StatusBadRequest},
378368
mockResponseBody: "bad request",
@@ -383,9 +373,7 @@ func TestUpdateAppVersion(t *testing.T) {
383373
{
384374
name: "failure - 404",
385375
request: &model.UpdateAppVersionRequest{
386-
ApplicationKey: "test-app",
387-
Version: "1.0.0",
388-
Tag: "release/1.2.3",
376+
Tag: "release/1.2.3",
389377
},
390378
mockResponse: &http.Response{StatusCode: http.StatusNotFound},
391379
mockResponseBody: "not found",
@@ -396,9 +384,7 @@ func TestUpdateAppVersion(t *testing.T) {
396384
{
397385
name: "http client error",
398386
request: &model.UpdateAppVersionRequest{
399-
ApplicationKey: "test-app",
400-
Version: "1.0.0",
401-
Tag: "release/1.2.3",
387+
Tag: "release/1.2.3",
402388
},
403389
mockResponse: nil,
404390
mockResponseBody: "",
@@ -411,13 +397,13 @@ func TestUpdateAppVersion(t *testing.T) {
411397
for _, tt := range tests {
412398
t.Run(tt.name, func(t *testing.T) {
413399
mockHttpClient := mockhttp.NewMockApptrustHttpClient(ctrl)
414-
mockHttpClient.EXPECT().Patch("/v1/applications/"+tt.request.ApplicationKey+"/versions/"+tt.request.Version, tt.request).
400+
mockHttpClient.EXPECT().Patch("/v1/applications/test-app/versions/1.0.0", tt.request).
415401
Return(tt.mockResponse, []byte(tt.mockResponseBody), tt.mockError).Times(1)
416402

417403
mockCtx := mockservice.NewMockContext(ctrl)
418404
mockCtx.EXPECT().GetHttpClient().Return(mockHttpClient).AnyTimes()
419405

420-
err := service.UpdateAppVersion(mockCtx, tt.request)
406+
err := service.UpdateAppVersion(mockCtx, "test-app", "1.0.0", tt.request)
421407
if tt.expectError {
422408
assert.Error(t, err)
423409
if tt.errorMsg != "" {

0 commit comments

Comments
 (0)