Skip to content

Commit

Permalink
rebase from main
Browse files Browse the repository at this point in the history
  • Loading branch information
jkroepke committed Aug 5, 2024
1 parent cb4cec2 commit da59316
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/provider/data_source_archive_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccArchiveFile_Basic(t *testing.T) {
ProtoV5ProviderFactories: protoV5ProviderFactories(),
Steps: []r.TestStep{
{
Config: testAccArchiveFileContentConfig(f),
Config: testAccArchiveFileContentConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
Expand All @@ -49,7 +49,7 @@ func TestAccArchiveFile_Basic(t *testing.T) {
),
},
{
Config: testAccArchiveFileFileConfig(f),
Config: testAccArchiveFileFileConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
Expand All @@ -74,7 +74,7 @@ func TestAccArchiveFile_Basic(t *testing.T) {
),
},
{
Config: testAccArchiveFileDirConfig(f),
Config: testAccArchiveFileDirConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
Expand All @@ -99,21 +99,21 @@ func TestAccArchiveFile_Basic(t *testing.T) {
),
},
{
Config: testAccArchiveFileDirExcludesConfig(f),
Config: testAccArchiveFileDirExcludesConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
),
},
{
Config: testAccArchiveFileDirExcludesGlobConfig(f),
Config: testAccArchiveFileDirExcludesGlobConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
),
},
{
Config: testAccArchiveFileMultiSourceConfig(f),
Config: testAccArchiveFileMultiSourceConfig("zip", f),
Check: r.ComposeTestCheckFunc(
testAccArchiveFileSize(f, &fileSize),
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
Expand Down Expand Up @@ -1404,15 +1404,15 @@ data "archive_file" "foo" {
`, format, filepath.ToSlash(outputPath))
}

func testAccArchiveFileDirExcludesGlobConfig(outputPath string) string {
func testAccArchiveFileDirExcludesGlobConfig(format, outputPath string) string {
return fmt.Sprintf(`
data "archive_file" "foo" {
type = "zip"
type = "%s"
source_dir = "test-fixtures/test-dir/test-dir1"
excludes = ["test-fixtures/test-dir/test-dir1/file2.txt", "**/file[2-3].txt"]
output_path = "%s"
}
`, filepath.ToSlash(outputPath))
`, format, filepath.ToSlash(outputPath))
}

func testAccArchiveFileMultiSourceConfig(format, outputPath string) string {
Expand Down
49 changes: 49 additions & 0 deletions internal/provider/tar_archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,32 @@ func TestTarArchiver_Dir_Exclude_DoNotExcludeSymlinkDirectories(t *testing.T) {
})
}

func TestTarArchiver_Dir_Exclude_Glob_DoNotExcludeSymlinkDirectories(t *testing.T) {
tarFilePath := filepath.Join(t.TempDir(), "archive-dir-with-symlink-dir.tar")

archiver := NewTarGzArchiver(tarFilePath)
if err := archiver.ArchiveDir("./test-fixtures", ArchiveDirOpts{
Excludes: []string{
"**/file1.txt",
"**/file2.*",
"test-dir-with-symlink-dir/test-symlink-dir",
"test-symlink-dir-with-symlink-file/test-symlink.txt",
},
}); err != nil {
t.Fatalf("unexpected error: %s", err)
}

ensureTarContents(t, tarFilePath, map[string][]byte{
"test-dir/test-dir1/file3.txt": []byte("This is file 3"),
"test-dir/test-dir2/file3.txt": []byte("This is file 3"),
"test-dir/test-file.txt": []byte("This is test content"),
"test-dir-with-symlink-file/test-file.txt": []byte("This is test content"),
"test-dir-with-symlink-file/test-symlink.txt": []byte("This is test content"),
"test-symlink-dir/file3.txt": []byte("This is file 3"),
"test-symlink-dir-with-symlink-file/test-file.txt": []byte("This is test content"),
})
}

func TestTarArchiver_Dir_Exclude_ExcludeSymlinkDirectories(t *testing.T) {
tarFilePath := filepath.Join(t.TempDir(), "archive-dir-with-symlink-dir.tar.gz")

Expand Down Expand Up @@ -334,6 +360,29 @@ func TestTarArchiver_Dir_Exclude_ExcludeSymlinkDirectories(t *testing.T) {
})
}

func TestTarArchiver_Dir_Exclude_Glob_ExcludeSymlinkDirectories(t *testing.T) {
tarFilePath := filepath.Join(t.TempDir(), "archive-dir-with-symlink-dir.zip")

archiver := NewTarGzArchiver(tarFilePath)
err := archiver.ArchiveDir("./test-fixtures", ArchiveDirOpts{
Excludes: []string{
"test-dir/test-dir1/file1.txt",
"**/file[2-3].txt",
"test-dir-with-symlink-file",
},
ExcludeSymlinkDirectories: true,
})

if err != nil {
t.Errorf("expected no error: %s", err)
}

ensureTarContents(t, tarFilePath, map[string][]byte{
"test-dir/test-dir2/file1.txt": []byte("This is file 1"),
"test-dir/test-file.txt": []byte("This is test content"),
})
}

func ensureTarContents(t *testing.T, tarFilePath string, wants map[string][]byte) {
t.Helper()

Expand Down

0 comments on commit da59316

Please sign in to comment.