Fix tests
Signed-off-by: Drew Erny <derny@mirantis.com>
This commit is contained in:
parent
392d34a93a
commit
2922732df5
3 changed files with 18 additions and 66 deletions
|
@ -210,7 +210,7 @@ func TestTmpfsConversion(t *testing.T) {
|
|||
},
|
||||
}
|
||||
config := containerConfig{task: &task}
|
||||
assert.Check(t, is.DeepEqual(c.to, config.hostConfig().Mounts))
|
||||
assert.Check(t, is.DeepEqual(c.to, config.hostConfig(nil).Mounts))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ func TestConvertTmpfsOptions(t *testing.T) {
|
|||
readOnly bool
|
||||
expectedSubstrings []string
|
||||
unexpectedSubstrings []string
|
||||
err bool
|
||||
}
|
||||
cases := []testCase{
|
||||
{
|
||||
|
@ -252,10 +253,26 @@ func TestConvertTmpfsOptions(t *testing.T) {
|
|||
expectedSubstrings: []string{"ro"},
|
||||
unexpectedSubstrings: []string{},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{Options: "exec"},
|
||||
readOnly: true,
|
||||
expectedSubstrings: []string{"ro", "exec"},
|
||||
unexpectedSubstrings: []string{"noexec"},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{Options: "INVALID"},
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
p := NewLinuxParser()
|
||||
for _, tc := range cases {
|
||||
data, err := p.ConvertTmpfsOptions(&tc.opt, tc.readOnly)
|
||||
if tc.err {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for %+v, got nil", tc.opt)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
|
||||
tc.opt, tc.readOnly, err)
|
||||
|
|
|
@ -2,7 +2,6 @@ package mounts // import "github.com/docker/docker/volume/mounts"
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
|
@ -10,70 +9,6 @@ import (
|
|||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
|
||||
type parseMountRawTestSet struct {
|
||||
valid []string
|
||||
invalid map[string]string
|
||||
}
|
||||
|
||||
func TestConvertTmpfsOptions(t *testing.T) {
|
||||
type testCase struct {
|
||||
opt mount.TmpfsOptions
|
||||
readOnly bool
|
||||
expectedSubstrings []string
|
||||
unexpectedSubstrings []string
|
||||
err bool
|
||||
}
|
||||
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{},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{Options: "exec"},
|
||||
readOnly: true,
|
||||
expectedSubstrings: []string{"ro", "exec"},
|
||||
unexpectedSubstrings: []string{"noexec"},
|
||||
},
|
||||
{
|
||||
opt: mount.TmpfsOptions{Options: "INVALID"},
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
p := &linuxParser{}
|
||||
for _, c := range cases {
|
||||
data, err := p.ConvertTmpfsOptions(&c.opt, c.readOnly)
|
||||
if c.err {
|
||||
if err == nil {
|
||||
t.Fatalf("expected error for %+v, got nil", c.opt)
|
||||
}
|
||||
continue
|
||||
}
|
||||
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