github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/archive/archive_windows_test.go (about)

     1  //go:build windows
     2  
     3  package archive // import "github.com/Prakhar-Agarwal-byte/moby/pkg/archive"
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"testing"
     9  )
    10  
    11  func TestCopyFileWithInvalidDest(t *testing.T) {
    12  	// TODO Windows: This is currently failing. Not sure what has
    13  	// recently changed in CopyWithTar as used to pass. Further investigation
    14  	// is required.
    15  	t.Skip("Currently fails")
    16  	folder, err := os.MkdirTemp("", "docker-archive-test")
    17  	if err != nil {
    18  		t.Fatal(err)
    19  	}
    20  	defer os.RemoveAll(folder)
    21  	dest := "c:dest"
    22  	srcFolder := filepath.Join(folder, "src")
    23  	src := filepath.Join(folder, "src", "src")
    24  	err = os.MkdirAll(srcFolder, 0o740)
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	os.WriteFile(src, []byte("content"), 0o777)
    29  	err = defaultCopyWithTar(src, dest)
    30  	if err == nil {
    31  		t.Fatalf("archiver.CopyWithTar should throw an error on invalid dest.")
    32  	}
    33  }
    34  
    35  func TestCanonicalTarName(t *testing.T) {
    36  	cases := []struct {
    37  		in       string
    38  		isDir    bool
    39  		expected string
    40  	}{
    41  		{"foo", false, "foo"},
    42  		{"foo", true, "foo/"},
    43  		{`foo\bar`, false, "foo/bar"},
    44  		{`foo\bar`, true, "foo/bar/"},
    45  	}
    46  	for _, v := range cases {
    47  		if canonicalTarName(v.in, v.isDir) != v.expected {
    48  			t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, canonicalTarName(v.in, v.isDir))
    49  		}
    50  	}
    51  }
    52  
    53  func TestChmodTarEntry(t *testing.T) {
    54  	cases := []struct {
    55  		in, expected os.FileMode
    56  	}{
    57  		{0o000, 0o111},
    58  		{0o777, 0o755},
    59  		{0o644, 0o755},
    60  		{0o755, 0o755},
    61  		{0o444, 0o555},
    62  	}
    63  	for _, v := range cases {
    64  		if out := chmodTarEntry(v.in); out != v.expected {
    65  			t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
    66  		}
    67  	}
    68  }