mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
volume/mounts: move TestConvertTmpfsOptions
It's only testing the LinuxParser, so moving it to a file specific to that code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
300c11c7c9
commit
536818508d
2 changed files with 50 additions and 42 deletions
50
volume/mounts/linux_parser_test.go
Normal file
50
volume/mounts/linux_parser_test.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package mounts // import "github.com/docker/docker/volume/mounts"
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
)
|
||||
|
||||
func TestConvertTmpfsOptions(t *testing.T) {
|
||||
type testCase struct {
|
||||
opt mount.TmpfsOptions
|
||||
readOnly bool
|
||||
expectedSubstrings []string
|
||||
unexpectedSubstrings []string
|
||||
}
|
||||
cases := []testCase{
|
||||
{
|
||||
opt: mount.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700},
|
||||
readOnly: false,
|
||||
expectedSubstrings: []string{"size=1m", "mode=700"},
|
||||
unexpectedSubstrings: []string{"ro"},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{},
|
||||
readOnly: true,
|
||||
expectedSubstrings: []string{"ro"},
|
||||
unexpectedSubstrings: []string{},
|
||||
},
|
||||
}
|
||||
p := &linuxParser{}
|
||||
for _, c := range cases {
|
||||
data, err := p.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,48 +17,6 @@ type parseMountRawTestSet struct {
|
|||
invalid map[string]string
|
||||
}
|
||||
|
||||
func TestConvertTmpfsOptions(t *testing.T) {
|
||||
type testCase struct {
|
||||
opt mount.TmpfsOptions
|
||||
readOnly bool
|
||||
expectedSubstrings []string
|
||||
unexpectedSubstrings []string
|
||||
}
|
||||
cases := []testCase{
|
||||
{
|
||||
opt: mount.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700},
|
||||
readOnly: false,
|
||||
expectedSubstrings: []string{"size=1m", "mode=700"},
|
||||
unexpectedSubstrings: []string{"ro"},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{},
|
||||
readOnly: true,
|
||||
expectedSubstrings: []string{"ro"},
|
||||
unexpectedSubstrings: []string{},
|
||||
},
|
||||
}
|
||||
p := &linuxParser{}
|
||||
for _, c := range cases {
|
||||
data, err := p.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type mockFiProvider struct{}
|
||||
|
||||
func (mockFiProvider) fileInfo(path string) (exists, isDir bool, err error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue