|
6 | 6 | "encoding/json" |
7 | 7 | "fmt" |
8 | 8 | "net/http" |
| 9 | + "strings" |
9 | 10 | "testing" |
10 | 11 | "time" |
11 | 12 |
|
@@ -234,6 +235,51 @@ func TestUpdateVersion(t *testing.T) { |
234 | 235 | assert.Equal(t, tag, versionContent.Tag) |
235 | 236 | } |
236 | 237 |
|
| 238 | +func TestUpdateDraftVersionSources(t *testing.T) { |
| 239 | + appKey := utils.GenerateUniqueKey("app-version-update-sources") |
| 240 | + utils.CreateBasicApplication(t, appKey) |
| 241 | + defer utils.DeleteApplication(t, appKey) |
| 242 | + testPackage := utils.GetTestPackage(t) |
| 243 | + version := "1.0.6" |
| 244 | + packageFlag := fmt.Sprintf("--source-type-packages=type=%s, name=%s, version=%s, repo-key=%s", |
| 245 | + testPackage.PackageType, testPackage.PackageName, testPackage.PackageVersion, testPackage.RepoKey) |
| 246 | + err := utils.AppTrustCli.Exec("version-create", appKey, version, packageFlag, "--draft") |
| 247 | + require.NoError(t, err) |
| 248 | + defer utils.DeleteApplicationVersion(t, appKey, version) |
| 249 | + artifactPath := utils.GetTestArtifact(t) |
| 250 | + artifactFlag := fmt.Sprintf("--source-type-artifacts=path=%s", artifactPath) |
| 251 | + |
| 252 | + err = utils.AppTrustCli.Exec("version-update-sources", appKey, version, artifactFlag) |
| 253 | + require.NoError(t, err) |
| 254 | + |
| 255 | + versionContent, statusCode, err := utils.GetApplicationVersion(appKey, version) |
| 256 | + require.NoError(t, err) |
| 257 | + assert.Equal(t, http.StatusOK, statusCode) |
| 258 | + require.NotNil(t, versionContent) |
| 259 | + assert.Equal(t, appKey, versionContent.ApplicationKey) |
| 260 | + assert.Equal(t, version, versionContent.Version) |
| 261 | + assert.Contains(t, utils.StatusDraft, versionContent.Status) |
| 262 | + var artifactPaths []string |
| 263 | + for _, r := range versionContent.Releasables { |
| 264 | + for _, a := range r.Artifacts { |
| 265 | + artifactPaths = append(artifactPaths, a.Path) |
| 266 | + } |
| 267 | + } |
| 268 | + assert.True(t, containsPath(artifactPaths, testPackage.PackagePath), |
| 269 | + "expected package path %q in version releasables (got %v)", testPackage.PackagePath, artifactPaths) |
| 270 | + assert.True(t, containsPath(artifactPaths, artifactPath), |
| 271 | + "expected artifact path %q in version releasables (got %v)", artifactPath, artifactPaths) |
| 272 | +} |
| 273 | + |
| 274 | +func containsPath(paths []string, target string) bool { |
| 275 | + for _, path := range paths { |
| 276 | + if strings.Contains(target, path) { |
| 277 | + return true |
| 278 | + } |
| 279 | + } |
| 280 | + return false |
| 281 | +} |
| 282 | + |
237 | 283 | func TestDeleteVersion(t *testing.T) { |
238 | 284 | // Prepare |
239 | 285 | appKey := utils.GenerateUniqueKey("app-version-delete") |
|
0 commit comments