Skip to content

Commit 0c7110c

Browse files
committed
Add IT
1 parent 4c0a1ac commit 0c7110c

File tree

1 file changed

+71
-7
lines changed

1 file changed

+71
-7
lines changed

lifecycle_test.go

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"github.com/jfrog/gofrog/io"
77
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
8+
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
89
configUtils "github.com/jfrog/jfrog-cli-core/v2/utils/config"
910
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1011
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
@@ -24,6 +25,7 @@ import (
2425
"os"
2526
"path"
2627
"path/filepath"
28+
"strconv"
2729
"testing"
2830
"time"
2931
)
@@ -160,7 +162,24 @@ func TestLifecycleFullFlow(t *testing.T) {
160162
// Verify the artifacts were distributed correctly by the provided path mappings.
161163
assertExpectedArtifacts(t, tests.SearchAllDevRepo, tests.GetExpectedLifecycleDistributedArtifacts())
162164
*/
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, "")
163179

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, "")
164183
}
165184

166185
// Import bundles only work on onPerm platforms
@@ -208,22 +227,67 @@ func createRbFromSpec(t *testing.T, specName, rbName, rbVersion string, sync boo
208227
createRb(t, specFile, "spec", rbName, rbVersion, sync, withoutKey)
209228
}
210229

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+
211267
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{
216269
getOption(sourceOption, specFilePath),
217270
}
218271

219272
if !withoutKey {
220-
argsAndOptions = append(argsAndOptions, getOption(cliutils.SigningKey, gpgKeyPairName))
273+
options = append(options, getOption(cliutils.SigningKey, gpgKeyPairName))
221274
}
222275

223-
// Add the --sync option only if requested, to test the default value.
224276
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,
226288
}
289+
290+
argsAndOptions = append(argsAndOptions, options...)
227291
assert.NoError(t, lcCli.Exec(argsAndOptions...))
228292
}
229293

0 commit comments

Comments
 (0)