github.com/vvnotw/moby@v1.13.1/daemon/volumes_unit_test.go (about)

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