-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Distribution path mapping with AQL #861
Changes from 2 commits
c7934b9
16b115a
aed86c7
39b3825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |||||
"net/http" | ||||||
"os" | ||||||
"path/filepath" | ||||||
"strings" | ||||||
"testing" | ||||||
"time" | ||||||
) | ||||||
|
@@ -52,7 +53,9 @@ func TestDistributionServices(t *testing.T) { | |||||
t.Run("createSignDistributeDelete", createSignDistributeDelete) | ||||||
t.Run("createSignSyncDistributeDelete", createSignSyncDistributeDelete) | ||||||
t.Run("createDistributeMapping", createDistributeMapping) | ||||||
t.Run("createDistributeMappingPlaceholder", createDistributeMappingPlaceholder) | ||||||
t.Run("createDistributeMappingFromPatternAndTarget", createDistributeMappingFromPatternAndTarget) | ||||||
t.Run("createDistributeMappingWithPlaceholder", createDistributeMappingWithPlaceholder) | ||||||
t.Run("createDistributeMappingFromPatternAndTargetWithPlaceholder", createDistributeMappingFromPatternAndTargetWithPlaceholder) | ||||||
|
||||||
artifactoryCleanup(t) | ||||||
deleteGpgKeys(t) | ||||||
|
@@ -123,6 +126,9 @@ func createUpdate(t *testing.T) { | |||||
// Verify was not created. | ||||||
getLocalBundle(t, bundleName, false) | ||||||
|
||||||
// Redefine specFiles to create params from scratch | ||||||
createBundleParams.SpecFiles[0] = &utils.CommonParams{Pattern: getRtTargetRepo() + "b.in"} | ||||||
|
||||||
// Create unsigned release bundle | ||||||
summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) | ||||||
if !assert.NoError(t, err) { | ||||||
|
@@ -147,6 +153,9 @@ func createUpdate(t *testing.T) { | |||||
// Verify the release bundle was not updated. | ||||||
assertCreatedLocalBundle(t, bundleName, createBundleParams) | ||||||
|
||||||
// Redefine specFiles to create params from scratch | ||||||
updateBundleParams.SpecFiles[0] = &utils.CommonParams{Pattern: getRtTargetRepo() + "test/a.in"} | ||||||
|
||||||
summary, err = testsBundleUpdateService.UpdateReleaseBundle(updateBundleParams) | ||||||
if !assert.NoError(t, err) { | ||||||
return | ||||||
|
@@ -355,6 +364,52 @@ func createSignSyncDistributeDelete(t *testing.T) { | |||||
func createDistributeMapping(t *testing.T) { | ||||||
bundleName := initRemoteDistributionTest(t, "client-test-bundle-"+getRunId()) | ||||||
|
||||||
// Create release bundle with path mapping from <RtTargetRepo>/b.in to <RtTargetRepo>/b.out | ||||||
createBundleParams := services.NewCreateReleaseBundleParams(bundleName, bundleVersion) | ||||||
createBundleParams.SpecFiles = []*utils.CommonParams{ | ||||||
{ | ||||||
Aql: utils.Aql{ | ||||||
ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\": \"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"b.in\"}}]}]}", | ||||||
}, | ||||||
PathMapping: utils.PathMapping{ | ||||||
Input: getRtTargetRepo() + "b.in", | ||||||
Output: getRtTargetRepo() + "b.out", | ||||||
}, | ||||||
}, | ||||||
} | ||||||
createBundleParams.SignImmediately = true | ||||||
summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) | ||||||
if !assert.NoError(t, err) { | ||||||
return | ||||||
} | ||||||
defer deleteRemoteAndLocalBundle(t, bundleName) | ||||||
assert.NotNil(t, summary) | ||||||
verifyValidSha256(t, summary.GetSha256()) | ||||||
|
||||||
// Distribute release bundle | ||||||
distributeBundleParams := distribution.NewDistributeReleaseBundleParams(bundleName, bundleVersion) | ||||||
distributeBundleParams.DistributionRules = []*distribution.DistributionCommonParams{{SiteName: "*"}} | ||||||
testsBundleDistributeService.Sync = true | ||||||
// On distribution with path mapping, the target repository cannot be auto-created | ||||||
testsBundleDistributeService.AutoCreateRepo = false | ||||||
testsBundleDistributeService.DistributeParams = distributeBundleParams | ||||||
err = testsBundleDistributeService.Distribute() | ||||||
assert.NoError(t, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above code lines seem to be duplicated multiple times in this file. Let's move into a function and reuse the code. |
||||||
|
||||||
// Make sure <RtTargetRepo>/b.out does exist in Artifactory | ||||||
searchParams := artifactoryServices.NewSearchParams() | ||||||
searchParams.Pattern = getRtTargetRepo() + "b.out" | ||||||
reader, err := testsSearchService.Search(searchParams) | ||||||
assert.NoError(t, err) | ||||||
readerCloseAndAssert(t, reader) | ||||||
length, err := reader.Length() | ||||||
assert.NoError(t, err) | ||||||
assert.Equal(t, 1, length) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above code lines seem to be duplicated multiple times in this file. Let's move into a function and reuse the code. |
||||||
} | ||||||
|
||||||
func createDistributeMappingFromPatternAndTarget(t *testing.T) { | ||||||
bundleName := initRemoteDistributionTest(t, "client-test-bundle-"+getRunId()) | ||||||
|
||||||
// Create release bundle with path mapping from <RtTargetRepo>/b.in to <RtTargetRepo>/b.out | ||||||
createBundleParams := services.NewCreateReleaseBundleParams(bundleName, bundleVersion) | ||||||
createBundleParams.SpecFiles = []*utils.CommonParams{{Pattern: getRtTargetRepo() + "b.in", Target: getRtTargetRepo() + "b.out"}} | ||||||
|
@@ -388,7 +443,54 @@ func createDistributeMapping(t *testing.T) { | |||||
assert.Equal(t, 1, length) | ||||||
} | ||||||
|
||||||
func createDistributeMappingPlaceholder(t *testing.T) { | ||||||
func createDistributeMappingWithPlaceholder(t *testing.T) { | ||||||
bundleName := initRemoteDistributionTest(t, "client-test-bundle-"+getRunId()) | ||||||
|
||||||
// Create release bundle with path mapping from <RtTargetRepo>/b.in to <RtTargetRepo>/b.out | ||||||
createBundleParams := services.NewCreateReleaseBundleParams(bundleName, bundleVersion) | ||||||
createBundleParams.SpecFiles = []*utils.CommonParams{ | ||||||
{ | ||||||
Aql: utils.Aql{ | ||||||
ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\": \"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"*.in\"}}]}]}", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}, | ||||||
PathMapping: utils.PathMapping{ | ||||||
Input: "(" + getRtTargetRepo() + ")" + "(.*).in", | ||||||
Output: "$1$2.out", | ||||||
}, | ||||||
}, | ||||||
} | ||||||
|
||||||
createBundleParams.SignImmediately = true | ||||||
summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) | ||||||
if !assert.NoError(t, err) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better readability and shorter code, let's not use "ifs" in tests. The "assert" and/or "require" alone should help us to eliminate them. |
||||||
return | ||||||
} | ||||||
defer deleteRemoteAndLocalBundle(t, bundleName) | ||||||
assert.NotNil(t, summary) | ||||||
verifyValidSha256(t, summary.GetSha256()) | ||||||
|
||||||
// Distribute release bundle | ||||||
distributeBundleParams := distribution.NewDistributeReleaseBundleParams(bundleName, bundleVersion) | ||||||
distributeBundleParams.DistributionRules = []*distribution.DistributionCommonParams{{SiteName: "*"}} | ||||||
testsBundleDistributeService.Sync = true | ||||||
// On distribution with path mapping, the target repository cannot be auto-created | ||||||
testsBundleDistributeService.AutoCreateRepo = false | ||||||
testsBundleDistributeService.DistributeParams = distributeBundleParams | ||||||
err = testsBundleDistributeService.Distribute() | ||||||
assert.NoError(t, err) | ||||||
|
||||||
// Make sure <RtTargetRepo>/b.out does exist in Artifactory | ||||||
searchParams := artifactoryServices.NewSearchParams() | ||||||
searchParams.Pattern = getRtTargetRepo() + "b.out" | ||||||
reader, err := testsSearchService.Search(searchParams) | ||||||
assert.NoError(t, err) | ||||||
readerCloseAndAssert(t, reader) | ||||||
length, err := reader.Length() | ||||||
assert.NoError(t, err) | ||||||
assert.Equal(t, 1, length) | ||||||
} | ||||||
|
||||||
func createDistributeMappingFromPatternAndTargetWithPlaceholder(t *testing.T) { | ||||||
bundleName := initRemoteDistributionTest(t, "client-test-bundle-"+getRunId()) | ||||||
|
||||||
// Create release bundle with path mapping from <RtTargetRepo>/b.in to <RtTargetRepo>/b.out | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.