2016-09-22 23:14:15 +03:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package volume
|
|
|
|
|
|
|
|
import (
|
2016-11-08 09:46:23 +03:00
|
|
|
"strings"
|
2016-09-22 23:14:15 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
mounttypes "github.com/docker/docker/api/types/mount"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestConvertTmpfsOptions(t *testing.T) {
|
|
|
|
type testCase struct {
|
2016-11-08 09:46:23 +03:00
|
|
|
opt mounttypes.TmpfsOptions
|
|
|
|
readOnly bool
|
|
|
|
expectedSubstrings []string
|
|
|
|
unexpectedSubstrings []string
|
2016-09-22 23:14:15 +03:00
|
|
|
}
|
|
|
|
cases := []testCase{
|
2016-11-08 09:46:23 +03:00
|
|
|
{
|
|
|
|
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{},
|
|
|
|
},
|
2016-09-22 23:14:15 +03:00
|
|
|
}
|
|
|
|
for _, c := range cases {
|
2016-11-08 09:46:23 +03:00
|
|
|
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)
|
|
|
|
}
|
2016-09-22 23:14:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|