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- }
0 commit comments