From d719d6bc7297a3a05916f31677a3ee819e939568 Mon Sep 17 00:00:00 2001 From: Assaf Attias <49212512+attiasas@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:46:50 +0200 Subject: [PATCH] Add tests for maven and gradle build timestamp (#2296) --- go.mod | 2 +- go.sum | 4 ++-- gradle_test.go | 2 +- maven_test.go | 22 +++++++++++++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index d8a67f1d1..7b6e7d6b3 100644 --- a/go.mod +++ b/go.mod @@ -129,7 +129,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231031143744-13f94ab07bbc +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231107094842-97a0ca9da395 replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20231105094115-13b1588fc537 diff --git a/go.sum b/go.sum index 4c109a921..dedcceb4d 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jedib0t/go-pretty/v6 v6.4.8 h1:HiNzyMSEpsBaduKhmK+CwcpulEeBrTmxutz4oX/oWkg= github.com/jedib0t/go-pretty/v6 v6.4.8/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs= -github.com/jfrog/build-info-go v1.8.9-0.20231031143744-13f94ab07bbc h1:MFejgCB90z7nA/KP48lF1t04tYuXAAQc53cBaFd9zcw= -github.com/jfrog/build-info-go v1.8.9-0.20231031143744-13f94ab07bbc/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg= +github.com/jfrog/build-info-go v1.8.9-0.20231107094842-97a0ca9da395 h1:ICEUzDzr66jxaEl59BLqEuMGKFixcC1+66W4KgkVvCo= +github.com/jfrog/build-info-go v1.8.9-0.20231107094842-97a0ca9da395/go.mod h1:ujJ8XQZMdT2tMkLSMJNyDd1pCY+duwHdjV+9or9FLIg= github.com/jfrog/gofrog v1.3.1 h1:QqAwQXCVReT724uga1AYqG/ZyrNQ6f+iTxmzkb+YFQk= github.com/jfrog/gofrog v1.3.1/go.mod h1:IFMc+V/yf7rA5WZ74CSbXe+Lgf0iApEQLxRZVzKRUR0= github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY= diff --git a/gradle_test.go b/gradle_test.go index 773521091..b629b096b 100644 --- a/gradle_test.go +++ b/gradle_test.go @@ -82,7 +82,7 @@ func TestGradleBuildWithServerID(t *testing.T) { searchSpec, err := tests.CreateSpec(tests.SearchAllGradle) assert.NoError(t, err) inttestutils.VerifyExistInArtifactory(tests.GetGradleDeployedArtifacts(), searchSpec, serverDetails, t) - verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+tests.GradleBuildName+";build.number="+buildNumber, t) + verifyExistInArtifactoryByProps(tests.GetGradleDeployedArtifacts(), tests.GradleRepo+"/*", "build.name="+tests.GradleBuildName+";build.number="+buildNumber+";build.timestamp="+getBuildTimestamp(tests.GradleBuildName, buildNumber, t), t) assert.NoError(t, artifactoryCli.Exec("bp", tests.GradleBuildName, buildNumber)) publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, tests.GradleBuildName, buildNumber) diff --git a/maven_test.go b/maven_test.go index 16311cb5c..d8c2cb783 100644 --- a/maven_test.go +++ b/maven_test.go @@ -2,6 +2,12 @@ package main import ( "fmt" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/jfrog/build-info-go/build" buildinfo "github.com/jfrog/build-info-go/entities" biutils "github.com/jfrog/build-info-go/utils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/mvn" @@ -17,10 +23,6 @@ import ( "github.com/jfrog/jfrog-client-go/utils/log" clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests" "github.com/stretchr/testify/assert" - "os" - "path/filepath" - "strings" - "testing" ) const mavenTestsProxyPort = "1028" @@ -200,6 +202,16 @@ func createHomeConfigAndLocalRepo(t *testing.T, encryptPassword bool) (err error return err } +// Get the build timestamp from the build info. +func getBuildTimestamp(buildName, buildNumber string, t *testing.T) string { + service := build.NewBuildInfoService() + bld, err := service.GetOrCreateBuild(buildName, buildNumber) + if assert.NoError(t, err) { + return fmt.Sprintf("%d", bld.GetBuildTimestamp().UnixMilli()) + } + return "" +} + func TestMavenBuildIncludePatterns(t *testing.T) { initMavenTest(t, false) buildNumber := "123" @@ -209,7 +221,7 @@ func TestMavenBuildIncludePatterns(t *testing.T) { searchSpec, err := tests.CreateSpec(tests.SearchAllMaven) assert.NoError(t, err) inttestutils.VerifyExistInArtifactory(tests.GetMavenMultiIncludedDeployedArtifacts(), searchSpec, serverDetails, t) - verifyExistInArtifactoryByProps(tests.GetMavenMultiIncludedDeployedArtifacts(), tests.MvnRepo1+"/*", "build.name="+tests.MvnBuildName+";build.number="+buildNumber, t) + verifyExistInArtifactoryByProps(tests.GetMavenMultiIncludedDeployedArtifacts(), tests.MvnRepo1+"/*", "build.name="+tests.MvnBuildName+";build.number="+buildNumber+";build.timestamp="+getBuildTimestamp(tests.MvnBuildName, buildNumber, t), t) // Validate build info. assert.NoError(t, artifactoryCli.Exec("build-publish", tests.MvnBuildName, buildNumber))