Skip to content

Commit 4b7f6b5

Browse files
jonglerbhanurp
andauthored
Added e2e tests for new release bundle finalize command (#3340)
* Added e2e tests for new release bundle finalize command * Added e2e test for finalize release bundle command * Update lifecycle_test.go Co-authored-by: Bhanu Reddy <[email protected]> --------- Co-authored-by: Bhanu Reddy <[email protected]>
1 parent e5a9738 commit 4b7f6b5

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

lifecycle_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,33 @@ func TestReleaseBundleUpdateWithFlags(t *testing.T) {
569569
assertRbArtifacts(t, lcManager, tests.LcRbName2, number2, tests.GetExpectedLifecycleUpdateBuild2Artifacts())
570570
}
571571

572+
func TestReleaseBundleFinalize(t *testing.T) {
573+
cleanCallback := initLifecycleTest(t, draftBundleArtifactoryMinVersion)
574+
defer cleanCallback()
575+
lcManager := getLcServiceManager(t)
576+
577+
deleteBuilds := uploadBuilds(t)
578+
defer deleteBuilds()
579+
580+
// Create a draft bundle from build 1
581+
createRbWithFlags(t, "", "", tests.LcBuildName1, number1, tests.LcRbName1, number1, "default", true, true, true)
582+
defer deleteReleaseBundle(t, lcManager, tests.LcRbName1, number1)
583+
assertStatusDraft(t, lcManager, tests.LcRbName1, number1)
584+
assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, tests.GetExpectedLifecycleBuild1Artifacts())
585+
586+
// Finalize the draft bundle (the command prints "Release Bundle successfully finalized" on success)
587+
finalizeRbWithFlags(t, tests.LcRbName1, number1, "default", gpgKeyPairName, true)
588+
589+
// Verify the bundle's current status is COMPLETED after finalize
590+
// Note: We use assertCurrentBundleStatusCompleted (not assertStatusCompleted) because
591+
// the creation status endpoint returns the audit status of the creation operation (DRAFT),
592+
// while we want to verify the bundle's actual current state (COMPLETED after finalize).
593+
assertCurrentBundleStatusCompleted(t, lcManager, tests.LcRbName1, number1)
594+
595+
// Verify the bundle still exists and contains the same artifacts after finalize
596+
assertRbArtifacts(t, lcManager, tests.LcRbName1, number1, tests.GetExpectedLifecycleBuild1Artifacts())
597+
}
598+
572599
/*func deleteExportedReleaseBundle(t *testing.T, rbName string) {
573600
assert.NoError(t, os.RemoveAll(rbName))
574601
}*/
@@ -719,6 +746,22 @@ func updateRbWithFlags(t *testing.T, specFilePath, rbName, rbVersion, project, s
719746
assert.NoError(t, lcCli.Exec(argsAndOptions...))
720747
}
721748

749+
func finalizeRbWithFlags(t *testing.T, rbName, rbVersion, project, signingKey string, sync bool) {
750+
argsAndOptions := []string{
751+
"rbf",
752+
rbName,
753+
rbVersion,
754+
}
755+
if signingKey != "" {
756+
argsAndOptions = append(argsAndOptions, getOption(cliutils.SigningKey, signingKey))
757+
}
758+
if project != "" {
759+
argsAndOptions = append(argsAndOptions, getOption(cliutils.Project, project))
760+
}
761+
argsAndOptions = append(argsAndOptions, getOption(cliutils.Sync, strconv.FormatBool(sync)))
762+
assert.NoError(t, lcCli.Exec(argsAndOptions...))
763+
}
764+
722765
/*func exportRb(t *testing.T, rbName, rbVersion, targetPath string) {
723766
lcCli.RunCliCmdWithOutput(t, "rbe", rbName, rbVersion, targetPath+"/")
724767
exists, err := fileutils.IsDirExists(path.Join(targetPath, rbName), false)
@@ -799,6 +842,35 @@ func assertStatusCompletedWithProject(t *testing.T, lcManager *lifecycle.Lifecyc
799842
assert.Equal(t, services.Completed, resp.Status)
800843
}
801844

845+
// assertCurrentBundleStatusCompleted asserts the bundle's current record status is COMPLETED.
846+
// This differs from assertStatusCompleted which checks the creation operation's audit status.
847+
// Use this after finalize to verify the bundle is now in COMPLETED state.
848+
func assertCurrentBundleStatusCompleted(t *testing.T, lcManager *lifecycle.LifecycleServicesManager, rbName, rbVersion string) {
849+
status, err := getCurrentBundleRecordStatus(lcManager, rbName, rbVersion)
850+
if !assert.NoError(t, err) {
851+
return
852+
}
853+
assert.Equal(t, "COMPLETED", status, "Expected bundle current status to be COMPLETED after finalize")
854+
}
855+
856+
// getCurrentBundleRecordStatus fetches the current bundle status from the bundle record.
857+
// This returns the actual current state of the bundle, not the creation operation status.
858+
func getCurrentBundleRecordStatus(lcManager *lifecycle.LifecycleServicesManager, rbName, rbVersion string) (string, error) {
859+
params := services.GetSearchOptionalQueryParams{
860+
Limit: 100,
861+
}
862+
resp, err := lcManager.ReleaseBundlesSearchVersions(rbName, params)
863+
if err != nil {
864+
return "", err
865+
}
866+
for _, bundle := range resp.ReleaseBundles {
867+
if bundle.ReleaseBundleVersion == rbVersion {
868+
return bundle.Status, nil
869+
}
870+
}
871+
return "", fmt.Errorf("bundle version %s/%s not found", rbName, rbVersion)
872+
}
873+
802874
func getLcServiceManager(t *testing.T) *lifecycle.LifecycleServicesManager {
803875
lcManager, err := utils.CreateLifecycleServiceManager(lcDetails, false)
804876
assert.NoError(t, err)

0 commit comments

Comments
 (0)