Bläddra i källkod

Fix tests

Signed-off-by: Drew Erny <derny@mirantis.com>
Drew Erny 1 år sedan
förälder
incheckning
2922732df5

+ 1 - 1
daemon/cluster/executor/container/container_test.go

@@ -210,7 +210,7 @@ func TestTmpfsConversion(t *testing.T) {
 				},
 				},
 			}
 			}
 			config := containerConfig{task: &task}
 			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))
 		})
 		})
 	}
 	}
 }
 }

+ 17 - 0
volume/mounts/linux_parser_test.go

@@ -238,6 +238,7 @@ func TestConvertTmpfsOptions(t *testing.T) {
 		readOnly             bool
 		readOnly             bool
 		expectedSubstrings   []string
 		expectedSubstrings   []string
 		unexpectedSubstrings []string
 		unexpectedSubstrings []string
+		err                  bool
 	}
 	}
 	cases := []testCase{
 	cases := []testCase{
 		{
 		{
@@ -252,10 +253,26 @@ func TestConvertTmpfsOptions(t *testing.T) {
 			expectedSubstrings:   []string{"ro"},
 			expectedSubstrings:   []string{"ro"},
 			unexpectedSubstrings: []string{},
 			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()
 	p := NewLinuxParser()
 	for _, tc := range cases {
 	for _, tc := range cases {
 		data, err := p.ConvertTmpfsOptions(&tc.opt, tc.readOnly)
 		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 {
 		if err != nil {
 			t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
 			t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
 				tc.opt, tc.readOnly, err)
 				tc.opt, tc.readOnly, err)

+ 0 - 65
volume/mounts/parser_test.go

@@ -2,7 +2,6 @@ package mounts // import "github.com/docker/docker/volume/mounts"
 
 
 import (
 import (
 	"os"
 	"os"
-	"strings"
 	"testing"
 	"testing"
 
 
 	"github.com/docker/docker/api/types/mount"
 	"github.com/docker/docker/api/types/mount"
@@ -10,70 +9,6 @@ import (
 	is "gotest.tools/v3/assert/cmp"
 	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{}
 type mockFiProvider struct{}
 
 
 func (mockFiProvider) fileInfo(path string) (exists, isDir bool, err error) {
 func (mockFiProvider) fileInfo(path string) (exists, isDir bool, err error) {