github.com/gunjan5/docker@v1.8.2/daemon/volumes_unit_test.go (about)

     1  package daemon
     2  
     3  import "testing"
     4  
     5  func TestParseVolumeFrom(t *testing.T) {
     6  	cases := []struct {
     7  		spec    string
     8  		expId   string
     9  		expMode string
    10  		fail    bool
    11  	}{
    12  		{"", "", "", true},
    13  		{"foobar", "foobar", "rw", false},
    14  		{"foobar:rw", "foobar", "rw", false},
    15  		{"foobar:ro", "foobar", "ro", false},
    16  		{"foobar:baz", "", "", true},
    17  	}
    18  
    19  	for _, c := range cases {
    20  		id, mode, err := parseVolumesFrom(c.spec)
    21  		if c.fail {
    22  			if err == nil {
    23  				t.Fatalf("Expected error, was nil, for spec %s\n", c.spec)
    24  			}
    25  			continue
    26  		}
    27  
    28  		if id != c.expId {
    29  			t.Fatalf("Expected id %s, was %s, for spec %s\n", c.expId, id, c.spec)
    30  		}
    31  		if mode != c.expMode {
    32  			t.Fatalf("Expected mode %s, was %s for spec %s\n", c.expMode, mode, c.spec)
    33  		}
    34  	}
    35  }