github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/pkg/archive/archive_windows_test.go (about)

     1  // +build windows
     2  
     3  package archive // import "github.com/docker/docker/pkg/archive"
     4  
     5  import (
     6  	"io/ioutil"
     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 := ioutil.TempDir("", "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  	ioutil.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 TestCanonicalTarNameForPath(t *testing.T) {
    37  	cases := []struct {
    38  		in, expected string
    39  	}{
    40  		{"foo", "foo"},
    41  		{"foo/bar", "foo/bar"},
    42  		{`foo\bar`, "foo/bar"},
    43  	}
    44  	for _, v := range cases {
    45  		if CanonicalTarNameForPath(v.in) != v.expected {
    46  			t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, CanonicalTarNameForPath(v.in))
    47  		}
    48  	}
    49  }
    50  
    51  func TestCanonicalTarName(t *testing.T) {
    52  	cases := []struct {
    53  		in       string
    54  		isDir    bool
    55  		expected string
    56  	}{
    57  		{"foo", false, "foo"},
    58  		{"foo", true, "foo/"},
    59  		{`foo\bar`, false, "foo/bar"},
    60  		{`foo\bar`, true, "foo/bar/"},
    61  	}
    62  	for _, v := range cases {
    63  		if canonicalTarName(v.in, v.isDir) != v.expected {
    64  			t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, canonicalTarName(v.in, v.isDir))
    65  		}
    66  	}
    67  }
    68  
    69  func TestChmodTarEntry(t *testing.T) {
    70  	cases := []struct {
    71  		in, expected os.FileMode
    72  	}{
    73  		{0000, 0111},
    74  		{0777, 0755},
    75  		{0644, 0755},
    76  		{0755, 0755},
    77  		{0444, 0555},
    78  		{0755 | os.ModeDir, 0755 | os.ModeDir},
    79  		{0755 | os.ModeSymlink, 0755 | os.ModeSymlink},
    80  	}
    81  	for _, v := range cases {
    82  		if out := chmodTarEntry(v.in); out != v.expected {
    83  			t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
    84  		}
    85  	}
    86  }