github.com/rawahars/moby@v24.0.4+incompatible/pkg/archive/archive_windows_test.go (about)

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