diff --git a/artifactory_test.go b/artifactory_test.go index 2049f3a9f..9ba575230 100644 --- a/artifactory_test.go +++ b/artifactory_test.go @@ -2920,6 +2920,89 @@ func TestArtifactoryIncludeDirFlatNonEmptyFolderUploadMatchingPattern(t *testing cleanArtifactoryTest() } +func TestArtifactoryUploadWithIncludeDirsAndDryRun(t *testing.T) { + initArtifactoryTest(t, "") + + // Use a unique subdirectory in the repo to avoid conflicts + uploadPath := "dry-run-test" + + // Create test directory structure with files and empty directories + dirInnerPath := filepath.Join("inner", "folder") + canonicalPath := tests.Out + fileutils.GetFileSeparator() + dirInnerPath + err := os.MkdirAll(canonicalPath, 0777) + assert.NoError(t, err) + + // Create a test file in the nested directory + testFile := filepath.Join(canonicalPath, "test.txt") + err = os.WriteFile(testFile, []byte("test content"), 0644) + assert.NoError(t, err) + + // Create an empty directory + emptyDirPath := tests.Out + fileutils.GetFileSeparator() + "empty" + err = os.MkdirAll(emptyDirPath, 0777) + assert.NoError(t, err) + + // Upload with include-dirs and dry-run - files should not be uploaded + runRt(t, "upload", tests.Out+"/", tests.RtRepo1+"/"+uploadPath+"/", "--recursive=true", "--include-dirs=true", "--flat=false", "--dry-run") + + // Search for files specifically (not directories) - dry-run should prevent file uploads + searchSpecBuilder := spec.NewBuilder(). + Pattern(tests.RtRepo1 + "/" + uploadPath + "/*"). + Recursive(true) + searchCmd := generic.NewSearchCommand() + searchCmd.SetServerDetails(serverDetails) + searchCmd.SetSpec(searchSpecBuilder.BuildSpec()) + reader, err := searchCmd.Search() + assert.NoError(t, err) + + var fileItems []utils.SearchResult + for resultItem := new(utils.SearchResult); reader.NextRecord(resultItem) == nil; resultItem = new(utils.SearchResult) { + // Only count files, not directories (directories have type "folder" and size 0) + if resultItem.Type != "folder" { + fileItems = append(fileItems, *resultItem) + } + } + readerGetErrorAndAssert(t, reader) + readerCloseAndAssert(t, reader) + + // Verify no files were uploaded with dry-run (directories might still be created) + assert.Empty(t, fileItems, "Files should not be uploaded with dry-run flag") + + // Now upload without dry-run - should upload files and directories + runRt(t, "upload", tests.Out+"/", tests.RtRepo1+"/"+uploadPath+"/", "--recursive=true", "--include-dirs=true", "--flat=false") + + // Verify files were uploaded + reader, err = searchCmd.Search() + assert.NoError(t, err) + + fileItems = []utils.SearchResult{} + for resultItem := new(utils.SearchResult); reader.NextRecord(resultItem) == nil; resultItem = new(utils.SearchResult) { + if resultItem.Type != "folder" { + fileItems = append(fileItems, *resultItem) + } + } + readerGetErrorAndAssert(t, reader) + readerCloseAndAssert(t, reader) + + assert.NotEmpty(t, fileItems, "Files should be uploaded without dry-run") + assert.GreaterOrEqual(t, len(fileItems), 1, "At least one file should be uploaded") + + // Verify we can download the uploaded structure + clientTestUtils.RemoveAllAndAssert(t, tests.Out) + runRt(t, "download", tests.RtRepo1+"/"+uploadPath+"/", tests.Out+"/", "--include-dirs=true", "--recursive=true") + + // Verify the directory structure was downloaded + // The upload path preserves the "out/" directory, so files are at dry-run-test/out/... + expectedFilePath := filepath.Join(tests.Out, uploadPath, "out", "inner", "folder", "test.txt") + assert.True(t, fileutils.IsPathExists(expectedFilePath, false), + "File should exist after download at: %s", expectedFilePath) + expectedEmptyDirPath := filepath.Join(tests.Out, uploadPath, "out", "empty") + assert.True(t, fileutils.IsPathExists(expectedEmptyDirPath, false), + "Empty directory should exist after download at: %s", expectedEmptyDirPath) + + cleanArtifactoryTest() +} + func TestArtifactoryDirectDownload(t *testing.T) { initArtifactoryTest(t, "") diff --git a/go.mod b/go.mod index e42be5e90..ce6223dec 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/jfrog/build-info-go v1.13.1-0.20260120103048-d7f367bfa36e github.com/jfrog/gofrog v1.7.6 github.com/jfrog/jfrog-cli-application v1.0.2-0.20260107143435-b30ede954432 - github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260120063955-c654c159290e + github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260127133717-20240af03a4c github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260112010739-87fc7275623c github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251225153025-9d8ac181d615 github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20251205121610-171eb9b0000e @@ -284,10 +284,8 @@ replace github.com/gfleury/go-bitbucket-v1 => github.com/gfleury/go-bitbucket-v1 //replace github.com/jfrog/jfrog-cli-core/v2 => ../jfrog-cli-core -// replace github.com/jfrog/jfrog-cli-artifactory => github.com/fluxxBot/jfrog-cli-artifactory v0.0.0-20260105073552-ae4f86048a11 -// //replace github.com/jfrog/build-info-go => github.com/fluxxBot/build-info-go v1.10.10-0.20260105070825-d3f36f619ba5 -// + //replace github.com/jfrog/jfrog-cli-core/v2 => github.com/fluxxBot/jfrog-cli-core/v2 v2.58.1-0.20260105065921-c6488910f44c //replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6 diff --git a/go.sum b/go.sum index d3b15d43c..90fcbe00f 100644 --- a/go.sum +++ b/go.sum @@ -1216,8 +1216,8 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w= github.com/jfrog/jfrog-cli-application v1.0.2-0.20260107143435-b30ede954432 h1:6eOOs+326IrWLVA+ghDDudJmN3Nt8lxPl11eOu8vtPE= github.com/jfrog/jfrog-cli-application v1.0.2-0.20260107143435-b30ede954432/go.mod h1:xum2HquWO5uExa/A7MQs3TgJJVEeoqTR+6Z4mfBr1Xw= -github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260120063955-c654c159290e h1:F/VQ7UJ4jaEr9tLJ8jLfy4BF4Obhhd0pWu007SBSHt8= -github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260120063955-c654c159290e/go.mod h1:LbhCULfa/eIPSXNgQ5Xw8BIZRmJ0qfF2I4sPa7AHXkY= +github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260127133717-20240af03a4c h1:czaLFCx8wRuO0ixOFgEWYNX2L9UQdcBP71r391LQ3nc= +github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260127133717-20240af03a4c/go.mod h1:ANFZOB4AX+Voo24l1BO8bVvN76m3ZViR1QaK5u3QDgE= github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260112010739-87fc7275623c h1:K9anqOZ7ASxlsijsl9u4jh92wqqIvJA4kTYfXrcOmJA= github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260112010739-87fc7275623c/go.mod h1:+Hnaikp/xCSPD/q7txxRy4Zc0wzjW/usrCSf+6uONSQ= github.com/jfrog/jfrog-cli-evidence v0.8.3-0.20251225153025-9d8ac181d615 h1:y5an0bojHL00ipHP1QuBUrVcP+XK+yZHHOJ/r1I0RUM=