Skip to content

Commit 6d86597

Browse files
APP-4230 - Add E2E test for --skip-unassigned flag
Two subtests covering auto-promotion behavior: - Success: source repo mapped to DEV -> version promoted to DEV - Mismatch: source repo mapped only to PROD -> version stays unassigned with message explaining the repo_mismatch Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 998e7c7 commit 6d86597

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

e2e/utils/artifactory_utils.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,30 @@ func deleteBuild() {
210210
log.Error("Failed to delete build-info", err)
211211
}
212212
}
213+
214+
var prodOnlyRepoKey string
215+
216+
func GetTestArtifactInProdOnlyRepo(t *testing.T) string {
217+
if prodOnlyRepoKey != "" {
218+
return prodOnlyRepoKey + "/mismatch-artifact.txt"
219+
}
220+
servicesManager := getArtifactoryServicesManager(t)
221+
prodOnlyRepoKey = GetTestProjectKey(t) + "-prod-only-local"
222+
localRepoConfig := services.NewGenericLocalRepositoryParams()
223+
localRepoConfig.ProjectKey = GetTestProjectKey(t)
224+
localRepoConfig.Key = prodOnlyRepoKey
225+
localRepoConfig.Environments = []string{"PROD"}
226+
err := servicesManager.CreateLocalRepository().Generic(localRepoConfig)
227+
require.NoError(t, err)
228+
return uploadSimpleFileToArtifactory(t, prodOnlyRepoKey, "mismatch-artifact.txt")
229+
}
230+
231+
func deleteProdOnlyRepo() {
232+
if prodOnlyRepoKey == "" || artifactoryServicesManager == nil {
233+
return
234+
}
235+
err := artifactoryServicesManager.DeleteRepository(prodOnlyRepoKey)
236+
if err != nil {
237+
log.Error("Failed to delete prod-only repo", err)
238+
}
239+
}

e2e/utils/project_utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func DeleteTestProject() {
3333
deleteBuild()
3434
deleteNpmRepo()
3535
deleteGenericRepo()
36+
deleteProdOnlyRepo()
3637
accessManager, err := utils.CreateAccessServiceManager(serverDetails, false)
3738
if err != nil {
3839
log.Error("Failed to create Access service manager", err)

e2e/version_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,69 @@ func TestCreateVersion_Draft(t *testing.T) {
196196
assert.Equal(t, utils.StatusDraft, versionContent.Status)
197197
}
198198

199+
func TestCreateVersion_SkipUnassigned(t *testing.T) {
200+
appKey := utils.GenerateUniqueKey("app-version-skip-unassigned")
201+
utils.CreateBasicApplication(t, appKey)
202+
defer utils.DeleteApplication(t, appKey)
203+
204+
testPackage := utils.GetTestPackage(t)
205+
206+
t.Run("passes eligibility when source repo is mapped to first stage", func(t *testing.T) {
207+
version := utils.GenerateUniqueKey("skip-ua-ok")
208+
209+
packageFlag := fmt.Sprintf("--source-type-packages=type=%s, name=%s, version=%s, repo-key=%s",
210+
testPackage.PackageType, testPackage.PackageName, testPackage.PackageVersion, testPackage.RepoKey)
211+
output := utils.AppTrustCli.RunCliCmdWithOutput(t, "version-create", appKey, version, packageFlag, "--skip-unassigned")
212+
defer utils.DeleteApplicationVersion(t, appKey, version)
213+
214+
require.NotEmpty(t, output)
215+
216+
var response struct {
217+
ApplicationKey string `json:"application_key"`
218+
Version string `json:"version"`
219+
Status string `json:"status"`
220+
CurrentStage string `json:"current_stage"`
221+
Message string `json:"message"`
222+
}
223+
err := json.Unmarshal([]byte(output), &response)
224+
require.NoError(t, err, "failed to parse CLI output as JSON: %s", output)
225+
assert.Equal(t, appKey, response.ApplicationKey)
226+
assert.Equal(t, version, response.Version)
227+
228+
versionContent, statusCode, err := utils.GetApplicationVersion(appKey, version)
229+
require.NoError(t, err)
230+
assert.Equal(t, http.StatusOK, statusCode)
231+
require.NotNil(t, versionContent)
232+
assert.Equal(t, utils.StatusCompleted, versionContent.Status)
233+
assert.Equal(t, "DEV", versionContent.CurrentStage, "Version should be auto-promoted to DEV stage")
234+
})
235+
236+
t.Run("stays unassigned with message when artifacts mismatch first stage", func(t *testing.T) {
237+
version := utils.GenerateUniqueKey("skip-ua-fail")
238+
239+
artifactPath := utils.GetTestArtifactInProdOnlyRepo(t)
240+
artifactFlag := fmt.Sprintf("--source-type-artifacts=path=%s", artifactPath)
241+
output := utils.AppTrustCli.RunCliCmdWithOutput(t, "version-create", appKey, version, artifactFlag, "--skip-unassigned")
242+
defer utils.DeleteApplicationVersion(t, appKey, version)
243+
244+
require.NotEmpty(t, output)
245+
246+
var response struct {
247+
ApplicationKey string `json:"application_key"`
248+
Version string `json:"version"`
249+
Status string `json:"status"`
250+
CurrentStage string `json:"current_stage"`
251+
Message string `json:"message"`
252+
}
253+
err := json.Unmarshal([]byte(output), &response)
254+
require.NoError(t, err, "failed to parse CLI output as JSON: %s", output)
255+
assert.Equal(t, appKey, response.ApplicationKey)
256+
assert.Equal(t, version, response.Version)
257+
assert.Empty(t, response.CurrentStage, "Version should NOT be promoted when artifacts are in PROD-only repo")
258+
assert.NotEmpty(t, response.Message, "A message should explain why auto-promotion did not occur")
259+
})
260+
}
261+
199262
func TestCreateVersion_Async(t *testing.T) {
200263
appKey := utils.GenerateUniqueKey("app-version-create-async")
201264
utils.CreateBasicApplication(t, appKey)

0 commit comments

Comments
 (0)