Skip to content

Commit a9d17c4

Browse files
authored
E2e tests rt vsc containers (#3586)
1 parent 744d944 commit a9d17c4

8 files changed

Lines changed: 255 additions & 3 deletions

File tree

artifactory_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6922,6 +6922,51 @@ func terraformPublishModulesAndBuildInfo(t *testing.T, trPublishArgs []string) {
69226922
assert.Len(t, buildInfo.Modules[0].Artifacts, 3)
69236923
}
69246924

6925+
func TestTerraformPublishWithLocalGitVcsProps(t *testing.T) {
6926+
initArtifactoryTest(t, terraformMinArtifactoryVersion)
6927+
defer cleanArtifactoryTest()
6928+
createJfrogHomeConfig(t, true)
6929+
6930+
buildNumber := "local-git-1"
6931+
buildName := tests.RtBuildName1 + "-local-git"
6932+
6933+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
6934+
defer cleanupEnv()
6935+
6936+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
6937+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
6938+
6939+
projectPath := prepareTerraformProject("terraformproject", t, true)
6940+
tests.CopyGitFixtureIntoProject(t, projectPath)
6941+
6942+
wd, err := os.Getwd()
6943+
require.NoError(t, err)
6944+
awsDir := filepath.Join(projectPath, "aws")
6945+
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, awsDir)
6946+
defer chdirCallback()
6947+
6948+
trPublishArgs := []string{
6949+
"terraform", "publish",
6950+
"--namespace=namespace", "--provider=provider", "--tag=tag",
6951+
"--exclusions=*test*",
6952+
"--build-name=" + buildName, "--build-number=" + buildNumber,
6953+
"--module=my-tr-module-local-git",
6954+
}
6955+
require.NoError(t, platformCli.WithoutCredentials().Exec(trPublishArgs...))
6956+
require.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber))
6957+
6958+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
6959+
require.NoError(t, err)
6960+
require.True(t, found)
6961+
6962+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
6963+
require.NoError(t, err)
6964+
6965+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.TerraformRepo,
6966+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
6967+
assert.Greater(t, count, 0)
6968+
}
6969+
69256970
func prepareTerraformProject(projectName string, t *testing.T, copyDirs bool) string {
69266971
projectPath := filepath.Join(tests.GetTestResourcesPath(), "terraform", projectName)
69276972
testdataTarget := filepath.Join(tests.Out, "terraformProject")

docker_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,55 @@ CMD ["echo", "Hello from CI VCS test"]`, baseImage)
15741574
assert.Greater(t, artifactCount, 0, "No artifacts in build info")
15751575
}
15761576

1577+
// TestDockerPushWithLocalGitVcsProps verifies local git VCS props on Docker artifacts
1578+
// when running build-publish with VCS collection enabled and no CI env.
1579+
func TestDockerPushWithLocalGitVcsProps(t *testing.T) {
1580+
cleanup := initDockerBuildTest(t)
1581+
defer cleanup()
1582+
1583+
buildName := "docker-local-git-test"
1584+
buildNumber := "1"
1585+
1586+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
1587+
defer cleanupEnv()
1588+
1589+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
1590+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
1591+
1592+
registryHost := *tests.ContainerRegistry
1593+
if parsedURL, err := url.Parse(registryHost); err == nil && parsedURL.Host != "" {
1594+
registryHost = parsedURL.Host
1595+
}
1596+
imageName := path.Join(registryHost, tests.OciLocalRepo, "test-local-git-docker")
1597+
imageTag := imageName + ":v1"
1598+
1599+
workspace, err := filepath.Abs(tests.Out)
1600+
require.NoError(t, err)
1601+
require.NoError(t, fileutils.CreateDirIfNotExist(workspace))
1602+
tests.CopyGitFixtureIntoProject(t, workspace)
1603+
1604+
baseImage := path.Join(registryHost, tests.OciRemoteRepo, "alpine:latest")
1605+
dockerfileContent := fmt.Sprintf("FROM %s\nCMD [\"echo\", \"local git vcs test\"]", baseImage)
1606+
dockerfilePath := filepath.Join(workspace, "Dockerfile")
1607+
require.NoError(t, os.WriteFile(dockerfilePath, []byte(dockerfileContent), 0o644)) //#nosec G703 -- test code, path built from test workspace
1608+
1609+
runJfrogCli(t, "rt", "bc", buildName, buildNumber)
1610+
runJfrogCli(t, "docker", "build", "-t", imageTag, "--push", "-f", dockerfilePath,
1611+
"--build-name="+buildName, "--build-number="+buildNumber, workspace)
1612+
runRt(t, "build-publish", buildName, buildNumber, "--dot-git-path", workspace)
1613+
1614+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
1615+
require.NoError(t, err)
1616+
require.True(t, found)
1617+
1618+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
1619+
require.NoError(t, err)
1620+
1621+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.OciLocalRepo,
1622+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
1623+
assert.Greater(t, count, 0)
1624+
}
1625+
15771626
// TestSetupDockerCommand verifies `jf setup docker --url ...` end-to-end.
15781627
//
15791628
// Guards RTECO-1352: configureContainer (in jfrog-cli-artifactory) used to read

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.20260702071632-62c27c48b207
24+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260707101914-5f6d052c3b99
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ 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=
7270
github.com/aws/aws-sdk-go-v2 v1.41.7 h1:DWpAJt66FmnnaRIOT/8ASTucrvuDPZASqhhLey6tLY8=
7371
github.com/aws/aws-sdk-go-v2 v1.41.7/go.mod h1:4LAfZOPHNVNQEckOACQx60Y8pSRjIkNZQz1w92xpMJc=
7472
github.com/aws/aws-sdk-go-v2/config v1.32.17 h1:FpL4/758/diKwqbytU0prpuiu60fgXKUWCpDJtApclU=
@@ -410,6 +408,8 @@ github.com/jfrog/jfrog-cli-application v1.0.2-0.20260621072921-cadb78770a3e h1:j
410408
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260621072921-cadb78770a3e/go.mod h1:p8yLtbmCxxQucIbLZKnWu0F+EDtj6NLXbRQCEK/nb6o=
411409
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260702071632-62c27c48b207 h1:RbqWYCj0Iw1IGO9gW7ghEHV8L2xnMjDUulDnNHOstVM=
412410
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260702071632-62c27c48b207/go.mod h1:VqV0Bed11HoBlugAEGa3RumbwnDVslEf0gKocTzLs9s=
411+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260707101914-5f6d052c3b99 h1:V9AtxtEshzsnMUn78mPhTzMqZUJx/2DF7ELnj+URzPM=
412+
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260707101914-5f6d052c3b99/go.mod h1:VqV0Bed11HoBlugAEGa3RumbwnDVslEf0gKocTzLs9s=
413413
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260624085155-5ba797de2616 h1:bioFXGzf3pF2qnC3LZD1S1saWiHSekL4vdsDSWksj/4=
414414
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260624085155-5ba797de2616/go.mod h1:9R90mhbczGXwW5EGlDs7F08ejQU/xdoDhYHMvzBiqgE=
415415
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260618135203-4d2bdd4ee35f h1:MV4BATdkEoUYJmdPDvaB9EBb8JQZg28n/K4X7dcmyAY=

helm_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,99 @@ func TestHelmBuildPublishWithCIVcsProps(t *testing.T) {
958958
assert.Greater(t, artifactCount, 0, "No artifacts were validated for CI VCS properties")
959959
}
960960

961+
// TestHelmPushWithLocalGitVcsProps verifies local git VCS props on Helm artifacts
962+
// when running build-publish with VCS collection enabled and no CI env.
963+
func TestHelmPushWithLocalGitVcsProps(t *testing.T) {
964+
initHelmTest(t)
965+
defer cleanHelmTest(t)
966+
967+
buildName := tests.HelmBuildName + "-local-git"
968+
buildNumber := "1"
969+
970+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
971+
defer cleanupEnv()
972+
973+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
974+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
975+
976+
chartDir := createTestHelmChartWithDependencies(t, "test-chart-local-git", "0.2.0")
977+
defer func() {
978+
if err := os.RemoveAll(chartDir); err != nil {
979+
t.Logf("Warning: Failed to remove test chart directory %s: %v", chartDir, err)
980+
}
981+
}()
982+
tests.CopyGitFixtureIntoProject(t, chartDir)
983+
984+
originalDir, err := os.Getwd()
985+
require.NoError(t, err)
986+
defer func() {
987+
if err := os.Chdir(originalDir); err != nil {
988+
t.Logf("Warning: Failed to change back to original directory: %v", err)
989+
}
990+
}()
991+
require.NoError(t, os.Chdir(chartDir))
992+
993+
helmCmd := exec.Command("helm", "dependency", "update")
994+
helmCmd.Dir = chartDir
995+
require.NoError(t, helmCmd.Run(), "helm dependency update should succeed")
996+
997+
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
998+
require.NoError(t, jfrogCli.Exec("helm", "package", ".",
999+
"--build-name="+buildName, "--build-number="+buildNumber), "helm package should succeed")
1000+
1001+
chartFiles, err := filepath.Glob(filepath.Join(chartDir, "*.tgz"))
1002+
require.NoError(t, err)
1003+
require.NotEmpty(t, chartFiles, "Chart package file should be created")
1004+
chartFile := filepath.Base(chartFiles[0])
1005+
1006+
parsedURL, err := url.Parse(serverDetails.ArtifactoryUrl)
1007+
require.NoError(t, err)
1008+
registryHost := parsedURL.Host
1009+
registryURL := fmt.Sprintf("oci://%s/%s", registryHost, tests.HelmLocalRepo)
1010+
1011+
if !isRepoExist(tests.HelmLocalRepo) {
1012+
t.Skipf("Repository %s does not exist. Skipping test.", tests.HelmLocalRepo)
1013+
}
1014+
1015+
err = loginHelmRegistry(t, registryHost)
1016+
if err != nil {
1017+
errorMsg := strings.ToLower(err.Error())
1018+
if strings.Contains(errorMsg, "account temporarily locked") {
1019+
t.Skip("Artifactory account is temporarily locked. Skipping test.")
1020+
}
1021+
if strings.Contains(errorMsg, "http response to https") ||
1022+
strings.Contains(errorMsg, "tls: first record does not look like a tls handshake") {
1023+
t.Skip("Helm registry login failed due to HTTPS/HTTP mismatch. Skipping test.")
1024+
}
1025+
}
1026+
require.NoError(t, err, "helm registry login should succeed")
1027+
1028+
err = jfrogCli.Exec("helm", "push", chartFile, registryURL,
1029+
"--build-name="+buildName, "--build-number="+buildNumber)
1030+
if err != nil {
1031+
errorMsg := strings.ToLower(err.Error())
1032+
if strings.Contains(errorMsg, "404") ||
1033+
strings.Contains(errorMsg, "not found") ||
1034+
strings.Contains(errorMsg, "exit status 1") {
1035+
t.Skip("OCI registry API not accessible (404). Skipping test.")
1036+
}
1037+
}
1038+
require.NoError(t, err, "helm push should succeed")
1039+
1040+
require.NoError(t, artifactoryCli.Exec("bp", buildName, buildNumber))
1041+
1042+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
1043+
require.NoError(t, err)
1044+
require.True(t, found)
1045+
1046+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
1047+
require.NoError(t, err)
1048+
1049+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.HelmLocalRepo,
1050+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
1051+
assert.Greater(t, count, 0)
1052+
}
1053+
9611054
// InitHelmTests initializes Helm tests
9621055
func InitHelmTests() {
9631056
initArtifactoryCli()

huggingface_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
"strings"
1111
"testing"
1212

13+
"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
1314
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
1415
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
1516
coreTests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
17+
"github.com/jfrog/jfrog-cli/inttestutils"
1618
"github.com/jfrog/jfrog-cli/utils/tests"
1719
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
1820
"github.com/stretchr/testify/assert"
@@ -867,6 +869,53 @@ func InitHuggingFaceTests() {
867869
createRequiredRepos()
868870
}
869871

872+
func TestHuggingFaceUploadWithLocalGitVcsProps(t *testing.T) {
873+
initHuggingFaceTest(t)
874+
defer cleanHuggingFaceTest(t)
875+
checkHuggingFaceHubAvailable(t)
876+
877+
buildName := tests.HuggingFaceBuildName + "-local-git"
878+
buildNumber := "1"
879+
880+
cleanupEnv := tests.SetupLocalGitVcsEnv(t)
881+
defer cleanupEnv()
882+
883+
inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
884+
defer inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, buildName, artHttpDetails)
885+
886+
tempDir, err := os.MkdirTemp("", "hf-local-git-*")
887+
require.NoError(t, err)
888+
t.Cleanup(func() { _ = os.RemoveAll(tempDir) })
889+
tests.CopyGitFixtureIntoProject(t, tempDir)
890+
891+
require.NoError(t, os.WriteFile(filepath.Join(tempDir, "config.json"),
892+
[]byte(`{"model_type": "local-git-vcs"}`), 0o644))
893+
require.NoError(t, os.WriteFile(filepath.Join(tempDir, "model.bin"),
894+
[]byte("model"), 0o644))
895+
896+
jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
897+
args := []string{
898+
"hf", "u", tempDir, "test-org/test-local-git-model",
899+
"--repo-type=model",
900+
"--build-name=" + buildName,
901+
"--build-number=" + buildNumber,
902+
"--repo-key=" + tests.HuggingFaceLocalRepo,
903+
}
904+
require.NoError(t, jfrogCli.Exec(args...))
905+
require.NoError(t, jfrogCli.Exec("rt", "bp", buildName, buildNumber, "--dot-git-path", tempDir))
906+
907+
publishedBuildInfo, found, err := tests.GetBuildInfo(serverDetails, buildName, buildNumber)
908+
require.NoError(t, err)
909+
require.True(t, found)
910+
911+
serviceManager, err := utils.CreateServiceManager(serverDetails, 3, 1000, false)
912+
require.NoError(t, err)
913+
914+
count := tests.ValidateLocalGitVcsPropsOnBuildInfoArtifacts(t, serviceManager, publishedBuildInfo, tests.HuggingFaceLocalRepo,
915+
tests.VcsFixtureMainURL, tests.VcsFixtureMainRevision, tests.VcsFixtureMainBranch)
916+
assert.Greater(t, count, 0)
917+
}
918+
870919
// CleanHuggingFaceTests cleans up after HuggingFace tests
871920
func CleanHuggingFaceTests() {
872921
deleteCreatedRepos()

utils/tests/artifact_props.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ func ArtifactFullPath(a buildinfo.Artifact, defaultRepo string) string {
2020
if repo == "" {
2121
repo = defaultRepo
2222
}
23+
if path == "" {
24+
if repo != "" {
25+
return repo
26+
}
27+
return ""
28+
}
2329
if repo != "" {
2430
return repo + "/" + path
2531
}

utils/tests/artifact_props_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ func TestArtifactItemPath_DoesNotDoubleAppendName(t *testing.T) {
5656
assert.Equal(t, "mvn-local/com/foo/1.0/foo.jar", ArtifactItemPath(a, ""))
5757
}
5858

59+
func TestArtifactFullPath_EmptyPathReturnsRepoOnly(t *testing.T) {
60+
a := buildinfo.Artifact{Path: "", Name: "config.json"}
61+
assert.Equal(t, "my-repo", ArtifactFullPath(a, "my-repo"))
62+
}
63+
64+
func TestArtifactItemPath_EmptyPathDoesNotDoubleSlash(t *testing.T) {
65+
a := buildinfo.Artifact{Path: "", Name: "config.json"}
66+
assert.Equal(t, "my-repo/config.json", ArtifactItemPath(a, "my-repo"))
67+
}
68+
5969
func TestArtifactItemPath_NpmTarballPathDoesNotAppendName(t *testing.T) {
6070
a := buildinfo.Artifact{
6171
OriginalDeploymentRepo: "cli-npm-123",

0 commit comments

Comments
 (0)