Skip to content

Commit e187bbf

Browse files
authored
E2e tests rt vsc more tools (#3585)
1 parent d0062cd commit e187bbf

13 files changed

Lines changed: 562 additions & 20 deletions

conan_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"strconv"
10+
"strings"
1011
"testing"
1112

1213
buildinfo "github.com/jfrog/build-info-go/entities"
@@ -1162,3 +1163,54 @@ func TestConanBuildPublishWithCIVcsProps(t *testing.T) {
11621163

11631164
assert.Greater(t, artifactCount, 0, "No artifacts were validated for CI VCS properties")
11641165
}
1166+
1167+
// TestConanUploadWithLocalGitVcsProps verifies civcs local git fallback on conan upload.
1168+
func TestConanUploadWithLocalGitVcsProps(t *testing.T) {
1169+
initConanTest(t)
1170+
1171+
buildName := tests.ConanBuildName + "-local-git"
1172+
buildNumber := "1"
1173+
1174+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
1175+
defer cleanupEnv()
1176+
1177+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
1178+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
1179+
1180+
projectPath := createConanProject(t, "conan-local-git")
1181+
tests.CopyGitFixtureIntoProject(t, projectPath)
1182+
1183+
conanfile := filepath.Join(projectPath, "conanfile.py")
1184+
data, err := os.ReadFile(conanfile)
1185+
require.NoError(t, err)
1186+
patched := strings.ReplaceAll(string(data), `name = "cli-test-package"`, `name = "cli-test-package-local-git"`)
1187+
require.NoError(t, os.WriteFile(conanfile, []byte(patched), 0o644)) //#nosec G703 -- test code, path built from createConanProject temp dir
1188+
1189+
wd, err := os.Getwd()
1190+
require.NoError(t, err)
1191+
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, projectPath)
1192+
defer chdirCallback()
1193+
1194+
configureConanRemote(t)
1195+
defer cleanupConanRemote()
1196+
1197+
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
1198+
require.NoError(t, jfrogCli.Exec("conan", "create", ".", "--build=missing",
1199+
"--build-name="+buildName, "--build-number="+buildNumber))
1200+
require.NoError(t, jfrogCli.Exec("conan", "upload", "cli-test-package-local-git/*",
1201+
"-r", tests.ConanLocalRepo, "--confirm",
1202+
"--build-name="+buildName, "--build-number="+buildNumber))
1203+
1204+
require.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber))
1205+
1206+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
1207+
require.NoError(t, err)
1208+
require.True(t, found)
1209+
1210+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
1211+
require.NoError(t, err)
1212+
1213+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.ConanLocalRepo,
1214+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
1215+
assert.Greater(t, count, 0)
1216+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/jfrog/build-info-go v1.13.1-0.20260615080618-42488b58c305
2222
github.com/jfrog/gofrog v1.7.6
2323
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260621072921-cadb78770a3e
24-
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260701085637-6ba50cd3676f
24+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260702071632-62c27c48b207
2525
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260624085155-5ba797de2616
2626
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260618135203-4d2bdd4ee35f
2727
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20260618062042-6053ab368cab

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
6767
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
6868
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
6969
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
70+
github.com/attiasas/jfrog-cli-artifactory v0.0.0-20260701102442-59ed24167b6c h1:oyOqDGLhx7Mqf3zr0K/TkCyAM/kBtMvW/yjdoujTWGs=
71+
github.com/attiasas/jfrog-cli-artifactory v0.0.0-20260701102442-59ed24167b6c/go.mod h1:VqV0Bed11HoBlugAEGa3RumbwnDVslEf0gKocTzLs9s=
7072
github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8=
7173
github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc=
7274
github.com/aws/aws-sdk-go-v2/config v1.32.17 h1:FpL4/758/diKwqbytU0prpuiu60fgXKUWCpDJtApclU=
@@ -406,8 +408,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
406408
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
407409
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260621072921-cadb78770a3e h1:jUfQzLCVbUazw7FEXf3+57vQheDSHa/Px/Gp4pf/sNI=
408410
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260621072921-cadb78770a3e/go.mod h1:p8yLtbmCxxQucIbLZKnWu0F+EDtj6NLXbRQCEK/nb6o=
409-
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260701085637-6ba50cd3676f h1:PMq0iTjH/H40BEL/RzBwXFt7JMb+CQBaVmScdbZaeRI=
410-
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260701085637-6ba50cd3676f/go.mod h1:VqV0Bed11HoBlugAEGa3RumbwnDVslEf0gKocTzLs9s=
411+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260702071632-62c27c48b207 h1:RbqWYCj0Iw1IGO9gW7ghEHV8L2xnMjDUulDnNHOstVM=
412+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260702071632-62c27c48b207/go.mod h1:VqV0Bed11HoBlugAEGa3RumbwnDVslEf0gKocTzLs9s=
411413
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260624085155-5ba797de2616 h1:bioFXGzf3pF2qnC3LZD1S1saWiHSekL4vdsDSWksj/4=
412414
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260624085155-5ba797de2616/go.mod h1:9R90mhbczGXwW5EGlDs7F08ejQU/xdoDhYHMvzBiqgE=
413415
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260618135203-4d2bdd4ee35f h1:MV4BATdkEoUYJmdPDvaB9EBb8JQZg28n/K4X7dcmyAY=

go_test.go

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,23 +469,20 @@ func TestGoBuildPublishWithCIVcsProps(t *testing.T) {
469469
assert.NoError(t, err)
470470

471471
// Verify VCS properties on each artifact from build info
472-
// Use same fallback logic as CI VCS: OriginalDeploymentRepo + Path, or Path directly
473472
artifactCount := 0
474473
for _, module := range publishedBuildInfo.BuildInfo.Modules {
475474
for _, artifact := range module.Artifacts {
476-
var fullPath string
477-
switch {
478-
case artifact.OriginalDeploymentRepo != "":
479-
fullPath = artifact.OriginalDeploymentRepo + "/" + artifact.Path
480-
case artifact.Path != "":
481-
fullPath = artifact.Path
482-
default:
483-
continue // Skip artifacts without any path info
475+
fullPath := tests.ArtifactFullPath(artifact, tests.GoRepo)
476+
if fullPath == "" {
477+
continue
484478
}
485479

486480
props, err := serviceManager.GetItemProps(fullPath)
487481
assert.NoError(t, err, "Failed to get properties for artifact: %s", fullPath)
488482
assert.NotNil(t, props, "Properties are nil for artifact: %s", fullPath)
483+
if props == nil {
484+
continue
485+
}
489486

490487
// Validate VCS properties
491488
assert.Contains(t, props.Properties, "vcs.provider", "Missing vcs.provider on %s", artifact.Name)
@@ -503,3 +500,57 @@ func TestGoBuildPublishWithCIVcsProps(t *testing.T) {
503500

504501
assert.Greater(t, artifactCount, 0, "No artifacts were validated for CI VCS properties")
505502
}
503+
504+
// TestGoPublishWithLocalGitVcsProps tests that local git VCS properties are set on Go artifacts
505+
// when running go-publish followed by build-publish with VCS collection enabled and no CI env.
506+
func TestGoPublishWithLocalGitVcsProps(t *testing.T) {
507+
_, cleanUpFunc := initGoTest(t)
508+
defer cleanUpFunc()
509+
510+
buildName := tests.GoBuildName + "-local-git"
511+
buildNumber := "1"
512+
513+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
514+
defer cleanupEnv()
515+
516+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
517+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
518+
519+
wd, err := os.Getwd()
520+
assert.NoError(t, err, "Failed to get current dir")
521+
522+
projectPath := createGoProject(t, "project1", true)
523+
testdataTarget := filepath.Join(tests.Out, "testdata")
524+
testdataSrc := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", "testdata")
525+
require.NoError(t, biutils.CopyDir(testdataSrc, testdataTarget, true, nil))
526+
configFileDir := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "go", "project1", ".jfrog", "projects")
527+
_, err = tests.ReplaceTemplateVariables(filepath.Join(configFileDir, "go.yaml"), filepath.Join(projectPath, ".jfrog", "projects"))
528+
require.NoError(t, err)
529+
530+
tests.CopyGitFixtureIntoProject(t, projectPath)
531+
require.FileExists(t, filepath.Join(projectPath, ".git", "HEAD"))
532+
clientTestUtils.ChangeDirAndAssert(t, projectPath)
533+
defer clientTestUtils.ChangeDirAndAssert(t, wd)
534+
log.Info("Using Go project located at", projectPath)
535+
536+
jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "")
537+
err = execGo(jfrogCli, "go", "build", "--mod=mod", "--build-name="+buildName, "--build-number="+buildNumber)
538+
assert.NoError(t, err)
539+
540+
err = execGo(jfrogCli, "gp", "--build-name="+buildName, "--build-number="+buildNumber, "v1.0.0")
541+
assert.NoError(t, err)
542+
543+
err = execGo(artifactoryCli, "bp", buildName, buildNumber)
544+
assert.NoError(t, err)
545+
546+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
547+
assert.NoError(t, err)
548+
assert.True(t, found, "Build info was not found")
549+
550+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
551+
assert.NoError(t, err)
552+
553+
artifactCount := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo,
554+
tests.GoRepo, tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
555+
assert.Greater(t, artifactCount, 0)
556+
}

gradle_test.go

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,14 @@ func TestGradleBuildPublishWithCIVcsProps(t *testing.T) {
707707
artifactCount := 0
708708
for _, module := range publishedBuildInfo.BuildInfo.Modules {
709709
for _, artifact := range module.Artifacts {
710-
fullPath := artifact.OriginalDeploymentRepo + "/" + artifact.Path
710+
fullPath := tests.ArtifactFullPath(artifact, tests.GradleRepo)
711711

712712
props, err := serviceManager.GetItemProps(fullPath)
713713
assert.NoError(t, err, "Failed to get properties for artifact: %s", fullPath)
714714
assert.NotNil(t, props, "Properties are nil for artifact: %s", fullPath)
715+
if props == nil {
716+
continue
717+
}
715718

716719
// Validate VCS properties
717720
assert.Contains(t, props.Properties, "vcs.provider", "Missing vcs.provider on %s", artifact.Name)
@@ -730,3 +733,104 @@ func TestGradleBuildPublishWithCIVcsProps(t *testing.T) {
730733

731734
cleanGradleTest(t)
732735
}
736+
737+
// TestGradleBuildPublishWithLocalGitVcsProps tests that local git VCS properties are set on Gradle artifacts
738+
// when running build-publish with VCS collection enabled and no CI env.
739+
// Uses the traditional Gradle extractor path (not FlexPack) because SetCIVcsPropsToConfig
740+
// injects local git props into the extractor config; FlexPack only sets build.* props on publish.
741+
func TestGradleBuildPublishWithLocalGitVcsProps(t *testing.T) {
742+
initGradleTest(t)
743+
buildName := "gradle-local-git-test"
744+
buildNumber := "1"
745+
746+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
747+
defer cleanupEnv()
748+
749+
_ = os.Unsetenv("JFROG_RUN_NATIVE")
750+
751+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
752+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
753+
754+
buildGradlePath := createGradleProject(t, "gradleproject")
755+
projectDir := filepath.Dir(buildGradlePath)
756+
tests.CopyGitFixtureIntoProject(t, projectDir)
757+
require.FileExists(t, filepath.Join(projectDir, ".git", "HEAD"))
758+
759+
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.GradleConfig)
760+
createConfigFile(filepath.Join(projectDir, ".jfrog", "projects"), configFilePath, t)
761+
762+
oldHomeDir := changeWD(t, projectDir)
763+
defer clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
764+
765+
buildGradlePath = strings.ReplaceAll(buildGradlePath, `\`, "/")
766+
runJfrogCli(t, "gradle", "clean", "artifactoryPublish", "-b"+buildGradlePath, "--build-name="+buildName, "--build-number="+buildNumber)
767+
768+
assert.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber))
769+
770+
clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
771+
772+
var publishedBuildInfo *buildinfo.PublishedBuildInfo
773+
var found bool
774+
assert.Eventuallyf(t, func() bool {
775+
var biErr error
776+
publishedBuildInfo, found, biErr = tests.GetBuildInfo(serverDetails, buildName, buildNumber)
777+
return biErr == nil && found
778+
}, 30*time.Second, 2*time.Second, "Build info was not found for %s/%s", buildName, buildNumber)
779+
if !found || publishedBuildInfo == nil {
780+
return
781+
}
782+
783+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
784+
assert.NoError(t, err)
785+
786+
artifactCount := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo,
787+
tests.GradleRepo, tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
788+
assert.Greater(t, artifactCount, 0)
789+
790+
cleanGradleTest(t)
791+
}
792+
793+
// TestGradleFlexPackPublishWithLocalGitVcsProps verifies local git VCS on FlexPack publish path.
794+
func TestGradleFlexPackPublishWithLocalGitVcsProps(t *testing.T) {
795+
initGradleTest(t)
796+
buildName := "gradle-flexpack-local-git"
797+
buildNumber := "1"
798+
799+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
800+
defer cleanupEnv()
801+
802+
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, "JFROG_RUN_NATIVE", "true")
803+
defer setEnvCallBack()
804+
805+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
806+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
807+
808+
buildGradlePath := createGradleProject(t, "civcsproject")
809+
projectDir := filepath.Dir(buildGradlePath)
810+
tests.CopyGitFixtureIntoProject(t, projectDir)
811+
812+
oldHomeDir := changeWD(t, projectDir)
813+
defer clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
814+
815+
runJfrogCli(t, "gradle", "clean", "publish", "--build-name="+buildName, "--build-number="+buildNumber)
816+
require.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber))
817+
818+
clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
819+
820+
var publishedBuildInfo *buildinfo.PublishedBuildInfo
821+
var found bool
822+
require.Eventually(t, func() bool {
823+
var biErr error
824+
publishedBuildInfo, found, biErr = tests.GetBuildInfo(serverDetails, buildName, buildNumber)
825+
return biErr == nil && found
826+
}, 30*time.Second, 2*time.Second)
827+
828+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
829+
require.NoError(t, err)
830+
831+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.GradleRepo,
832+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
833+
assert.Greater(t, count, 0)
834+
835+
cleanGradleTest(t)
836+
}

maven_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,3 +839,50 @@ func TestMavenBuildPublishWithCIVcsProps(t *testing.T) {
839839

840840
cleanMavenTest(t)
841841
}
842+
843+
// TestMavenBuildPublishWithLocalGitVcsProps verifies local git VCS props on Maven artifacts
844+
// when running build-publish with VCS collection enabled and no CI env.
845+
func TestMavenBuildPublishWithLocalGitVcsProps(t *testing.T) {
846+
initMavenTest(t, false)
847+
buildName := tests.MvnBuildName + "-local-git"
848+
buildNumber := "1"
849+
850+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
851+
defer cleanupEnv()
852+
853+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
854+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
855+
856+
pomDir := createSimpleMavenProject(t)
857+
tests.CopyGitFixtureIntoProject(t, pomDir)
858+
require.FileExists(t, filepath.Join(pomDir, ".git", "HEAD"))
859+
860+
configFilePath := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "buildspecs", tests.MavenConfig)
861+
destPath := filepath.Join(pomDir, ".jfrog", "projects")
862+
createConfigFile(destPath, configFilePath, t)
863+
require.NoError(t, os.Rename(filepath.Join(destPath, tests.MavenConfig), filepath.Join(destPath, "maven.yaml")))
864+
865+
oldHomeDir := changeWD(t, pomDir)
866+
defer clientTestUtils.ChangeDirAndAssert(t, oldHomeDir)
867+
868+
repoLocalSystemProp := localRepoSystemProperty + localRepoDir
869+
args := []string{"mvn", "clean", "install", "-B", repoLocalSystemProp,
870+
"--build-name=" + buildName, "--build-number=" + buildNumber}
871+
require.NoError(t, runJfrogCliWithoutAssertion(args...))
872+
873+
// Must run build-publish from project dir so GetLocalGitVcsInfo finds the fixture .git
874+
runRt(t, "build-publish", buildName, buildNumber)
875+
876+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
877+
require.NoError(t, err)
878+
require.True(t, found, "Build info was not found")
879+
880+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
881+
require.NoError(t, err)
882+
883+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.MvnRepo1,
884+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
885+
assert.Greater(t, count, 0)
886+
887+
cleanMavenTest(t)
888+
}

0 commit comments

Comments
 (0)