5
5
"fmt"
6
6
"github.com/jfrog/gofrog/io"
7
7
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
8
+ "github.com/jfrog/jfrog-cli-core/v2/common/spec"
8
9
configUtils "github.com/jfrog/jfrog-cli-core/v2/utils/config"
9
10
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
10
11
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
@@ -24,6 +25,7 @@ import (
24
25
"os"
25
26
"path"
26
27
"path/filepath"
28
+ "strconv"
27
29
"testing"
28
30
"time"
29
31
)
@@ -160,7 +162,24 @@ func TestLifecycleFullFlow(t *testing.T) {
160
162
// Verify the artifacts were distributed correctly by the provided path mappings.
161
163
assertExpectedArtifacts(t, tests.SearchAllDevRepo, tests.GetExpectedLifecycleDistributedArtifacts())
162
164
*/
165
+ }
166
+
167
+ func TestCreateBundleWithoutSpec (t * testing.T ) {
168
+ cleanCallback := initLifecycleTest (t )
169
+ defer cleanCallback ()
170
+
171
+ lcManager := getLcServiceManager (t )
172
+
173
+ deleteBuilds := uploadBuilds (t )
174
+ defer deleteBuilds ()
175
+
176
+ createRbFromBuildNameAndNumber (t , tests .LifecycleBuilds12 , tests .LcRbName1 , number1 , true , false )
177
+ defer deleteReleaseBundle (t , lcManager , tests .LcRbName1 , number1 )
178
+ assertStatusCompleted (t , lcManager , tests .LcRbName1 , number1 , "" )
163
179
180
+ createRbFromBuildNameAndNumber (t , tests .LifecycleBuilds12 , tests .LcRbName1 , number2 , true , true )
181
+ defer deleteReleaseBundle (t , lcManager , tests .LcRbName1 , number2 )
182
+ assertStatusCompleted (t , lcManager , tests .LcRbName1 , number2 , "" )
164
183
}
165
184
166
185
// Import bundles only work on onPerm platforms
@@ -208,22 +227,67 @@ func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync boo
208
227
createRb (t , specFile , "spec" , rbName , rbVersion , sync , withoutKey )
209
228
}
210
229
230
+ func createRbFromBuildNameAndNumber (t * testing.T , specName , rbName , rbVersion string , sync bool , withoutKey bool ) {
231
+ filePath , err := tests .CreateSpec (specName )
232
+ assert .NoError (t , err )
233
+
234
+ specFile , err := os .Open (filePath )
235
+ if err != nil {
236
+ fmt .Println ("Error opening file:" , err )
237
+ return
238
+ }
239
+ defer specFile .Close ()
240
+ var specData spec.SpecFiles
241
+ decoder := json .NewDecoder (specFile )
242
+ if err := decoder .Decode (& specData ); err != nil {
243
+ fmt .Println ("Error decoding JSON:" , err )
244
+ return
245
+ }
246
+
247
+ buildInfo := specData .Files [0 ].Build
248
+ buildName , buildNumber , err := tests .ExtractBuildInfo (buildInfo )
249
+ assert .NoError (t , err )
250
+
251
+ options := []string {
252
+ getOption (cliutils .BuildName , buildName ),
253
+ getOption (cliutils .BuildNumber , buildNumber ),
254
+ }
255
+
256
+ if ! withoutKey {
257
+ options = append (options , getOption (cliutils .SigningKey , gpgKeyPairName ))
258
+ }
259
+
260
+ if sync {
261
+ options = append (options , getOption (cliutils .Sync , strconv .FormatBool (sync )))
262
+ }
263
+
264
+ createRbWithOptions (t , rbName , rbVersion , options ... )
265
+ }
266
+
211
267
func createRb (t * testing.T , specFilePath , sourceOption , rbName , rbVersion string , sync bool , withoutKey bool ) {
212
- argsAndOptions := []string {
213
- "rbc" ,
214
- rbName ,
215
- rbVersion ,
268
+ options := []string {
216
269
getOption (sourceOption , specFilePath ),
217
270
}
218
271
219
272
if ! withoutKey {
220
- argsAndOptions = append (argsAndOptions , getOption (cliutils .SigningKey , gpgKeyPairName ))
273
+ options = append (options , getOption (cliutils .SigningKey , gpgKeyPairName ))
221
274
}
222
275
223
- // Add the --sync option only if requested, to test the default value.
224
276
if sync {
225
- argsAndOptions = append (argsAndOptions , getOption (cliutils .Sync , "true" ))
277
+ options = append (options , getOption (cliutils .Sync , "true" ))
278
+ }
279
+
280
+ createRbWithOptions (t , rbName , rbVersion , options ... )
281
+ }
282
+
283
+ func createRbWithOptions (t * testing.T , rbName , rbVersion string , options ... string ) {
284
+ argsAndOptions := []string {
285
+ "rbc" ,
286
+ rbName ,
287
+ rbVersion ,
226
288
}
289
+
290
+ argsAndOptions = append (argsAndOptions , options ... )
227
291
assert .NoError (t , lcCli .Exec (argsAndOptions ... ))
228
292
}
229
293
0 commit comments