github.com/rentongzhang/docker@v1.8.2-rc1/pkg/archive/archive_unix_test.go (about)

     1  // +build !windows
     2  
     3  package archive
     4  
     5  import (
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func TestCanonicalTarNameForPath(t *testing.T) {
    11  	cases := []struct{ in, expected string }{
    12  		{"foo", "foo"},
    13  		{"foo/bar", "foo/bar"},
    14  		{"foo/dir/", "foo/dir/"},
    15  	}
    16  	for _, v := range cases {
    17  		if out, err := CanonicalTarNameForPath(v.in); err != nil {
    18  			t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
    19  		} else if out != v.expected {
    20  			t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
    21  		}
    22  	}
    23  }
    24  
    25  func TestCanonicalTarName(t *testing.T) {
    26  	cases := []struct {
    27  		in       string
    28  		isDir    bool
    29  		expected string
    30  	}{
    31  		{"foo", false, "foo"},
    32  		{"foo", true, "foo/"},
    33  		{"foo/bar", false, "foo/bar"},
    34  		{"foo/bar", true, "foo/bar/"},
    35  	}
    36  	for _, v := range cases {
    37  		if out, err := canonicalTarName(v.in, v.isDir); err != nil {
    38  			t.Fatalf("cannot get canonical name for path: %s: %v", v.in, err)
    39  		} else if out != v.expected {
    40  			t.Fatalf("wrong canonical tar name. expected:%s got:%s", v.expected, out)
    41  		}
    42  	}
    43  }
    44  
    45  func TestChmodTarEntry(t *testing.T) {
    46  	cases := []struct {
    47  		in, expected os.FileMode
    48  	}{
    49  		{0000, 0000},
    50  		{0777, 0777},
    51  		{0644, 0644},
    52  		{0755, 0755},
    53  		{0444, 0444},
    54  	}
    55  	for _, v := range cases {
    56  		if out := chmodTarEntry(v.in); out != v.expected {
    57  			t.Fatalf("wrong chmod. expected:%v got:%v", v.expected, out)
    58  		}
    59  	}
    60  }