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

     1  // +build linux
     2  
     3  package volume
     4  
     5  import (
     6  	"strings"
     7  	"testing"
     8  
     9  	mounttypes "github.com/docker/docker/api/types/mount"
    10  )
    11  
    12  func TestConvertTmpfsOptions(t *testing.T) {
    13  	type testCase struct {
    14  		opt                  mounttypes.TmpfsOptions
    15  		readOnly             bool
    16  		expectedSubstrings   []string
    17  		unexpectedSubstrings []string
    18  	}
    19  	cases := []testCase{
    20  		{
    21  			opt:                  mounttypes.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700},
    22  			readOnly:             false,
    23  			expectedSubstrings:   []string{"size=1m", "mode=700"},
    24  			unexpectedSubstrings: []string{"ro"},
    25  		},
    26  		{
    27  			opt:                  mounttypes.TmpfsOptions{},
    28  			readOnly:             true,
    29  			expectedSubstrings:   []string{"ro"},
    30  			unexpectedSubstrings: []string{},
    31  		},
    32  	}
    33  	for _, c := range cases {
    34  		data, err := ConvertTmpfsOptions(&c.opt, c.readOnly)
    35  		if err != nil {
    36  			t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
    37  				c.opt, c.readOnly, err)
    38  		}
    39  		t.Logf("data=%q", data)
    40  		for _, s := range c.expectedSubstrings {
    41  			if !strings.Contains(data, s) {
    42  				t.Fatalf("expected substring: %s, got %v (case=%+v)", s, data, c)
    43  			}
    44  		}
    45  		for _, s := range c.unexpectedSubstrings {
    46  			if strings.Contains(data, s) {
    47  				t.Fatalf("unexpected substring: %s, got %v (case=%+v)", s, data, c)
    48  			}
    49  		}
    50  	}
    51  }