Skip to content
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

Add terraform build info test #1792

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
68 changes: 49 additions & 19 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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/RobiNino/build-info-go v1.0.1-0.20230103105450-6e7b50ba7eae

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/RobiNino/jfrog-cli-core/v2 v2.0.0-20230103110405-fbbfbda41b72

// replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.5-0.20221107113836-a4c9225c690e
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/RobiNino/build-info-go v1.0.1-0.20230103105450-6e7b50ba7eae h1:UuS8seVv/gS566nmAkGZ4+rSnn8RMLxWJfjtXdj/fMw=
github.com/RobiNino/build-info-go v1.0.1-0.20230103105450-6e7b50ba7eae/go.mod h1:iSTj26qEX3eUtyAGMH0qKsW4WJT+MceYxLWP9FfiAq4=
github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20230103110405-fbbfbda41b72 h1:kQomillJDH4Q20elKw4hDJyqlz2E9dqEj7GYWmgVtlY=
github.com/RobiNino/jfrog-cli-core/v2 v2.0.0-20230103110405-fbbfbda41b72/go.mod h1:pBmNxTLAuPmJpiZKZh46b3w5Q/oRVIHhLa5zPD+f/VQ=
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
Expand Down Expand Up @@ -524,12 +528,8 @@ 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/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-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=
Expand Down