Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions apptrust/commands/version/create_app_version_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type createAppVersionCommand struct {
}

type createVersionSpec struct {
Artifacts []model.CreateVersionArtifact `json:"artifacts,omitempty"`
Packages []model.CreateVersionPackage `json:"packages,omitempty"`
Builds []model.CreateVersionBuild `json:"builds,omitempty"`
ReleaseBundles []model.CreateVersionReleaseBundle `json:"release_bundles,omitempty"`
Expand Down Expand Up @@ -137,11 +138,12 @@ func (cv *createAppVersionCommand) loadFromSpec(ctx *components.Context) (*model
}

// Validation: if all sources are empty, return error
if (len(spec.Packages) == 0) && (len(spec.Builds) == 0) && (len(spec.ReleaseBundles) == 0) && (len(spec.Versions) == 0) {
return nil, errorutils.CheckErrorf("Spec file is empty: must provide at least one source (packages, builds, release_bundles, or versions)")
if (len(spec.Packages) == 0) && (len(spec.Builds) == 0) && (len(spec.ReleaseBundles) == 0) && (len(spec.Versions) == 0) && (len(spec.Artifacts) == 0) {
return nil, errorutils.CheckErrorf("Spec file is empty: must provide at least one source (artifacts, packages, builds, release_bundles, or versions)")
}

sources := &model.CreateVersionSources{
Artifacts: spec.Artifacts,
Packages: spec.Packages,
Builds: spec.Builds,
ReleaseBundles: spec.ReleaseBundles,
Expand Down
137 changes: 137 additions & 0 deletions apptrust/commands/version/create_app_version_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,143 @@ func TestCreateAppVersionCommand_SpecFileSuite(t *testing.T) {
expectsError: true,
errorContains: "Spec file is empty",
},
{
name: "artifacts spec file",
specPath: "./testfiles/artifacts-spec.json",
args: []string{"app-artifacts", "1.0.0"},
expectsPayload: &model.CreateAppVersionRequest{
ApplicationKey: "app-artifacts",
Version: "1.0.0",
Sources: &model.CreateVersionSources{
Artifacts: []model.CreateVersionArtifact{
{
Path: "repo/path/to/artifact1.jar",
SHA256: "abc123def456",
},
{
Path: "repo/path/to/artifact2.war",
},
},
},
},
},
{
name: "artifacts only spec file",
specPath: "./testfiles/artifacts-only-spec.json",
args: []string{"app-single-artifact", "2.0.0"},
expectsPayload: &model.CreateAppVersionRequest{
ApplicationKey: "app-single-artifact",
Version: "2.0.0",
Sources: &model.CreateVersionSources{
Artifacts: []model.CreateVersionArtifact{
{
Path: "repo/path/to/single-artifact.jar",
SHA256: "1234567890abcdef",
},
},
},
},
},
{
name: "mixed sources with artifacts spec file",
specPath: "./testfiles/mixed-sources-spec.json",
args: []string{"app-mixed", "3.0.0"},
expectsPayload: &model.CreateAppVersionRequest{
ApplicationKey: "app-mixed",
Version: "3.0.0",
Sources: &model.CreateVersionSources{
Artifacts: []model.CreateVersionArtifact{
{
Path: "repo/path/to/artifact.jar",
SHA256: "abc123",
},
},
Packages: []model.CreateVersionPackage{
{
Type: "npm",
Name: "my-package",
Version: "1.0.0",
Repository: "npm-repo",
},
},
Builds: []model.CreateVersionBuild{
{
Name: "build1",
Number: "42",
},
},
},
},
},
{
name: "all sources spec file",
specPath: "./testfiles/all-sources-spec.json",
args: []string{"app-all-sources", "5.0.0"},
expectsPayload: &model.CreateAppVersionRequest{
ApplicationKey: "app-all-sources",
Version: "5.0.0",
Sources: &model.CreateVersionSources{
Artifacts: []model.CreateVersionArtifact{
{
Path: "repo/path/to/app.jar",
SHA256: "abc123def456789",
},
{
Path: "repo/path/to/lib.war",
},
},
Packages: []model.CreateVersionPackage{
{
Type: "npm",
Name: "my-package",
Version: "1.2.3",
Repository: "npm-local",
},
{
Type: "docker",
Name: "my-docker-image",
Version: "2.0.0",
Repository: "docker-local",
},
},
Builds: []model.CreateVersionBuild{
{
Name: "my-build",
Number: "123",
IncludeDependencies: true,
},
{
Name: "another-build",
Number: "456",
RepositoryKey: "build-info",
IncludeDependencies: false,
},
},
ReleaseBundles: []model.CreateVersionReleaseBundle{
{
Name: "my-release-bundle",
Version: "1.0.0",
ProjectKey: "my-project",
RepositoryKey: "rb-repo",
},
{
Name: "another-bundle",
Version: "2.0.0",
},
},
Versions: []model.CreateVersionReference{
{
ApplicationKey: "dependency-app-1",
Version: "3.0.0",
},
{
ApplicationKey: "dependency-app-2",
Version: "4.5.6",
},
},
},
},
},
}

for _, tt := range tests {
Expand Down
61 changes: 61 additions & 0 deletions apptrust/commands/version/testfiles/all-sources-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"artifacts": [
{
"path": "repo/path/to/app.jar",
"sha256": "abc123def456789"
},
{
"path": "repo/path/to/lib.war"
}
],
"packages": [
{
"type": "npm",
"name": "my-package",
"version": "1.2.3",
"repository_key": "npm-local"
},
{
"type": "docker",
"name": "my-docker-image",
"version": "2.0.0",
"repository_key": "docker-local"
}
],
"builds": [
{
"name": "my-build",
"number": "123",
"include_dependencies": true
},
{
"name": "another-build",
"number": "456",
"repository_key": "build-info",
"include_dependencies": false
}
],
"release_bundles": [
{
"name": "my-release-bundle",
"version": "1.0.0",
"project_key": "my-project",
"repository_key": "rb-repo"
},
{
"name": "another-bundle",
"version": "2.0.0"
}
],
"versions": [
{
"application_key": "dependency-app-1",
"version": "3.0.0"
},
{
"application_key": "dependency-app-2",
"version": "4.5.6"
}
]
}

9 changes: 9 additions & 0 deletions apptrust/commands/version/testfiles/artifacts-only-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"artifacts": [
{
"path": "repo/path/to/single-artifact.jar",
"sha256": "1234567890abcdef"
}
]
}

12 changes: 12 additions & 0 deletions apptrust/commands/version/testfiles/artifacts-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"artifacts": [
{
"path": "repo/path/to/artifact1.jar",
"sha256": "abc123def456"
},
{
"path": "repo/path/to/artifact2.war"
}
]
}

23 changes: 23 additions & 0 deletions apptrust/commands/version/testfiles/mixed-sources-spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"artifacts": [
{
"path": "repo/path/to/artifact.jar",
"sha256": "abc123"
}
],
"packages": [
{
"type": "npm",
"name": "my-package",
"version": "1.0.0",
"repository_key": "npm-repo"
}
],
"builds": [
{
"name": "build1",
"number": "42"
}
]
}

1 change: 1 addition & 0 deletions apptrust/model/create_app_version_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type CreateVersionPackage struct {
}

type CreateVersionSources struct {
Artifacts []CreateVersionArtifact `json:"artifacts,omitempty"`
Packages []CreateVersionPackage `json:"packages,omitempty"`
Builds []CreateVersionBuild `json:"builds,omitempty"`
ReleaseBundles []CreateVersionReleaseBundle `json:"release_bundles,omitempty"`
Expand Down
Loading