55 "testing"
66
77 "github.com/jfrog/jfrog-cli-application/apptrust/commands"
8- "github.com/jfrog/jfrog-cli-application/apptrust/commands/utils"
98 mockversions "github.com/jfrog/jfrog-cli-application/apptrust/service/versions/mocks"
109 "go.uber.org/mock/gomock"
1110
@@ -64,54 +63,36 @@ func TestReleaseAppVersionCommand_Run(t *testing.T) {
6463}
6564
6665func TestReleaseAppVersionCommand_Run_Error (t * testing.T ) {
67- tests := []struct {
68- name string
69- sync bool
70- }{
71- {
72- name : "sync flag true - error" ,
73- sync : true ,
74- },
75- {
76- name : "sync flag false - error" ,
77- sync : false ,
78- },
79- }
80-
81- for _ , tt := range tests {
82- t .Run (tt .name , func (t * testing.T ) {
83- ctrl := gomock .NewController (t )
84- defer ctrl .Finish ()
85-
86- serverDetails := & config.ServerDetails {Url : "https://example.com" }
87- applicationKey := "app-key"
88- version := "1.0.0"
89- requestPayload := model .NewReleaseAppVersionRequest (
90- model .PromotionTypeCopy ,
91- nil , // includedRepos
92- nil , // excludedRepos
93- nil , // artifactProps
94- )
95- expectedError := errors .New ("service error occurred" )
96-
97- mockVersionService := mockversions .NewMockVersionService (ctrl )
98- mockVersionService .EXPECT ().ReleaseAppVersion (gomock .Any (), applicationKey , version , requestPayload , tt .sync ).
99- Return (expectedError ).Times (1 )
66+ ctrl := gomock .NewController (t )
67+ defer ctrl .Finish ()
10068
101- cmd := & releaseAppVersionCommand {
102- versionService : mockVersionService ,
103- serverDetails : serverDetails ,
104- applicationKey : applicationKey ,
105- version : version ,
106- requestPayload : requestPayload ,
107- sync : tt .sync ,
108- }
69+ serverDetails := & config.ServerDetails {Url : "https://example.com" }
70+ applicationKey := "app-key"
71+ version := "1.0.0"
72+ requestPayload := model .NewReleaseAppVersionRequest (
73+ model .PromotionTypeCopy ,
74+ nil , // includedRepos
75+ nil , // excludedRepos
76+ nil , // artifactProps
77+ )
78+ expectedError := errors .New ("service error occurred" )
79+
80+ mockVersionService := mockversions .NewMockVersionService (ctrl )
81+ mockVersionService .EXPECT ().ReleaseAppVersion (gomock .Any (), applicationKey , version , requestPayload , false ).
82+ Return (expectedError ).Times (1 )
10983
110- err := cmd .Run ()
111- assert .Error (t , err )
112- assert .Contains (t , err .Error (), "service error occurred" )
113- })
84+ cmd := & releaseAppVersionCommand {
85+ versionService : mockVersionService ,
86+ serverDetails : serverDetails ,
87+ applicationKey : applicationKey ,
88+ version : version ,
89+ requestPayload : requestPayload ,
90+ sync : false ,
11491 }
92+
93+ err := cmd .Run ()
94+ assert .Error (t , err )
95+ assert .Contains (t , err .Error (), "service error occurred" )
11596}
11697
11798func TestReleaseAppVersionCommand_ServerDetails (t * testing.T ) {
@@ -135,52 +116,3 @@ func TestReleaseAppVersionCommand_CommandName(t *testing.T) {
135116 cmd := & releaseAppVersionCommand {}
136117 assert .Equal (t , commands .VersionRelease , cmd .CommandName ())
137118}
138-
139- func TestReleaseAppVersionCommand_BuildRequestPayload (t * testing.T ) {
140- // Test the key validation logic used in buildRequestPayload
141- t .Run ("validation test" , func (t * testing.T ) {
142- // Let's define the actual allowed values for promotion type
143- allowedValues := []string {model .PromotionTypeCopy , model .PromotionTypeMove }
144-
145- // Case 1: Empty string should return the default value
146- result1 , err1 := utils .ValidateEnumFlag (
147- "test-flag" ,
148- "" ,
149- model .PromotionTypeCopy ,
150- allowedValues )
151-
152- assert .NoError (t , err1 )
153- assert .Equal (t , model .PromotionTypeCopy , result1 )
154-
155- // Case 2: Valid value should be returned as is
156- result2 , err2 := utils .ValidateEnumFlag (
157- "test-flag" ,
158- model .PromotionTypeMove ,
159- model .PromotionTypeCopy ,
160- allowedValues )
161-
162- assert .NoError (t , err2 )
163- assert .Equal (t , model .PromotionTypeMove , result2 )
164-
165- // Case 3: Invalid value should return an error
166- result3 , err3 := utils .ValidateEnumFlag (
167- "test-flag" ,
168- "invalid-type" ,
169- model .PromotionTypeCopy ,
170- allowedValues )
171-
172- assert .Error (t , err3 )
173- assert .Equal (t , "" , result3 ) // On error, the result is empty
174- assert .Contains (t , err3 .Error (), "invalid value" )
175- })
176-
177- t .Run ("property parsing test" , func (t * testing.T ) {
178- // Test property parsing behavior
179- props , err := utils .ParseMapFlag ("key1=value1;key2=value2" )
180- assert .NoError (t , err )
181- assert .Equal (t , map [string ]string {"key1" : "value1" , "key2" : "value2" }, props )
182-
183- _ , err = utils .ParseMapFlag ("invalid-format" )
184- assert .Error (t , err )
185- })
186- }
0 commit comments