github.com/darciopacifico/docker@v1.9.0-rc1/daemon/volumes_linux_unit_test.go (about)

     1  // +build experimental
     2  
     3  package daemon
     4  
     5  import "testing"
     6  
     7  func TestParseBindMount(t *testing.T) {
     8  	cases := []struct {
     9  		bind      string
    10  		driver    string
    11  		expDest   string
    12  		expSource string
    13  		expName   string
    14  		expDriver string
    15  		expRW     bool
    16  		fail      bool
    17  	}{
    18  		{"/tmp:/tmp", "", "/tmp", "/tmp", "", "", true, false},
    19  		{"/tmp:/tmp:ro", "", "/tmp", "/tmp", "", "", false, false},
    20  		{"/tmp:/tmp:rw", "", "/tmp", "/tmp", "", "", true, false},
    21  		{"/tmp:/tmp:foo", "", "/tmp", "/tmp", "", "", false, true},
    22  		{"name:/tmp", "", "/tmp", "", "name", "local", true, false},
    23  		{"name:/tmp", "external", "/tmp", "", "name", "external", true, false},
    24  		{"name:/tmp:ro", "local", "/tmp", "", "name", "local", false, false},
    25  		{"local/name:/tmp:rw", "", "/tmp", "", "local/name", "local", true, false},
    26  		{"/tmp:tmp", "", "", "", "", "", true, true},
    27  	}
    28  
    29  	for _, c := range cases {
    30  		m, err := parseBindMount(c.bind, c.driver)
    31  		if c.fail {
    32  			if err == nil {
    33  				t.Fatalf("Expected error, was nil, for spec %s\n", c.bind)
    34  			}
    35  			continue
    36  		}
    37  
    38  		if m.Destination != c.expDest {
    39  			t.Fatalf("Expected destination %s, was %s, for spec %s\n", c.expDest, m.Destination, c.bind)
    40  		}
    41  
    42  		if m.Source != c.expSource {
    43  			t.Fatalf("Expected source %s, was %s, for spec %s\n", c.expSource, m.Source, c.bind)
    44  		}
    45  
    46  		if m.Name != c.expName {
    47  			t.Fatalf("Expected name %s, was %s for spec %s\n", c.expName, m.Name, c.bind)
    48  		}
    49  
    50  		if m.Driver != c.expDriver {
    51  			t.Fatalf("Expected driver %s, was %s, for spec %s\n", c.expDriver, m.Driver, c.bind)
    52  		}
    53  
    54  		if m.RW != c.expRW {
    55  			t.Fatalf("Expected RW %v, was %v for spec %s\n", c.expRW, m.RW, c.bind)
    56  		}
    57  	}
    58  }