diff --git a/artifactory_test.go b/artifactory_test.go index f8b02c075..028460847 100644 --- a/artifactory_test.go +++ b/artifactory_test.go @@ -1442,7 +1442,7 @@ func checkSyncedDirContent(expected, actual []string, t *testing.T) { assert.NoError(t, err) } -// Check if only the files we were expecting, exist locally, i.e return an error if there is a local file we didn't expect. +// Check if only the files we were expecting, exist locally, i.e. return an error if there is a local file we didn't expect. // Since the "actual" list contains paths of both directories and files, for each element in the "actual" list: // Check if the path equals to an existing file (for a file) OR // if the path is a prefix of some path of an existing file (for a dir). @@ -1670,9 +1670,9 @@ func testArtifactoryProxy(t *testing.T, isHttps bool) { } authenticate(true) proxyRtUrl := prepareArtifactoryUrlForProxyTest(t) - spec := spec.NewBuilder().Pattern(tests.RtRepo1 + "/*.zip").Recursive(true).BuildSpec() + searchSpec := spec.NewBuilder().Pattern(tests.RtRepo1 + "/*.zip").Recursive(true).BuildSpec() serverDetails.ArtifactoryUrl = proxyRtUrl - checkForErrDueToMissingProxy(spec, t) + checkForErrDueToMissingProxy(searchSpec, t) var port string if isHttps { go cliproxy.StartHttpsProxy() @@ -1685,7 +1685,7 @@ func testArtifactoryProxy(t *testing.T, isHttps bool) { err := checkIfServerIsUp(port, "http", false) assert.NoError(t, err) searchCmd := generic.NewSearchCommand() - searchCmd.SetServerDetails(serverDetails).SetSpec(spec) + searchCmd.SetServerDetails(serverDetails).SetSpec(searchSpec) reader, err := searchCmd.Search() assert.NoError(t, err) if reader != nil { @@ -2814,7 +2814,7 @@ func TestArtifactoryUploadFlatFolderWithFileAndInnerEmptyMatchingPattern(t *test err := os.MkdirAll(newFolderPath, 0777) assert.NoError(t, err) // We created an empty child folder to 'c' therefore 'c' is not longer a bottom chain and new 'd' inner directory is indeed bottom chain directory. - // 'd' should uploaded and 'c' shouldn't + // 'd' should be uploaded and 'c' shouldn't runRt(t, "upload", tests.GetTestResourcesPath()+"a/b/*", tests.RtRepo1, "--include-dirs=true", "--flat=true") clientTestUtils.RemoveAllAndAssert(t, newFolderPath) runRt(t, "download", tests.RtRepo1, tests.Out+"/", "--include-dirs=true", "--recursive=true") @@ -2832,7 +2832,7 @@ func TestArtifactoryUploadFlatFolderWithFileAndInnerEmptyMatchingPatternWithPlac err := os.MkdirAll(fullPath, 0777) assert.NoError(t, err) // We created an empty child folder to 'c' therefore 'c' is not longer a bottom chain and new 'd' inner directory is indeed bottom chain directory. - // 'd' should uploaded and 'c' shouldn't + // 'd' should be uploaded and 'c' shouldn't runRt(t, "upload", tests.GetTestResourcesPath()+"a/(*)/*", tests.RtRepo1+"/{1}/", "--include-dirs=true", "--flat=true") clientTestUtils.RemoveAllAndAssert(t, fullPath) runRt(t, "download", tests.RtRepo1, tests.Out+"/", "--include-dirs=true", "--recursive=true") @@ -3857,7 +3857,7 @@ func TestArtifactoryCopyByBuildOverridingByInlineFlag(t *testing.T) { runRt(t, "build-publish", tests.RtBuildName1, buildNumberA) runRt(t, "build-publish", tests.RtBuildName1, buildNumberB) - // Copy by build number: using override of build by flag from inline (no number set so LATEST build should be copied), a* should be copied + // Copy by build number: using override of build by flag from inline (no number set so the LATEST build should be copied), a* should be copied runRt(t, "copy", "--build="+tests.RtBuildName1, "--spec="+specFile) // Validate files are Copied by build number @@ -4445,7 +4445,7 @@ func TestArtifactoryDeleteExcludeProps(t *testing.T) { searchCmd.SetSpec(searchSpecBuilder.BuildSpec()) reader, err := searchCmd.Search() assert.NoError(t, err) - resultItems := []utils.SearchResult{} + var resultItems []utils.SearchResult readerNoDate, err := utils.SearchResultNoDate(reader) assert.NoError(t, err) for resultItem := new(utils.SearchResult); readerNoDate.NextRecord(resultItem) == nil; resultItem = new(utils.SearchResult) { @@ -4838,10 +4838,10 @@ func testCopyMoveNoSpec(command string, beforeCommandExpected, afterCommandExpec func searchItemsInArtifactory(t *testing.T, specSource string) []rtutils.ResultItem { fileSpec, err := tests.CreateSpec(specSource) assert.NoError(t, err) - spec, flags := getSpecAndCommonFlags(fileSpec) + searchSpec, flags := getSpecAndCommonFlags(fileSpec) var resultItems []rtutils.ResultItem - for i := 0; i < len(spec.Files); i++ { - searchParams, err := utils.GetSearchParams(spec.Get(i)) + for i := 0; i < len(searchSpec.Files); i++ { + searchParams, err := utils.GetSearchParams(searchSpec.Get(i)) assert.NoError(t, err, "Failed Searching files") reader, err := services.SearchBySpecFiles(searchParams, flags, rtutils.ALL) assert.NoError(t, err, "Failed Searching files") @@ -5337,9 +5337,9 @@ func TestPermissionTargets(t *testing.T) { assertPermissionTarget(t, servicesManager, tests.RtRepo1) // Update permission target to ANY repo. - any := "ANY" - runRt(t, "ptu", templatePath, createPermissionTargetsTemplateVars(any)) - assertPermissionTarget(t, servicesManager, any) + anyRepo := "ANY" + runRt(t, "ptu", templatePath, createPermissionTargetsTemplateVars(anyRepo)) + assertPermissionTarget(t, servicesManager, anyRepo) // Delete permission target. runRt(t, "ptdel", tests.RtPermissionTargetName) @@ -5486,6 +5486,14 @@ func validateBuildYamlFile(t *testing.T, projectDir string) { } func TestTerraformPublish(t *testing.T) { + testTerraformPublish(t, false) +} + +func TestTerraformPublishWithBuildInfo(t *testing.T) { + testTerraformPublish(t, true) +} + +func testTerraformPublish(t *testing.T, buildInfo bool) { initArtifactoryTest(t, terraformMinArtifactoryVersion) defer cleanArtifactoryTest() createJfrogHomeConfig(t, true) @@ -5495,12 +5503,13 @@ func TestTerraformPublish(t *testing.T) { assert.NoError(t, err) chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, filepath.Join(projectPath, "aws")) defer chdirCallback() - artifactoryCli.SetPrefix("jf") - // Terraform publish - err = artifactoryCli.Exec("terraform", "publish", "--namespace=namespace", "--provider=provider", "--tag=tag", "--exclusions=*test*") - assert.NoError(t, err) - artifactoryCli.SetPrefix("jf rt") + trPublishArgs := []string{"terraform", "publish", "--namespace=namespace", "--provider=provider", "--tag=tag", "--exclusions=*test*"} + if !buildInfo { + assert.NoError(t, platformCli.Exec(trPublishArgs...)) + } else { + terraformPublishModulesAndBuildInfo(t, trPublishArgs) + } // Download modules to 'result' directory. chdirCallback() @@ -5509,6 +5518,27 @@ func TestTerraformPublish(t *testing.T) { verifyModuleInArtifactoryWithRetry(t) } +func terraformPublishModulesAndBuildInfo(t *testing.T, trPublishArgs []string) { + buildNumber := "42" + trPublishArgs = append(trPublishArgs, []string{"--build-name=" + tests.RtBuildName1, "--build-number=" + buildNumber}...) + assert.NoError(t, platformCli.Exec(trPublishArgs...)) + + assert.NoError(t, artifactoryCli.Exec("bp", tests.RtBuildName1, buildNumber)) + + publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.RtBuildName1, buildNumber) + if !assert.NoError(t, err) { + return + } + if !assert.True(t, found, "build info was expected to be found") { + return + } + buildInfo := publishedBuildInfo.BuildInfo + if !assert.Len(t, buildInfo.Modules, 1) { + return + } + assert.Len(t, buildInfo.Modules[0].Artifacts, 3) +} + func prepareTerraformProject(projectName string, t *testing.T, copyDirs bool) string { projectPath := filepath.Join(tests.GetTestResourcesPath(), "terraform", projectName) testdataTarget := filepath.Join(tests.Out, "terraformProject") diff --git a/go.mod b/go.mod index 33e5f9558..378943776 100644 --- a/go.mod +++ b/go.mod @@ -123,10 +123,10 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.5-0.20230102085833-456b7aea6098 +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.5-0.20230103131235-4993ad739dc6 replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.24.6-0.20230102092554-c56fc329c8fc -replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230102142458-a479005d4980 +replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230103131355-15bc81e82c09 // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.5-0.20221107113836-a4c9225c690e diff --git a/go.sum b/go.sum index f57245633..276a41420 100644 --- a/go.sum +++ b/go.sum @@ -524,12 +524,12 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i github.com/jedib0t/go-pretty/v6 v6.4.3 h1:2n9BZ0YQiXGESUSR+6FLg0WWWE80u+mIz35f0uHWcIE= github.com/jedib0t/go-pretty/v6 v6.4.3/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= -github.com/jfrog/build-info-go v1.8.5-0.20230102085833-456b7aea6098 h1:ESa8yV/3MrmHHKcO/wmZ0nk2SzLy9+DsB8hlsiVG2Fk= -github.com/jfrog/build-info-go v1.8.5-0.20230102085833-456b7aea6098/go.mod h1:iSTj26qEX3eUtyAGMH0qKsW4WJT+MceYxLWP9FfiAq4= +github.com/jfrog/build-info-go v1.8.5-0.20230103131235-4993ad739dc6 h1:4WeDAwB+tuHQY9Qow9kKe7J15zlrUHECpVs+gFHHJBs= +github.com/jfrog/build-info-go v1.8.5-0.20230103131235-4993ad739dc6/go.mod h1:iSTj26qEX3eUtyAGMH0qKsW4WJT+MceYxLWP9FfiAq4= github.com/jfrog/gofrog v1.2.5 h1:jCgJC0iGQ8bU7jCC+YEFJTNINyngApIrhd8BjZAVRIE= github.com/jfrog/gofrog v1.2.5/go.mod h1:o00tSRff6IapTgaCMuX1Cs9MH08Y1JqnsKgRtx91Gc4= -github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230102142458-a479005d4980 h1:ZzJ7g6gw9lMQUtS2O4eb6D50wwLxj3y/RIt6Gl2qMMY= -github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230102142458-a479005d4980/go.mod h1:pYbHZQZRKXOeCC7lBYzoM0H4fukOhqDMN7+9eTgi6WU= +github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230103131355-15bc81e82c09 h1:elN/3gOcYv1PxR+4cF9+Rmyta2Ip8o4pemqqJcghsEQ= +github.com/jfrog/jfrog-cli-core/v2 v2.26.1-0.20230103131355-15bc81e82c09/go.mod h1:pWMbG6ZMvfjIYKvKEH6C/dEhKiu1A2UeSY/XgsFaZJY= github.com/jfrog/jfrog-client-go v1.24.6-0.20230102092554-c56fc329c8fc h1:EVp7jh405HHaor48wNVslSAi62uCdJPgPU1Cm391s3A= github.com/jfrog/jfrog-client-go v1.24.6-0.20230102092554-c56fc329c8fc/go.mod h1:x+f2g5yp5n9utUEXW//vdJC07h5q4Nq7NOVlyo83F/c= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=