Skip to content

Commit 062415a

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 062415a

3 files changed

Lines changed: 78 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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ func uploadPackageToArtifactory(t *testing.T, repoKey, buildName, buildNumber st
125125
return artifactDetails.Checksums.Sha256
126126
}
127127

128+
func CreateGenericRepoWithEnv(t *testing.T, suffix string, environments []string) string {
129+
servicesManager := getArtifactoryServicesManager(t)
130+
repoKey := GetTestProjectKey(t) + "-" + suffix
131+
localRepoConfig := services.NewGenericLocalRepositoryParams()
132+
localRepoConfig.ProjectKey = GetTestProjectKey(t)
133+
localRepoConfig.Key = repoKey
134+
localRepoConfig.Environments = environments
135+
err := servicesManager.CreateLocalRepository().Generic(localRepoConfig)
136+
require.NoError(t, err)
137+
t.Cleanup(func() { _ = servicesManager.DeleteRepository(repoKey) })
138+
return repoKey
139+
}
140+
141+
func UploadTestArtifact(t *testing.T, repoKey, fileName string) string {
142+
return uploadSimpleFileToArtifactory(t, repoKey, fileName)
143+
}
144+
128145
func uploadSimpleFileToArtifactory(t *testing.T, repoKey, targetFileName string) string {
129146
tmpFile, err := os.CreateTemp("", "e2e-artifact-*.txt")
130147
require.NoError(t, err)

e2e/version_test.go

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

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

0 commit comments

Comments
 (0)