github.com/baris/docker@v1.7.0/daemon/volumes_stubs_unit_test.go (about)

     1  // +build !experimental
     2  
     3  package daemon
     4  
     5  import (
     6  	"io/ioutil"
     7  	"os"
     8  	"testing"
     9  
    10  	"github.com/docker/docker/runconfig"
    11  	"github.com/docker/docker/volume"
    12  	"github.com/docker/docker/volume/drivers"
    13  	"github.com/docker/docker/volume/local"
    14  )
    15  
    16  func TestGetVolumeDefaultDriver(t *testing.T) {
    17  	tmp, err := ioutil.TempDir("", "volume-test-")
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  	defer os.RemoveAll(tmp)
    22  
    23  	l, err := local.New(tmp)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	volumedrivers.Register(l, volume.DefaultDriverName)
    28  	d, err := getVolumeDriver("missing")
    29  	if err != nil {
    30  		t.Fatal(err)
    31  	}
    32  
    33  	if d.Name() != volume.DefaultDriverName {
    34  		t.Fatalf("Expected local driver, was %s\n", d.Name)
    35  	}
    36  }
    37  
    38  func TestParseBindMount(t *testing.T) {
    39  	cases := []struct {
    40  		bind       string
    41  		expDest    string
    42  		expSource  string
    43  		expName    string
    44  		mountLabel string
    45  		expRW      bool
    46  		fail       bool
    47  	}{
    48  		{"/tmp:/tmp", "/tmp", "/tmp", "", "", true, false},
    49  		{"/tmp:/tmp:ro", "/tmp", "/tmp", "", "", false, false},
    50  		{"/tmp:/tmp:rw", "/tmp", "/tmp", "", "", true, false},
    51  		{"/tmp:/tmp:foo", "/tmp", "/tmp", "", "", false, true},
    52  		{"name:/tmp", "", "", "", "", false, true},
    53  		{"local/name:/tmp:rw", "", "", "", "", true, true},
    54  	}
    55  
    56  	for _, c := range cases {
    57  		conf := &runconfig.Config{}
    58  		m, err := parseBindMount(c.bind, c.mountLabel, conf)
    59  		if c.fail {
    60  			if err == nil {
    61  				t.Fatalf("Expected error, was nil, for spec %s\n", c.bind)
    62  			}
    63  			continue
    64  		}
    65  
    66  		if m.Destination != c.expDest {
    67  			t.Fatalf("Expected destination %s, was %s, for spec %s\n", c.expDest, m.Destination, c.bind)
    68  		}
    69  
    70  		if m.Source != c.expSource {
    71  			t.Fatalf("Expected source %s, was %s, for spec %s\n", c.expSource, m.Source, c.bind)
    72  		}
    73  
    74  		if m.Name != c.expName {
    75  			t.Fatalf("Expected name %s, was %s for spec %s\n", c.expName, m.Name, c.bind)
    76  		}
    77  
    78  		if m.RW != c.expRW {
    79  			t.Fatalf("Expected RW %v, was %v for spec %s\n", c.expRW, m.RW, c.bind)
    80  		}
    81  	}
    82  }