From c7934b968a7bc0f7b4f2301c05c61c1182393e0e Mon Sep 17 00:00:00 2001 From: yardene Date: Thu, 9 Nov 2023 13:31:24 +0200 Subject: [PATCH 1/3] Added path mappings support for bundle creation and distribution --- artifactory/services/utils/specutils.go | 6 + .../services/utils/distributionutils.go | 12 +- .../services/utils/releasebundlebody.go | 12 +- lifecycle/services/distribute.go | 5 +- tests/distribution_test.go | 106 +++++++++++++++++- utils/distribution/utils.go | 22 ++-- utils/distribution/utils_test.go | 38 ++++++- 7 files changed, 180 insertions(+), 21 deletions(-) diff --git a/artifactory/services/utils/specutils.go b/artifactory/services/utils/specutils.go index 78bd7c797..f24eab695 100644 --- a/artifactory/services/utils/specutils.go +++ b/artifactory/services/utils/specutils.go @@ -18,8 +18,14 @@ type Aql struct { ItemsFind string `json:"items.find"` } +type PathMapping struct { + Input string `json:"input"` + Output string `json:"output"` +} + type CommonParams struct { Aql Aql + PathMapping PathMapping Pattern string Exclusions []string Target string diff --git a/distribution/services/utils/distributionutils.go b/distribution/services/utils/distributionutils.go index 529b16309..6a5660e7c 100644 --- a/distribution/services/utils/distributionutils.go +++ b/distribution/services/utils/distributionutils.go @@ -34,17 +34,23 @@ func NewReleaseBundleParams(name, version string) ReleaseBundleParams { func CreateBundleBody(releaseBundleParams ReleaseBundleParams, dryRun bool) (*ReleaseBundleBody, error) { var bundleQueries []BundleQuery + var pathMappings []rtUtils.PathMapping + // Create release bundle queries for _, specFile := range releaseBundleParams.SpecFiles { + // Create path mapping + if specFile.GetSpecType() == rtUtils.AQL { + pathMappings = distribution.CreatePathMappings(specFile.PathMapping.Input, specFile.PathMapping.Output) + } else { + pathMappings = distribution.CreatePathMappingsFromPatternAndTarget(specFile.Pattern, specFile.Target) + } + // Create AQL aql, err := createAql(specFile) if err != nil { return nil, err } - // Create path mapping - pathMappings := distribution.CreatePathMappings(specFile.Pattern, specFile.Target) - // Create added properties addedProps := createAddedProps(specFile) diff --git a/distribution/services/utils/releasebundlebody.go b/distribution/services/utils/releasebundlebody.go index e98a9fe26..3e16d49b9 100644 --- a/distribution/services/utils/releasebundlebody.go +++ b/distribution/services/utils/releasebundlebody.go @@ -1,6 +1,8 @@ package utils -import "github.com/jfrog/jfrog-client-go/utils/distribution" +import ( + "github.com/jfrog/jfrog-client-go/artifactory/services/utils" +) // REST body for create and update a release bundle type ReleaseBundleBody struct { @@ -22,10 +24,10 @@ type BundleSpec struct { } type BundleQuery struct { - QueryName string `json:"query_name,omitempty"` - Aql string `json:"aql,omitempty"` - PathMappings []distribution.PathMapping `json:"mappings,omitempty"` - AddedProps []AddedProps `json:"added_props,omitempty"` + QueryName string `json:"query_name,omitempty"` + Aql string `json:"aql,omitempty"` + PathMappings []utils.PathMapping `json:"mappings,omitempty"` + AddedProps []AddedProps `json:"added_props,omitempty"` } type AddedProps struct { diff --git a/lifecycle/services/distribute.go b/lifecycle/services/distribute.go index 2e61bcae8..447583a28 100644 --- a/lifecycle/services/distribute.go +++ b/lifecycle/services/distribute.go @@ -1,6 +1,7 @@ package services import ( + "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/distribution" @@ -62,7 +63,7 @@ func (dr *DistributeReleaseBundleService) createDistributeBody() ReleaseBundleDi return ReleaseBundleDistributeBody{ ReleaseBundleDistributeV1Body: distribution.CreateDistributeV1Body(dr.DistributeParams, dr.DryRun, dr.AutoCreateRepo), Modifications: Modifications{ - PathMappings: distribution.CreatePathMappings(dr.Pattern, dr.Target), + PathMappings: distribution.CreatePathMappingsFromPatternAndTarget(dr.Pattern, dr.Target), }, } } @@ -73,7 +74,7 @@ type ReleaseBundleDistributeBody struct { } type Modifications struct { - PathMappings []distribution.PathMapping `json:"mappings"` + PathMappings []utils.PathMapping `json:"mappings"` } type PathMapping struct { diff --git a/tests/distribution_test.go b/tests/distribution_test.go index 34acf0ca9..34bea56d2 100644 --- a/tests/distribution_test.go +++ b/tests/distribution_test.go @@ -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 /b.in to /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) + + // Make sure /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 createDistributeMappingFromPatternAndTarget(t *testing.T) { + bundleName := initRemoteDistributionTest(t, "client-test-bundle-"+getRunId()) + // Create release bundle with path mapping from /b.in to /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 /b.in to /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\"}}]}]}", + }, + PathMapping: utils.PathMapping{ + Input: "(" + getRtTargetRepo() + ")" + "(.*).in", + Output: "$1$2.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) + + // Make sure /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 /b.in to /b.out diff --git a/utils/distribution/utils.go b/utils/distribution/utils.go index 2c6ef7921..066cb7e45 100644 --- a/utils/distribution/utils.go +++ b/utils/distribution/utils.go @@ -2,19 +2,20 @@ package distribution import ( "github.com/jfrog/gofrog/stringutils" + "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "regexp" ) var fileSpecCaptureGroup = regexp.MustCompile(`({\d})`) -// Create the path mapping from the input spec -func CreatePathMappings(pattern, target string) []PathMapping { +// Create the path mapping from the input spec which includes pattern and target +func CreatePathMappingsFromPatternAndTarget(pattern, target string) []utils.PathMapping { if len(target) == 0 { - return []PathMapping{} + return []utils.PathMapping{} } // Convert the file spec pattern and target to match the path mapping input and output specifications, respectfully. - return []PathMapping{{ + return []utils.PathMapping{{ // The file spec pattern is wildcard based. Convert it to Regex: Input: stringutils.WildcardPatternToRegExp(pattern), // The file spec target contain placeholders-style matching groups, like {1}. @@ -26,7 +27,14 @@ func CreatePathMappings(pattern, target string) []PathMapping { }} } -type PathMapping struct { - Input string `json:"input"` - Output string `json:"output"` +// Create the path mapping from the input spec +func CreatePathMappings(input, output string) []utils.PathMapping { + if len(input) == 0 || len(output) == 0 { + return []utils.PathMapping{} + } + + return []utils.PathMapping{{ + Input: input, + Output: output, + }} } diff --git a/utils/distribution/utils_test.go b/utils/distribution/utils_test.go index 6eeb5235c..c9b47de34 100644 --- a/utils/distribution/utils_test.go +++ b/utils/distribution/utils_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -func TestCreatePathMappings(t *testing.T) { +func TestCreatePathMappingsFromPatternAndTarget(t *testing.T) { tests := []struct { specPattern string specTarget string @@ -27,7 +27,41 @@ func TestCreatePathMappings(t *testing.T) { for _, test := range tests { t.Run(test.specPattern, func(t *testing.T) { specFile := &utils.CommonParams{Pattern: test.specPattern, Target: test.specTarget} - pathMappings := CreatePathMappings(specFile.Pattern, specFile.Target) + pathMappings := CreatePathMappingsFromPatternAndTarget(specFile.Pattern, specFile.Target) + if test.expectedMappingInput == "" { + assert.Empty(t, pathMappings) + return + } + assert.Len(t, pathMappings, 1) + actualPathMapping := pathMappings[0] + assert.Equal(t, test.expectedMappingInput, actualPathMapping.Input) + assert.Equal(t, test.expectedMappingOutput, actualPathMapping.Output) + }) + } +} + +func TestCreatePathMappings(t *testing.T) { + tests := []struct { + specInput string + specOutput string + expectedMappingInput string + expectedMappingOutput string + }{ + {"", "", "", ""}, + {"repo/path/file.in", "", "", ""}, + {"", "repo/path/file.out", "", ""}, + {"a/b/c", "a/b/x", "a/b/c", "a/b/x"}, + } + + for _, test := range tests { + t.Run(test.specInput, func(t *testing.T) { + specFile := &utils.CommonParams{ + PathMapping: utils.PathMapping{ + Input: test.specInput, + Output: test.specOutput, + }, + } + pathMappings := CreatePathMappings(specFile.PathMapping.Input, specFile.PathMapping.Output) if test.expectedMappingInput == "" { assert.Empty(t, pathMappings) return From aed86c72e04b21ac575b535f87237ccb2d2a3347 Mon Sep 17 00:00:00 2001 From: yardene Date: Sun, 26 Nov 2023 13:51:02 +0200 Subject: [PATCH 2/3] Added path mappings support for bundle creation and distribution --- tests/distribution_test.go | 129 +++++++++++++++---------------------- 1 file changed, 51 insertions(+), 78 deletions(-) diff --git a/tests/distribution_test.go b/tests/distribution_test.go index 34bea56d2..d2de9e99a 100644 --- a/tests/distribution_test.go +++ b/tests/distribution_test.go @@ -45,17 +45,17 @@ func TestDistributionServices(t *testing.T) { sendGpgKeys(t) // Local release bundle tests - t.Run("createDelete", createDelete) - t.Run("createUpdate", createUpdate) - t.Run("createWithProps", createWithProps) + //t.Run("createDelete", createDelete) + //t.Run("createUpdate", createUpdate) + //t.Run("createWithProps", createWithProps) // Remote release bundle tests - t.Run("createSignDistributeDelete", createSignDistributeDelete) - t.Run("createSignSyncDistributeDelete", createSignSyncDistributeDelete) + //t.Run("createSignDistributeDelete", createSignDistributeDelete) + //t.Run("createSignSyncDistributeDelete", createSignSyncDistributeDelete) t.Run("createDistributeMapping", createDistributeMapping) - t.Run("createDistributeMappingFromPatternAndTarget", createDistributeMappingFromPatternAndTarget) - t.Run("createDistributeMappingWithPlaceholder", createDistributeMappingWithPlaceholder) - t.Run("createDistributeMappingFromPatternAndTargetWithPlaceholder", createDistributeMappingFromPatternAndTargetWithPlaceholder) + //t.Run("createDistributeMappingFromPatternAndTarget", createDistributeMappingFromPatternAndTarget) + //t.Run("createDistributeMappingWithPlaceholder", createDistributeMappingWithPlaceholder) + //t.Run("createDistributeMappingFromPatternAndTargetWithPlaceholder", createDistributeMappingFromPatternAndTargetWithPlaceholder) artifactoryCleanup(t) deleteGpgKeys(t) @@ -369,7 +369,7 @@ func createDistributeMapping(t *testing.T) { createBundleParams.SpecFiles = []*utils.CommonParams{ { Aql: utils.Aql{ - ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\": \"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"b.in\"}}]}]}", + ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\":\"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"b.in\"}}]}]}", }, PathMapping: utils.PathMapping{ Input: getRtTargetRepo() + "b.in", @@ -379,9 +379,8 @@ func createDistributeMapping(t *testing.T) { } createBundleParams.SignImmediately = true summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) - if !assert.NoError(t, err) { - return - } + assert.NoError(t, err) + defer deleteRemoteAndLocalBundle(t, bundleName) assert.NotNil(t, summary) verifyValidSha256(t, summary.GetSha256()) @@ -396,15 +395,11 @@ func createDistributeMapping(t *testing.T) { err = testsBundleDistributeService.Distribute() assert.NoError(t, err) + // Distribute release bundle + assertReleaseBundleDistribution(t, bundleName) + // Make sure /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) + assertFileExistsInArtifactory(t, getRtTargetRepo()+"b.out") } func createDistributeMappingFromPatternAndTarget(t *testing.T) { @@ -415,32 +410,17 @@ func createDistributeMappingFromPatternAndTarget(t *testing.T) { createBundleParams.SpecFiles = []*utils.CommonParams{{Pattern: getRtTargetRepo() + "b.in", Target: getRtTargetRepo() + "b.out"}} createBundleParams.SignImmediately = true summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) - if !assert.NoError(t, err) { - return - } + assert.NoError(t, err) + 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) + assertReleaseBundleDistribution(t, bundleName) // Make sure /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) + assertFileExistsInArtifactory(t, getRtTargetRepo()+"b.out") } func createDistributeMappingWithPlaceholder(t *testing.T) { @@ -451,7 +431,7 @@ func createDistributeMappingWithPlaceholder(t *testing.T) { createBundleParams.SpecFiles = []*utils.CommonParams{ { Aql: utils.Aql{ - ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\": \"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"*.in\"}}]}]}", + ItemsFind: "{\"$or\":[{\"$and\":[{\"repo\":{\"$match\":\"" + strings.TrimSuffix(getRtTargetRepo(), "/") + "\"},\"name\":{\"$match\":\"*.in\"}}]}]}", }, PathMapping: utils.PathMapping{ Input: "(" + getRtTargetRepo() + ")" + "(.*).in", @@ -462,32 +442,17 @@ func createDistributeMappingWithPlaceholder(t *testing.T) { createBundleParams.SignImmediately = true summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) - if !assert.NoError(t, err) { - return - } + assert.NoError(t, err) + 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) + assertReleaseBundleDistribution(t, bundleName) // Make sure /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) + assertFileExistsInArtifactory(t, getRtTargetRepo()+"b.out") } func createDistributeMappingFromPatternAndTargetWithPlaceholder(t *testing.T) { @@ -498,32 +463,17 @@ func createDistributeMappingFromPatternAndTargetWithPlaceholder(t *testing.T) { createBundleParams.SpecFiles = []*utils.CommonParams{{Pattern: "(" + getRtTargetRepo() + ")" + "(*).in", Target: "{1}{2}.out"}} createBundleParams.SignImmediately = true summary, err := testsBundleCreateService.CreateReleaseBundle(createBundleParams) - if !assert.NoError(t, err) { - return - } + assert.NoError(t, err) + 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) + assertReleaseBundleDistribution(t, bundleName) // Make sure /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) + assertFileExistsInArtifactory(t, getRtTargetRepo()+"b.out") } // Send GPG keys to Distribution and Artifactory to allow signing of release bundles @@ -669,3 +619,26 @@ func deleteRemoteAndLocalBundle(t *testing.T, bundleName string) { artifactoryCleanup(t) assert.NoError(t, err) } + +func assertFileExistsInArtifactory(t *testing.T, filePath string) { + searchParams := artifactoryServices.NewSearchParams() + searchParams.Pattern = filePath + 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 assertReleaseBundleDistribution(t *testing.T, bundleName string) { + // 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) +} From 39b3825ae436004f23d7ad39f95d3b48e47426cd Mon Sep 17 00:00:00 2001 From: yardene Date: Sun, 26 Nov 2023 13:52:19 +0200 Subject: [PATCH 3/3] Added path mappings support for bundle creation and distribution --- tests/distribution_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/distribution_test.go b/tests/distribution_test.go index d2de9e99a..e6c6144f0 100644 --- a/tests/distribution_test.go +++ b/tests/distribution_test.go @@ -45,17 +45,17 @@ func TestDistributionServices(t *testing.T) { sendGpgKeys(t) // Local release bundle tests - //t.Run("createDelete", createDelete) - //t.Run("createUpdate", createUpdate) - //t.Run("createWithProps", createWithProps) + t.Run("createDelete", createDelete) + t.Run("createUpdate", createUpdate) + t.Run("createWithProps", createWithProps) // Remote release bundle tests - //t.Run("createSignDistributeDelete", createSignDistributeDelete) - //t.Run("createSignSyncDistributeDelete", createSignSyncDistributeDelete) + t.Run("createSignDistributeDelete", createSignDistributeDelete) + t.Run("createSignSyncDistributeDelete", createSignSyncDistributeDelete) t.Run("createDistributeMapping", createDistributeMapping) - //t.Run("createDistributeMappingFromPatternAndTarget", createDistributeMappingFromPatternAndTarget) - //t.Run("createDistributeMappingWithPlaceholder", createDistributeMappingWithPlaceholder) - //t.Run("createDistributeMappingFromPatternAndTargetWithPlaceholder", createDistributeMappingFromPatternAndTargetWithPlaceholder) + t.Run("createDistributeMappingFromPatternAndTarget", createDistributeMappingFromPatternAndTarget) + t.Run("createDistributeMappingWithPlaceholder", createDistributeMappingWithPlaceholder) + t.Run("createDistributeMappingFromPatternAndTargetWithPlaceholder", createDistributeMappingFromPatternAndTargetWithPlaceholder) artifactoryCleanup(t) deleteGpgKeys(t)