From 2d6d199c90e26bf99f1011a7db91ae9fd57218b8 Mon Sep 17 00:00:00 2001 From: Brandon Croft Date: Fri, 18 Aug 2023 09:13:28 -0600 Subject: [PATCH] Update slug_test.go --- slug_test.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/slug_test.go b/slug_test.go index 34a950f..5a1eb9d 100644 --- a/slug_test.go +++ b/slug_test.go @@ -84,6 +84,12 @@ func TestPack_absoluteSrcRelativeSymlinks(t *testing.T) { // traversing the source directory t.Fatalf("err: %v", err) } + + // Cannot pack without dereferencing + _, err = Pack(path, slug, false) + if !strings.HasPrefix(err.Error(), "illegal slug error:") { + t.Fatalf("expected illegal slug error, got %q", err) + } } func TestPackWithoutIgnoring(t *testing.T) { @@ -1088,7 +1094,8 @@ func assertArchiveFixture(t *testing.T, slug *bytes.Buffer, got *Meta) { tarR := tar.NewReader(gzipR) var ( - symFound bool + sym1Found bool + sym2Found bool externalTargetFound bool fileList []string slugSize int64 @@ -1115,7 +1122,17 @@ func assertArchiveFixture(t *testing.T, slug *bytes.Buffer, got *Meta) { if hdr.Linkname != "../bar.txt" { t.Fatalf("expect target of '../bar.txt', got %q", hdr.Linkname) } - symFound = true + sym1Found = true + } + + if hdr.Name == "sub2/bar.txt" { + if hdr.Typeflag != tar.TypeSymlink { + t.Fatalf("expect symlink for file 'sub2/bar.txt'") + } + if hdr.Linkname != "../sub/bar.txt" { + t.Fatalf("expect target of '../sub/bar.txt', got %q", hdr.Linkname) + } + sym2Found = true } if hdr.Name == "example.tf" { @@ -1127,8 +1144,8 @@ func assertArchiveFixture(t *testing.T, slug *bytes.Buffer, got *Meta) { } // Make sure we saw and handled a symlink - if !symFound { - t.Fatal("expected to find symlink") + if !sym1Found || !sym2Found { + t.Fatal("expected to find two symlinks") } // Make sure we saw and handled a dereferenced symlink