|
@@ -3,6 +3,7 @@
|
|
|
package volume
|
|
|
|
|
|
import (
|
|
|
+ "strings"
|
|
|
"testing"
|
|
|
|
|
|
mounttypes "github.com/docker/docker/api/types/mount"
|
|
@@ -10,14 +11,41 @@ import (
|
|
|
|
|
|
func TestConvertTmpfsOptions(t *testing.T) {
|
|
|
type testCase struct {
|
|
|
- opt mounttypes.TmpfsOptions
|
|
|
+ opt mounttypes.TmpfsOptions
|
|
|
+ readOnly bool
|
|
|
+ expectedSubstrings []string
|
|
|
+ unexpectedSubstrings []string
|
|
|
}
|
|
|
cases := []testCase{
|
|
|
- {mounttypes.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700}},
|
|
|
+ {
|
|
|
+ opt: mounttypes.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700},
|
|
|
+ readOnly: false,
|
|
|
+ expectedSubstrings: []string{"size=1m", "mode=700"},
|
|
|
+ unexpectedSubstrings: []string{"ro"},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ opt: mounttypes.TmpfsOptions{},
|
|
|
+ readOnly: true,
|
|
|
+ expectedSubstrings: []string{"ro"},
|
|
|
+ unexpectedSubstrings: []string{},
|
|
|
+ },
|
|
|
}
|
|
|
for _, c := range cases {
|
|
|
- if _, err := ConvertTmpfsOptions(&c.opt); err != nil {
|
|
|
- t.Fatalf("could not convert %+v to string: %v", c.opt, err)
|
|
|
+ data, err := ConvertTmpfsOptions(&c.opt, c.readOnly)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
|
|
|
+ c.opt, c.readOnly, err)
|
|
|
+ }
|
|
|
+ t.Logf("data=%q", data)
|
|
|
+ for _, s := range c.expectedSubstrings {
|
|
|
+ if !strings.Contains(data, s) {
|
|
|
+ t.Fatalf("expected substring: %s, got %v (case=%+v)", s, data, c)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, s := range c.unexpectedSubstrings {
|
|
|
+ if strings.Contains(data, s) {
|
|
|
+ t.Fatalf("unexpected substring: %s, got %v (case=%+v)", s, data, c)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|