Skip to content

Commit e095614

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 e095614

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

apptrust/commands/version/create_app_version_cmd_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ func TestCreateAppVersionCommand_FlagsSuite(t *testing.T) {
139139
ctx.Arguments = []string{"app-key", "1.0.0"}
140140
ctx.AddStringFlag(commands.TagFlag, "release-tag")
141141
ctx.AddBoolFlag(commands.DraftFlag, true)
142-
ctx.AddBoolFlag(commands.SkipUnassignedFlag, true)
143142
ctx.AddStringFlag(commands.SourceTypeBuildsFlag, "name=build1,id=1.0.0,include-deps=true,repo-key=build-info-repo,started=2024-01-15T10:30:00Z;name=build2,id=2.0.0,include-deps=false")
144143
ctx.AddStringFlag(commands.SourceTypeReleaseBundlesFlag, "name=rb1,version=1.0.0;name=rb2,version=2.0.0")
145144
ctx.AddStringFlag(commands.SourceTypeApplicationVersionsFlag, "application-key=source-app,version=3.2.1")
@@ -151,7 +150,6 @@ func TestCreateAppVersionCommand_FlagsSuite(t *testing.T) {
151150
Version: "1.0.0",
152151
Tag: "release-tag",
153152
Draft: true,
154-
SkipUnassigned: true,
155153
Sources: &model.CreateVersionSources{
156154
Builds: []model.CreateVersionBuild{
157155
{Name: "build1", Number: "1.0.0", IncludeDependencies: true, RepositoryKey: "build-info-repo", Started: "2024-01-15T10:30:00Z"},

e2e/utils/artifactory_utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,22 @@ func deleteBuild() {
210210
log.Error("Failed to delete build-info", err)
211211
}
212212
}
213+
214+
func CreateLocalRepo(t *testing.T, suffix string, environments []string) string {
215+
servicesManager := getArtifactoryServicesManager(t)
216+
repoKey := GetTestProjectKey(t) + "-" + suffix
217+
localRepoConfig := services.NewGenericLocalRepositoryParams()
218+
localRepoConfig.ProjectKey = GetTestProjectKey(t)
219+
localRepoConfig.Key = repoKey
220+
localRepoConfig.Environments = environments
221+
err := servicesManager.CreateLocalRepository().Generic(localRepoConfig)
222+
require.NoError(t, err)
223+
t.Cleanup(func() {
224+
_ = servicesManager.DeleteRepository(repoKey)
225+
})
226+
return repoKey
227+
}
228+
229+
func UploadTestArtifact(t *testing.T, repoKey, fileName string) string {
230+
return uploadSimpleFileToArtifactory(t, repoKey, fileName)
231+
}

e2e/version_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,70 @@ 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+
prodRepo := utils.CreateLocalRepo(t, "prod-only-local", []string{"PROD"})
240+
artifactPath := utils.UploadTestArtifact(t, prodRepo, "mismatch-artifact.txt")
241+
artifactFlag := fmt.Sprintf("--source-type-artifacts=path=%s", artifactPath)
242+
output := utils.AppTrustCli.RunCliCmdWithOutput(t, "version-create", appKey, version, artifactFlag, "--skip-unassigned")
243+
defer utils.DeleteApplicationVersion(t, appKey, version)
244+
245+
require.NotEmpty(t, output)
246+
247+
var response struct {
248+
ApplicationKey string `json:"application_key"`
249+
Version string `json:"version"`
250+
Status string `json:"status"`
251+
CurrentStage string `json:"current_stage"`
252+
Message string `json:"message"`
253+
}
254+
err := json.Unmarshal([]byte(output), &response)
255+
require.NoError(t, err, "failed to parse CLI output as JSON: %s", output)
256+
assert.Equal(t, appKey, response.ApplicationKey)
257+
assert.Equal(t, version, response.Version)
258+
assert.Empty(t, response.CurrentStage, "Version should NOT be promoted when artifacts are in PROD-only repo")
259+
assert.NotEmpty(t, response.Message, "A message should explain why auto-promotion did not occur")
260+
})
261+
}
262+
199263
func TestCreateVersion_Async(t *testing.T) {
200264
appKey := utils.GenerateUniqueKey("app-version-create-async")
201265
utils.CreateBasicApplication(t, appKey)

0 commit comments

Comments
 (0)