gitee.com/bomy/docker.git@v1.13.1/volume/volume_propagation_linux_test.go (about)

     1  // +build linux
     2  
     3  package volume
     4  
     5  import (
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestParseMountRawPropagation(t *testing.T) {
    11  	var (
    12  		valid   []string
    13  		invalid map[string]string
    14  	)
    15  
    16  	valid = []string{
    17  		"/hostPath:/containerPath:shared",
    18  		"/hostPath:/containerPath:rshared",
    19  		"/hostPath:/containerPath:slave",
    20  		"/hostPath:/containerPath:rslave",
    21  		"/hostPath:/containerPath:private",
    22  		"/hostPath:/containerPath:rprivate",
    23  		"/hostPath:/containerPath:ro,shared",
    24  		"/hostPath:/containerPath:ro,slave",
    25  		"/hostPath:/containerPath:ro,private",
    26  		"/hostPath:/containerPath:ro,z,shared",
    27  		"/hostPath:/containerPath:ro,Z,slave",
    28  		"/hostPath:/containerPath:Z,ro,slave",
    29  		"/hostPath:/containerPath:slave,Z,ro",
    30  		"/hostPath:/containerPath:Z,slave,ro",
    31  		"/hostPath:/containerPath:slave,ro,Z",
    32  		"/hostPath:/containerPath:rslave,ro,Z",
    33  		"/hostPath:/containerPath:ro,rshared,Z",
    34  		"/hostPath:/containerPath:ro,Z,rprivate",
    35  	}
    36  	invalid = map[string]string{
    37  		"/path:/path:ro,rshared,rslave":   `invalid mode`,
    38  		"/path:/path:ro,z,rshared,rslave": `invalid mode`,
    39  		"/path:shared":                    "invalid volume specification",
    40  		"/path:slave":                     "invalid volume specification",
    41  		"/path:private":                   "invalid volume specification",
    42  		"name:/absolute-path:shared":      "invalid volume specification",
    43  		"name:/absolute-path:rshared":     "invalid volume specification",
    44  		"name:/absolute-path:slave":       "invalid volume specification",
    45  		"name:/absolute-path:rslave":      "invalid volume specification",
    46  		"name:/absolute-path:private":     "invalid volume specification",
    47  		"name:/absolute-path:rprivate":    "invalid volume specification",
    48  	}
    49  
    50  	for _, path := range valid {
    51  		if _, err := ParseMountRaw(path, "local"); err != nil {
    52  			t.Fatalf("ParseMountRaw(`%q`) should succeed: error %q", path, err)
    53  		}
    54  	}
    55  
    56  	for path, expectedError := range invalid {
    57  		if _, err := ParseMountRaw(path, "local"); err == nil {
    58  			t.Fatalf("ParseMountRaw(`%q`) should have failed validation. Err %v", path, err)
    59  		} else {
    60  			if !strings.Contains(err.Error(), expectedError) {
    61  				t.Fatalf("ParseMountRaw(`%q`) error should contain %q, got %v", path, expectedError, err.Error())
    62  			}
    63  		}
    64  	}
    65  }