From 328b4008713925ee5be082c29c81ff047fa123be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Va=C5=A1ek?= Date: Fri, 31 Jan 2025 19:36:29 +0100 Subject: [PATCH] Create test symlinks dynamically (#1064) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some tools dislike having questionable symlinks in git repository so we must create this symlinks dynamically in the test instead of having it committed into the repository. Signed-off-by: Matej VaĊĦek --- pkg/oci/containerize_test.go | 13 ++++++++++++- pkg/oci/testdata/test-links/absoluteLink | 1 - pkg/oci/testdata/test-links/absoluteLinkWindows | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) delete mode 120000 pkg/oci/testdata/test-links/absoluteLink delete mode 120000 pkg/oci/testdata/test-links/absoluteLinkWindows diff --git a/pkg/oci/containerize_test.go b/pkg/oci/containerize_test.go index 33acffb461..a330b08ea8 100644 --- a/pkg/oci/containerize_test.go +++ b/pkg/oci/containerize_test.go @@ -1,6 +1,8 @@ package oci import ( + "errors" + "os" "path/filepath" "runtime" "testing" @@ -10,7 +12,16 @@ import ( // links which are absolute or refer to targets outside the given root, in // addition to the basic job of returning the value of reading the link. func Test_validatedLinkTarget(t *testing.T) { - root := "testdata/test-links" + root := filepath.Join("testdata", "test-links") + + err := os.Symlink("/var/example/absolute/link", filepath.Join(root, "absoluteLink")) + if err != nil && !errors.Is(err, os.ErrExist) { + t.Fatal(err) + } + err = os.Symlink("c://some/absolute/path", filepath.Join(root, "absoluteLinkWindows")) + if err != nil && !errors.Is(err, os.ErrExist) { + t.Fatal(err) + } // Windows-specific absolute link and link target values: absoluteLink := "absoluteLink" diff --git a/pkg/oci/testdata/test-links/absoluteLink b/pkg/oci/testdata/test-links/absoluteLink deleted file mode 120000 index 28434a9033..0000000000 --- a/pkg/oci/testdata/test-links/absoluteLink +++ /dev/null @@ -1 +0,0 @@ -/var/example/absolute/link \ No newline at end of file diff --git a/pkg/oci/testdata/test-links/absoluteLinkWindows b/pkg/oci/testdata/test-links/absoluteLinkWindows deleted file mode 120000 index c3aaf3f5c3..0000000000 --- a/pkg/oci/testdata/test-links/absoluteLinkWindows +++ /dev/null @@ -1 +0,0 @@ -c://some/absolute/path \ No newline at end of file