Merge pull request #32614 from aaronlehmann/testify
Remove pkg/testutil/assert in favor of testify
This commit is contained in:
commit
1eec7b5583
102 changed files with 2305 additions and 1143 deletions
|
@ -1,8 +1,9 @@
|
||||||
package dockerfile
|
package dockerfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func strPtr(source string) *string {
|
func strPtr(source string) *string {
|
||||||
|
@ -37,7 +38,7 @@ func TestGetAllAllowed(t *testing.T) {
|
||||||
"ArgFromMeta": "frommeta1",
|
"ArgFromMeta": "frommeta1",
|
||||||
"ArgFromMetaOverriden": "fromdockerfile3",
|
"ArgFromMetaOverriden": "fromdockerfile3",
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, all, expected)
|
assert.Equal(t, expected, all)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllMeta(t *testing.T) {
|
func TestGetAllMeta(t *testing.T) {
|
||||||
|
@ -59,5 +60,5 @@ func TestGetAllMeta(t *testing.T) {
|
||||||
"ArgOverriddenByOptions": "fromopt2",
|
"ArgOverriddenByOptions": "fromopt2",
|
||||||
"ArgNoDefaultInMetaFromOptions": "fromopt3",
|
"ArgNoDefaultInMetaFromOptions": "fromopt3",
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, all, expected)
|
assert.Equal(t, expected, all)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/builder/dockerfile/parser"
|
"github.com/docker/docker/builder/dockerfile/parser"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddNodesForLabelOption(t *testing.T) {
|
func TestAddNodesForLabelOption(t *testing.T) {
|
||||||
dockerfile := "FROM scratch"
|
dockerfile := "FROM scratch"
|
||||||
result, err := parser.Parse(strings.NewReader(dockerfile))
|
result, err := parser.Parse(strings.NewReader(dockerfile))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"org.e": "cli-e",
|
"org.e": "cli-e",
|
||||||
|
@ -27,8 +27,8 @@ func TestAddNodesForLabelOption(t *testing.T) {
|
||||||
"FROM scratch",
|
"FROM scratch",
|
||||||
`LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`,
|
`LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`,
|
||||||
}
|
}
|
||||||
assert.Equal(t, len(nodes.Children), 2)
|
assert.Len(t, nodes.Children, 2)
|
||||||
for i, v := range nodes.Children {
|
for i, v := range nodes.Children {
|
||||||
assert.Equal(t, v.Original, expected[i])
|
assert.Equal(t, expected[i], v.Original)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/strslice"
|
"github.com/docker/docker/api/types/strslice"
|
||||||
"github.com/docker/docker/builder"
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type commandWithFunction struct {
|
type commandWithFunction struct {
|
||||||
|
@ -137,13 +137,13 @@ func TestEnv2Variables(t *testing.T) {
|
||||||
|
|
||||||
args := []string{"var1", "val1", "var2", "val2"}
|
args := []string{"var1", "val1", "var2", "val2"}
|
||||||
err := env(b, args, nil, "")
|
err := env(b, args, nil, "")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
fmt.Sprintf("%s=%s", args[0], args[1]),
|
fmt.Sprintf("%s=%s", args[0], args[1]),
|
||||||
fmt.Sprintf("%s=%s", args[2], args[3]),
|
fmt.Sprintf("%s=%s", args[2], args[3]),
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, b.runConfig.Env, expected)
|
assert.Equal(t, expected, b.runConfig.Env)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
|
func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
|
||||||
|
@ -153,13 +153,13 @@ func TestEnvValueWithExistingRunConfigEnv(t *testing.T) {
|
||||||
|
|
||||||
args := []string{"var1", "val1"}
|
args := []string{"var1", "val1"}
|
||||||
err := env(b, args, nil, "")
|
err := env(b, args, nil, "")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := []string{
|
expected := []string{
|
||||||
fmt.Sprintf("%s=%s", args[0], args[1]),
|
fmt.Sprintf("%s=%s", args[0], args[1]),
|
||||||
"var2=fromenv",
|
"var2=fromenv",
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, b.runConfig.Env, expected)
|
assert.Equal(t, expected, b.runConfig.Env)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaintainer(t *testing.T) {
|
func TestMaintainer(t *testing.T) {
|
||||||
|
@ -215,40 +215,40 @@ func TestFromScratch(t *testing.T) {
|
||||||
err := from(b, []string{"scratch"}, nil, "")
|
err := from(b, []string{"scratch"}, nil, "")
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
assert.Error(t, err, "Windows does not support FROM scratch")
|
assert.EqualError(t, err, "Windows does not support FROM scratch")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, b.image, "")
|
assert.Equal(t, "", b.image)
|
||||||
assert.Equal(t, b.noBaseImage, true)
|
assert.Equal(t, true, b.noBaseImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromWithArg(t *testing.T) {
|
func TestFromWithArg(t *testing.T) {
|
||||||
tag, expected := ":sometag", "expectedthisid"
|
tag, expected := ":sometag", "expectedthisid"
|
||||||
|
|
||||||
getImage := func(name string) (builder.Image, error) {
|
getImage := func(name string) (builder.Image, error) {
|
||||||
assert.Equal(t, name, "alpine"+tag)
|
assert.Equal(t, "alpine"+tag, name)
|
||||||
return &mockImage{id: "expectedthisid"}, nil
|
return &mockImage{id: "expectedthisid"}, nil
|
||||||
}
|
}
|
||||||
b := newBuilderWithMockBackend()
|
b := newBuilderWithMockBackend()
|
||||||
b.docker.(*MockBackend).getImageOnBuildFunc = getImage
|
b.docker.(*MockBackend).getImageOnBuildFunc = getImage
|
||||||
|
|
||||||
assert.NilError(t, arg(b, []string{"THETAG=" + tag}, nil, ""))
|
assert.NoError(t, arg(b, []string{"THETAG=" + tag}, nil, ""))
|
||||||
err := from(b, []string{"alpine${THETAG}"}, nil, "")
|
err := from(b, []string{"alpine${THETAG}"}, nil, "")
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, b.image, expected)
|
assert.Equal(t, expected, b.image)
|
||||||
assert.Equal(t, b.from.ImageID(), expected)
|
assert.Equal(t, expected, b.from.ImageID())
|
||||||
assert.Equal(t, len(b.buildArgs.GetAllAllowed()), 0)
|
assert.Len(t, b.buildArgs.GetAllAllowed(), 0)
|
||||||
assert.Equal(t, len(b.buildArgs.GetAllMeta()), 1)
|
assert.Len(t, b.buildArgs.GetAllMeta(), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFromWithUndefinedArg(t *testing.T) {
|
func TestFromWithUndefinedArg(t *testing.T) {
|
||||||
tag, expected := "sometag", "expectedthisid"
|
tag, expected := "sometag", "expectedthisid"
|
||||||
|
|
||||||
getImage := func(name string) (builder.Image, error) {
|
getImage := func(name string) (builder.Image, error) {
|
||||||
assert.Equal(t, name, "alpine")
|
assert.Equal(t, "alpine", name)
|
||||||
return &mockImage{id: "expectedthisid"}, nil
|
return &mockImage{id: "expectedthisid"}, nil
|
||||||
}
|
}
|
||||||
b := newBuilderWithMockBackend()
|
b := newBuilderWithMockBackend()
|
||||||
|
@ -256,8 +256,8 @@ func TestFromWithUndefinedArg(t *testing.T) {
|
||||||
b.options.BuildArgs = map[string]*string{"THETAG": &tag}
|
b.options.BuildArgs = map[string]*string{"THETAG": &tag}
|
||||||
|
|
||||||
err := from(b, []string{"alpine${THETAG}"}, nil, "")
|
err := from(b, []string{"alpine${THETAG}"}, nil, "")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, b.image, expected)
|
assert.Equal(t, expected, b.image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOnbuildIllegalTriggers(t *testing.T) {
|
func TestOnbuildIllegalTriggers(t *testing.T) {
|
||||||
|
@ -508,11 +508,11 @@ func TestArg(t *testing.T) {
|
||||||
argDef := fmt.Sprintf("%s=%s", argName, argVal)
|
argDef := fmt.Sprintf("%s=%s", argName, argVal)
|
||||||
|
|
||||||
err := arg(b, []string{argDef}, nil, "")
|
err := arg(b, []string{argDef}, nil, "")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := map[string]string{argName: argVal}
|
expected := map[string]string{argName: argVal}
|
||||||
allowed := b.buildArgs.GetAllAllowed()
|
allowed := b.buildArgs.GetAllAllowed()
|
||||||
assert.DeepEqual(t, allowed, expected)
|
assert.Equal(t, expected, allowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShell(t *testing.T) {
|
func TestShell(t *testing.T) {
|
||||||
|
|
|
@ -7,7 +7,8 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/builder"
|
"github.com/docker/docker/builder"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEmptyDockerfile(t *testing.T) {
|
func TestEmptyDockerfile(t *testing.T) {
|
||||||
|
@ -38,7 +39,7 @@ func TestDockerfileOutsideTheBuildContext(t *testing.T) {
|
||||||
contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test")
|
contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test")
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
expectedError := "Forbidden path outside the build context"
|
expectedError := "Forbidden path outside the build context: ../../Dockerfile ()"
|
||||||
|
|
||||||
readAndCheckDockerfile(t, "DockerfileOutsideTheBuildContext", contextDir, "../../Dockerfile", expectedError)
|
readAndCheckDockerfile(t, "DockerfileOutsideTheBuildContext", contextDir, "../../Dockerfile", expectedError)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,7 @@ func TestNonExistingDockerfile(t *testing.T) {
|
||||||
|
|
||||||
func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) {
|
func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) {
|
||||||
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err = tarStream.Close(); err != nil {
|
if err = tarStream.Close(); err != nil {
|
||||||
|
@ -63,7 +64,7 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath,
|
||||||
}()
|
}()
|
||||||
|
|
||||||
context, err := builder.MakeTarSumContext(tarStream)
|
context, err := builder.MakeTarSumContext(tarStream)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err = context.Close(); err != nil {
|
if err = context.Close(); err != nil {
|
||||||
|
@ -78,5 +79,5 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath,
|
||||||
b := &Builder{options: options, context: context}
|
b := &Builder{options: options, context: context}
|
||||||
|
|
||||||
_, err = b.readAndParseDockerfile()
|
_, err = b.readAndParseDockerfile()
|
||||||
assert.Error(t, err, expectedError)
|
assert.EqualError(t, err, expectedError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseNameValOldFormat(t *testing.T) {
|
func TestParseNameValOldFormat(t *testing.T) {
|
||||||
directive := Directive{}
|
directive := Directive{}
|
||||||
node, err := parseNameVal("foo bar", "LABEL", &directive)
|
node, err := parseNameVal("foo bar", "LABEL", &directive)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := &Node{
|
expected := &Node{
|
||||||
Value: "foo",
|
Value: "foo",
|
||||||
Next: &Node{Value: "bar"},
|
Next: &Node{Value: "bar"},
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, node, expected)
|
assert.Equal(t, expected, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseNameValNewFormat(t *testing.T) {
|
func TestParseNameValNewFormat(t *testing.T) {
|
||||||
directive := Directive{}
|
directive := Directive{}
|
||||||
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
|
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := &Node{
|
expected := &Node{
|
||||||
Value: "foo",
|
Value: "foo",
|
||||||
|
@ -34,7 +35,7 @@ func TestParseNameValNewFormat(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, node, expected)
|
assert.Equal(t, expected, node)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeFromLabels(t *testing.T) {
|
func TestNodeFromLabels(t *testing.T) {
|
||||||
|
@ -60,6 +61,6 @@ func TestNodeFromLabels(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
node := NodeFromLabels(labels)
|
node := NodeFromLabels(labels)
|
||||||
assert.DeepEqual(t, node, expected)
|
assert.Equal(t, expected, node)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,8 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testDir = "testfiles"
|
const testDir = "testfiles"
|
||||||
|
@ -18,11 +19,11 @@ const testFileLineInfo = "testfile-line/Dockerfile"
|
||||||
|
|
||||||
func getDirs(t *testing.T, dir string) []string {
|
func getDirs(t *testing.T, dir string) []string {
|
||||||
f, err := os.Open(dir)
|
f, err := os.Open(dir)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
dirs, err := f.Readdirnames(0)
|
dirs, err := f.Readdirnames(0)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
return dirs
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,11 +32,11 @@ func TestTestNegative(t *testing.T) {
|
||||||
dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile")
|
dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile")
|
||||||
|
|
||||||
df, err := os.Open(dockerfile)
|
df, err := os.Open(dockerfile)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
defer df.Close()
|
defer df.Close()
|
||||||
|
|
||||||
_, err = Parse(df)
|
_, err = Parse(df)
|
||||||
assert.Error(t, err, "")
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,21 +46,21 @@ func TestTestData(t *testing.T) {
|
||||||
resultfile := filepath.Join(testDir, dir, "result")
|
resultfile := filepath.Join(testDir, dir, "result")
|
||||||
|
|
||||||
df, err := os.Open(dockerfile)
|
df, err := os.Open(dockerfile)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
defer df.Close()
|
defer df.Close()
|
||||||
|
|
||||||
result, err := Parse(df)
|
result, err := Parse(df)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(resultfile)
|
content, err := ioutil.ReadFile(resultfile)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// CRLF --> CR to match Unix behavior
|
// CRLF --> CR to match Unix behavior
|
||||||
content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1)
|
content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, result.AST.Dump()+"\n", string(content), "In "+dockerfile)
|
assert.Contains(t, result.AST.Dump()+"\n", string(content), "In "+dockerfile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,24 +102,24 @@ func TestParseWords(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
words := parseWords(test["input"][0], NewDefaultDirective())
|
words := parseWords(test["input"][0], NewDefaultDirective())
|
||||||
assert.DeepEqual(t, words, test["expect"])
|
assert.Equal(t, test["expect"], words)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLineInformation(t *testing.T) {
|
func TestLineInformation(t *testing.T) {
|
||||||
df, err := os.Open(testFileLineInfo)
|
df, err := os.Open(testFileLineInfo)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
defer df.Close()
|
defer df.Close()
|
||||||
|
|
||||||
result, err := Parse(df)
|
result, err := Parse(df)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ast := result.AST
|
ast := result.AST
|
||||||
if ast.StartLine != 5 || ast.endLine != 31 {
|
if ast.StartLine != 5 || ast.endLine != 31 {
|
||||||
fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 5, 31, ast.StartLine, ast.endLine)
|
fmt.Fprintf(os.Stderr, "Wrong root line information: expected(%d-%d), actual(%d-%d)\n", 5, 31, ast.StartLine, ast.endLine)
|
||||||
t.Fatal("Root line information doesn't match result.")
|
t.Fatal("Root line information doesn't match result.")
|
||||||
}
|
}
|
||||||
assert.Equal(t, len(ast.Children), 3)
|
assert.Len(t, ast.Children, 3)
|
||||||
expected := [][]int{
|
expected := [][]int{
|
||||||
{5, 5},
|
{5, 5},
|
||||||
{11, 12},
|
{11, 12},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestShellParser4EnvVars(t *testing.T) {
|
func TestShellParser4EnvVars(t *testing.T) {
|
||||||
|
@ -15,7 +15,7 @@ func TestShellParser4EnvVars(t *testing.T) {
|
||||||
lineCount := 0
|
lineCount := 0
|
||||||
|
|
||||||
file, err := os.Open(fn)
|
file, err := os.Open(fn)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
|
@ -36,7 +36,7 @@ func TestShellParser4EnvVars(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
words := strings.Split(line, "|")
|
words := strings.Split(line, "|")
|
||||||
assert.Equal(t, len(words), 3)
|
assert.Len(t, words, 3)
|
||||||
|
|
||||||
platform := strings.TrimSpace(words[0])
|
platform := strings.TrimSpace(words[0])
|
||||||
source := strings.TrimSpace(words[1])
|
source := strings.TrimSpace(words[1])
|
||||||
|
@ -51,9 +51,9 @@ func TestShellParser4EnvVars(t *testing.T) {
|
||||||
((platform == "U" || platform == "A") && runtime.GOOS != "windows") {
|
((platform == "U" || platform == "A") && runtime.GOOS != "windows") {
|
||||||
newWord, err := ProcessWord(source, envs, '\\')
|
newWord, err := ProcessWord(source, envs, '\\')
|
||||||
if expected == "error" {
|
if expected == "error" {
|
||||||
assert.Error(t, err, "")
|
assert.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, newWord, expected)
|
assert.Equal(t, newWord, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadFileV01Success(t *testing.T) {
|
func TestLoadFileV01Success(t *testing.T) {
|
||||||
|
@ -25,9 +25,9 @@ func TestLoadFileV01Success(t *testing.T) {
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
bundle, err := LoadFile(reader)
|
bundle, err := LoadFile(reader)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, bundle.Version, "0.1")
|
assert.Equal(t, "0.1", bundle.Version)
|
||||||
assert.Equal(t, len(bundle.Services), 2)
|
assert.Len(t, bundle.Services, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadFileSyntaxError(t *testing.T) {
|
func TestLoadFileSyntaxError(t *testing.T) {
|
||||||
|
@ -37,7 +37,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
_, err := LoadFile(reader)
|
_, err := LoadFile(reader)
|
||||||
assert.Error(t, err, "syntax error at byte 37: invalid character 'u'")
|
assert.EqualError(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadFileTypeError(t *testing.T) {
|
func TestLoadFileTypeError(t *testing.T) {
|
||||||
|
@ -52,7 +52,7 @@ func TestLoadFileTypeError(t *testing.T) {
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
_, err := LoadFile(reader)
|
_, err := LoadFile(reader)
|
||||||
assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string")
|
assert.EqualError(t, err, "Unexpected type at byte 94. Expected []string but received string.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrint(t *testing.T) {
|
func TestPrint(t *testing.T) {
|
||||||
|
@ -66,7 +66,7 @@ func TestPrint(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.NilError(t, Print(&buffer, bundle))
|
assert.NoError(t, Print(&buffer, bundle))
|
||||||
output := buffer.String()
|
output := buffer.String()
|
||||||
assert.Contains(t, output, "\"Image\": \"image\"")
|
assert.Contains(t, output, "\"Image\": \"image\"")
|
||||||
assert.Contains(t, output,
|
assert.Contains(t, output,
|
||||||
|
|
|
@ -13,11 +13,12 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
networktypes "github.com/docker/docker/api/types/network"
|
networktypes "github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/runconfig"
|
"github.com/docker/docker/runconfig"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateAttach(t *testing.T) {
|
func TestValidateAttach(t *testing.T) {
|
||||||
|
@ -243,23 +244,23 @@ func TestParseWithMacAddress(t *testing.T) {
|
||||||
func TestParseWithMemory(t *testing.T) {
|
func TestParseWithMemory(t *testing.T) {
|
||||||
invalidMemory := "--memory=invalid"
|
invalidMemory := "--memory=invalid"
|
||||||
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
||||||
assert.Error(t, err, invalidMemory)
|
testutil.ErrorContains(t, err, invalidMemory)
|
||||||
|
|
||||||
_, hostconfig := mustParse(t, "--memory=1G")
|
_, hostconfig := mustParse(t, "--memory=1G")
|
||||||
assert.Equal(t, hostconfig.Memory, int64(1073741824))
|
assert.Equal(t, int64(1073741824), hostconfig.Memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithMemorySwap(t *testing.T) {
|
func TestParseWithMemorySwap(t *testing.T) {
|
||||||
invalidMemory := "--memory-swap=invalid"
|
invalidMemory := "--memory-swap=invalid"
|
||||||
|
|
||||||
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
||||||
assert.Error(t, err, invalidMemory)
|
testutil.ErrorContains(t, err, invalidMemory)
|
||||||
|
|
||||||
_, hostconfig := mustParse(t, "--memory-swap=1G")
|
_, hostconfig := mustParse(t, "--memory-swap=1G")
|
||||||
assert.Equal(t, hostconfig.MemorySwap, int64(1073741824))
|
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap)
|
||||||
|
|
||||||
_, hostconfig = mustParse(t, "--memory-swap=-1")
|
_, hostconfig = mustParse(t, "--memory-swap=-1")
|
||||||
assert.Equal(t, hostconfig.MemorySwap, int64(-1))
|
assert.Equal(t, int64(-1), hostconfig.MemorySwap)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseHostname(t *testing.T) {
|
func TestParseHostname(t *testing.T) {
|
||||||
|
|
|
@ -4,13 +4,13 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildContainerListOptions(t *testing.T) {
|
func TestBuildContainerListOptions(t *testing.T) {
|
||||||
filters := opts.NewFilterOpt()
|
filters := opts.NewFilterOpt()
|
||||||
assert.NilError(t, filters.Set("foo=bar"))
|
assert.NoError(t, filters.Set("foo=bar"))
|
||||||
assert.NilError(t, filters.Set("baz=foo"))
|
assert.NoError(t, filters.Set("baz=foo"))
|
||||||
|
|
||||||
contexts := []struct {
|
contexts := []struct {
|
||||||
psOpts *psOptions
|
psOpts *psOptions
|
||||||
|
@ -101,12 +101,12 @@ func TestBuildContainerListOptions(t *testing.T) {
|
||||||
|
|
||||||
for _, c := range contexts {
|
for _, c := range contexts {
|
||||||
options, err := buildContainerListOptions(c.psOpts)
|
options, err := buildContainerListOptions(c.psOpts)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, c.expectedAll, options.All)
|
assert.Equal(t, c.expectedAll, options.All)
|
||||||
assert.Equal(t, c.expectedSize, options.Size)
|
assert.Equal(t, c.expectedSize, options.Size)
|
||||||
assert.Equal(t, c.expectedLimit, options.Limit)
|
assert.Equal(t, c.expectedLimit, options.Limit)
|
||||||
assert.Equal(t, options.Filters.Len(), len(c.expectedFilters))
|
assert.Equal(t, len(c.expectedFilters), options.Filters.Len())
|
||||||
|
|
||||||
for k, v := range c.expectedFilters {
|
for k, v := range c.expectedFilters {
|
||||||
f := options.Filters
|
f := options.Filters
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContainerPsContext(t *testing.T) {
|
func TestContainerPsContext(t *testing.T) {
|
||||||
|
@ -245,9 +245,9 @@ conta "ubuntu" 24 hours ago//.FOOBAR_BAR
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := ContainerWrite(testcase.context, containers)
|
err := ContainerWrite(testcase.context, containers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ func TestContainerContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ func TestContainerContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, containers[i].ID)
|
assert.Equal(t, containers[i].ID, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiffContextFormatWrite(t *testing.T) {
|
func TestDiffContextFormatWrite(t *testing.T) {
|
||||||
|
@ -51,9 +51,9 @@ D: /usr/app/old_app.js
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := DiffWrite(testcase.context, diffs)
|
err := DiffWrite(testcase.context, diffs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDiskUsageContextFormatWrite(t *testing.T) {
|
func TestDiskUsageContextFormatWrite(t *testing.T) {
|
||||||
|
@ -117,9 +117,9 @@ reclaimable: 0B
|
||||||
out := bytes.NewBufferString("")
|
out := bytes.NewBufferString("")
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
if err := testcase.context.Write(); err != nil {
|
if err := testcase.context.Write(); err != nil {
|
||||||
assert.Equal(t, err.Error(), testcase.expected)
|
assert.Equal(t, testcase.expected, err.Error())
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestImageContext(t *testing.T) {
|
func TestImageContext(t *testing.T) {
|
||||||
|
@ -265,9 +265,9 @@ image_id: imageID3
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := ImageWrite(testcase.context, images)
|
err := ImageWrite(testcase.context, images)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ func TestImageContextWriteWithNoImage(t *testing.T) {
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, context := range contexts {
|
||||||
ImageWrite(context.context, images)
|
ImageWrite(context.context, images)
|
||||||
assert.Equal(t, out.String(), context.expected)
|
assert.Equal(t, context.expected, out.String())
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNetworkContext(t *testing.T) {
|
func TestNetworkContext(t *testing.T) {
|
||||||
|
@ -160,9 +160,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := NetworkWrite(testcase.context, networks)
|
err := NetworkWrite(testcase.context, networks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ func TestNetworkContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +208,6 @@ func TestNetworkContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, networks[i].ID)
|
assert.Equal(t, networks[i].ID, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeContext(t *testing.T) {
|
func TestNodeContext(t *testing.T) {
|
||||||
|
@ -135,9 +135,9 @@ foobar_bar
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := NodeWrite(testcase.context, nodes, types.Info{})
|
err := NodeWrite(testcase.context, nodes, types.Info{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func TestNodeContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +183,6 @@ func TestNodeContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, nodes[i].ID)
|
assert.Equal(t, nodes[i].ID, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPluginContext(t *testing.T) {
|
func TestPluginContext(t *testing.T) {
|
||||||
|
@ -131,9 +131,9 @@ foobar_bar
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := PluginWrite(testcase.context, plugins)
|
err := PluginWrite(testcase.context, plugins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func TestPluginContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +177,6 @@ func TestPluginContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, plugins[i].ID)
|
assert.Equal(t, plugins[i].ID, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretContextFormatWrite(t *testing.T) {
|
func TestSecretContextFormatWrite(t *testing.T) {
|
||||||
|
@ -55,9 +55,9 @@ id_rsa
|
||||||
out := bytes.NewBufferString("")
|
out := bytes.NewBufferString("")
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
if err := SecretWrite(testcase.context, secrets); err != nil {
|
if err := SecretWrite(testcase.context, secrets); err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceContextWrite(t *testing.T) {
|
func TestServiceContextWrite(t *testing.T) {
|
||||||
|
@ -137,9 +137,9 @@ bar
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := ServiceListWrite(testcase.context, services, info)
|
err := ServiceListWrite(testcase.context, services, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ func TestServiceContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestServiceContextWriteJSONField(t *testing.T) {
|
func TestServiceContextWriteJSONField(t *testing.T) {
|
||||||
|
@ -234,6 +234,6 @@ func TestServiceContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, services[i].Spec.Name)
|
assert.Equal(t, services[i].Spec.Name, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContainerStatsContext(t *testing.T) {
|
func TestContainerStatsContext(t *testing.T) {
|
||||||
|
@ -116,9 +116,9 @@ container2 --
|
||||||
te.context.Output = &out
|
te.context.Output = &out
|
||||||
err := ContainerStatsWrite(te.context, stats, "linux")
|
err := ContainerStatsWrite(te.context, stats, "linux")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, te.expected)
|
assert.EqualError(t, err, te.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), te.expected)
|
assert.Equal(t, te.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,9 +182,9 @@ container2 -- --
|
||||||
te.context.Output = &out
|
te.context.Output = &out
|
||||||
err := ContainerStatsWrite(te.context, stats, "windows")
|
err := ContainerStatsWrite(te.context, stats, "windows")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, te.expected)
|
assert.EqualError(t, err, te.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), te.expected)
|
assert.Equal(t, te.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
||||||
|
|
||||||
for _, context := range contexts {
|
for _, context := range contexts {
|
||||||
ContainerStatsWrite(context.context, []StatsEntry{}, "windows")
|
ContainerStatsWrite(context.context, []StatsEntry{}, "windows")
|
||||||
assert.Equal(t, out.String(), context.expected)
|
assert.Equal(t, context.expected, out.String())
|
||||||
// Clean buffer
|
// Clean buffer
|
||||||
out.Reset()
|
out.Reset()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTaskContextWrite(t *testing.T) {
|
func TestTaskContextWrite(t *testing.T) {
|
||||||
|
@ -76,9 +76,9 @@ foobar_bar foo2
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := TaskWrite(testcase.context, tasks, names, nodes)
|
err := TaskWrite(testcase.context, tasks, names, nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,6 @@ func TestTaskContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, tasks[i].ID)
|
assert.Equal(t, tasks[i].ID, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumeContext(t *testing.T) {
|
func TestVolumeContext(t *testing.T) {
|
||||||
|
@ -131,9 +131,9 @@ foobar_bar
|
||||||
testcase.context.Output = out
|
testcase.context.Output = out
|
||||||
err := VolumeWrite(testcase.context, volumes)
|
err := VolumeWrite(testcase.context, volumes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.Error(t, err, testcase.expected)
|
assert.EqualError(t, err, testcase.expected)
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, out.String(), testcase.expected)
|
assert.Equal(t, testcase.expected, out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func TestVolumeContextWriteJSON(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
if err := json.Unmarshal([]byte(line), &m); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, m, expectedJSONs[i])
|
assert.Equal(t, expectedJSONs[i], m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +178,6 @@ func TestVolumeContextWriteJSONField(t *testing.T) {
|
||||||
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
if err := json.Unmarshal([]byte(line), &s); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, s, volumes[i].Name)
|
assert.Equal(t, volumes[i].Name, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func TestResolveError(t *testing.T) {
|
||||||
idResolver := New(cli, false)
|
idResolver := New(cli, false)
|
||||||
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
|
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
|
||||||
|
|
||||||
assert.Error(t, err, "unsupported type")
|
assert.EqualError(t, err, "unsupported type")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveWithNoResolveOption(t *testing.T) {
|
func TestResolveWithNoResolveOption(t *testing.T) {
|
||||||
|
@ -40,9 +40,9 @@ func TestResolveWithNoResolveOption(t *testing.T) {
|
||||||
idResolver := New(cli, true)
|
idResolver := New(cli, true)
|
||||||
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
|
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, "nodeID")
|
assert.Equal(t, "nodeID", id)
|
||||||
assert.Equal(t, resolved, false)
|
assert.False(t, resolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveWithCache(t *testing.T) {
|
func TestResolveWithCache(t *testing.T) {
|
||||||
|
@ -59,11 +59,11 @@ func TestResolveWithCache(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
|
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, "node-foo")
|
assert.Equal(t, "node-foo", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, inspectCounter, 1)
|
assert.Equal(t, 1, inspectCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResolveNode(t *testing.T) {
|
func TestResolveNode(t *testing.T) {
|
||||||
|
@ -103,8 +103,8 @@ func TestResolveNode(t *testing.T) {
|
||||||
idResolver := New(cli, false)
|
idResolver := New(cli, false)
|
||||||
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
|
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, tc.expectedID)
|
assert.Equal(t, tc.expectedID, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ func TestResolveService(t *testing.T) {
|
||||||
idResolver := New(cli, false)
|
idResolver := New(cli, false)
|
||||||
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
|
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, tc.expectedID)
|
assert.Equal(t, tc.expectedID, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeDemoteErrors(t *testing.T) {
|
func TestNodeDemoteErrors(t *testing.T) {
|
||||||
|
@ -47,7 +48,7 @@ func TestNodeDemoteErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID"})
|
cmd.SetArgs([]string{"nodeID"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeDemoteMultipleNode(t *testing.T) {
|
func TestNodeDemoteMultipleNode(t *testing.T) {
|
||||||
|
@ -84,5 +85,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeInspectErrors(t *testing.T) {
|
func TestNodeInspectErrors(t *testing.T) {
|
||||||
|
@ -77,7 +78,7 @@ func TestNodeInspectErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +116,9 @@ func TestNodeInspectPretty(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID"})
|
cmd.SetArgs([]string{"nodeID"})
|
||||||
cmd.Flags().Set("pretty", "true")
|
cmd.Flags().Set("pretty", "true")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeListErrorOnAPIFailure(t *testing.T) {
|
func TestNodeListErrorOnAPIFailure(t *testing.T) {
|
||||||
|
@ -50,7 +50,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
assert.EqualError(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ func TestNodeList(t *testing.T) {
|
||||||
}, buf)
|
}, buf)
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), `nodeID1 * nodeHostname1 Ready Active Leader`)
|
assert.Contains(t, buf.String(), `nodeID1 * nodeHostname1 Ready Active Leader`)
|
||||||
assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`)
|
assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`)
|
||||||
assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`)
|
assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`)
|
||||||
|
@ -92,7 +92,7 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
cmd.Flags().Set("quiet", "true")
|
cmd.Flags().Set("quiet", "true")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), "nodeID")
|
assert.Contains(t, buf.String(), "nodeID")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func TestNodeListContainsHostname(t *testing.T) {
|
||||||
cli := test.NewFakeCli(&fakeClient{}, buf)
|
cli := test.NewFakeCli(&fakeClient{}, buf)
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), "HOSTNAME")
|
assert.Contains(t, buf.String(), "HOSTNAME")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ func TestNodeListDefaultFormat(t *testing.T) {
|
||||||
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
|
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), `nodeID1: nodeHostname1 Ready/Leader`)
|
assert.Contains(t, buf.String(), `nodeID1: nodeHostname1 Ready/Leader`)
|
||||||
assert.Contains(t, buf.String(), `nodeID2: nodeHostname2 Ready/Reachable`)
|
assert.Contains(t, buf.String(), `nodeID2: nodeHostname2 Ready/Reachable`)
|
||||||
assert.Contains(t, buf.String(), `nodeID3: nodeHostname3 Ready`)
|
assert.Contains(t, buf.String(), `nodeID3: nodeHostname3 Ready`)
|
||||||
|
@ -156,7 +156,7 @@ func TestNodeListFormat(t *testing.T) {
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")
|
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), `nodeHostname1: Leader`)
|
assert.Contains(t, buf.String(), `nodeHostname1: Leader`)
|
||||||
assert.Contains(t, buf.String(), `nodeHostname2: Reachable`)
|
assert.Contains(t, buf.String(), `nodeHostname2: Reachable`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodePromoteErrors(t *testing.T) {
|
func TestNodePromoteErrors(t *testing.T) {
|
||||||
|
@ -47,7 +48,7 @@ func TestNodePromoteErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ func TestNodePromoteNoChange(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID"})
|
cmd.SetArgs([]string{"nodeID"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodePromoteMultipleNode(t *testing.T) {
|
func TestNodePromoteMultipleNode(t *testing.T) {
|
||||||
|
@ -84,5 +85,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodePsErrors(t *testing.T) {
|
func TestNodePsErrors(t *testing.T) {
|
||||||
|
@ -62,7 +63,7 @@ func TestNodePsErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
assert.EqualError(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,9 +126,9 @@ func TestNodePs(t *testing.T) {
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-ps.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-ps.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeRemoveErrors(t *testing.T) {
|
func TestNodeRemoveErrors(t *testing.T) {
|
||||||
|
@ -35,7 +36,7 @@ func TestNodeRemoveErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,5 +44,5 @@ func TestNodeRemoveMultiple(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
|
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
|
||||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeUpdateErrors(t *testing.T) {
|
func TestNodeUpdateErrors(t *testing.T) {
|
||||||
|
@ -67,7 +68,7 @@ func TestNodeUpdateErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +168,6 @@ func TestNodeUpdate(t *testing.T) {
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const secretDataFile = "secret-create-with-name.golden"
|
const secretDataFile = "secret-create-with-name.golden"
|
||||||
|
@ -47,7 +48,7 @@ func TestSecretCreateErrors(t *testing.T) {
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +72,10 @@ func TestSecretCreateWithName(t *testing.T) {
|
||||||
|
|
||||||
cmd := newSecretCreateCommand(cli)
|
cmd := newSecretCreateCommand(cli)
|
||||||
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
expected := golden.Get(t, actual, secretDataFile)
|
expected := golden.Get(t, actual, secretDataFile)
|
||||||
assert.Equal(t, string(actual), string(expected))
|
assert.Equal(t, expected, actual)
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name)
|
assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretCreateWithLabels(t *testing.T) {
|
func TestSecretCreateWithLabels(t *testing.T) {
|
||||||
|
@ -105,8 +106,8 @@ func TestSecretCreateWithLabels(t *testing.T) {
|
||||||
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
||||||
cmd.Flags().Set("label", "lbl1=Label-foo")
|
cmd.Flags().Set("label", "lbl1=Label-foo")
|
||||||
cmd.Flags().Set("label", "lbl2=Label-bar")
|
cmd.Flags().Set("label", "lbl2=Label-bar")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name)
|
assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareMap(actual map[string]string, expected map[string]string) bool {
|
func compareMap(actual map[string]string, expected map[string]string) bool {
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretInspectErrors(t *testing.T) {
|
func TestSecretInspectErrors(t *testing.T) {
|
||||||
|
@ -62,7 +63,7 @@ func TestSecretInspectErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +101,10 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
|
||||||
}, buf),
|
}, buf),
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +142,9 @@ func TestSecretInspectWithFormat(t *testing.T) {
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.Flags().Set("format", tc.format)
|
cmd.Flags().Set("format", tc.format)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretListErrors(t *testing.T) {
|
func TestSecretListErrors(t *testing.T) {
|
||||||
|
@ -43,7 +44,7 @@ func TestSecretListErrors(t *testing.T) {
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +71,10 @@ func TestSecretList(t *testing.T) {
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newSecretListCommand(cli)
|
cmd := newSecretListCommand(cli)
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "secret-list.golden")
|
expected := golden.Get(t, []byte(actual), "secret-list.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretListWithQuietOption(t *testing.T) {
|
func TestSecretListWithQuietOption(t *testing.T) {
|
||||||
|
@ -91,10 +92,10 @@ func TestSecretListWithQuietOption(t *testing.T) {
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newSecretListCommand(cli)
|
cmd := newSecretListCommand(cli)
|
||||||
cmd.Flags().Set("quiet", "true")
|
cmd.Flags().Set("quiet", "true")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "secret-list-with-quiet-option.golden")
|
expected := golden.Get(t, []byte(actual), "secret-list-with-quiet-option.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretListWithConfigFormat(t *testing.T) {
|
func TestSecretListWithConfigFormat(t *testing.T) {
|
||||||
|
@ -113,10 +114,10 @@ func TestSecretListWithConfigFormat(t *testing.T) {
|
||||||
SecretFormat: "{{ .Name }} {{ .Labels }}",
|
SecretFormat: "{{ .Name }} {{ .Labels }}",
|
||||||
})
|
})
|
||||||
cmd := newSecretListCommand(cli)
|
cmd := newSecretListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "secret-list-with-config-format.golden")
|
expected := golden.Get(t, []byte(actual), "secret-list-with-config-format.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretListWithFormat(t *testing.T) {
|
func TestSecretListWithFormat(t *testing.T) {
|
||||||
|
@ -133,18 +134,18 @@ func TestSecretListWithFormat(t *testing.T) {
|
||||||
}, buf)
|
}, buf)
|
||||||
cmd := newSecretListCommand(cli)
|
cmd := newSecretListCommand(cli)
|
||||||
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
|
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "secret-list-with-format.golden")
|
expected := golden.Get(t, []byte(actual), "secret-list-with-format.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretListWithFilter(t *testing.T) {
|
func TestSecretListWithFilter(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cli := test.NewFakeCli(&fakeClient{
|
cli := test.NewFakeCli(&fakeClient{
|
||||||
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
|
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
|
||||||
assert.Equal(t, options.Filters.Get("name")[0], "foo")
|
assert.Equal(t, "foo", options.Filters.Get("name")[0], "foo")
|
||||||
assert.Equal(t, options.Filters.Get("label")[0], "lbl1=Label-bar")
|
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
|
||||||
return []swarm.Secret{
|
return []swarm.Secret{
|
||||||
*Secret(SecretID("ID-foo"),
|
*Secret(SecretID("ID-foo"),
|
||||||
SecretName("foo"),
|
SecretName("foo"),
|
||||||
|
@ -165,8 +166,8 @@ func TestSecretListWithFilter(t *testing.T) {
|
||||||
cmd := newSecretListCommand(cli)
|
cmd := newSecretListCommand(cli)
|
||||||
cmd.Flags().Set("filter", "name=foo")
|
cmd.Flags().Set("filter", "name=foo")
|
||||||
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
|
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "secret-list-with-filter.golden")
|
expected := golden.Get(t, []byte(actual), "secret-list-with-filter.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretRemoveErrors(t *testing.T) {
|
func TestSecretRemoveErrors(t *testing.T) {
|
||||||
|
@ -38,7 +39,7 @@ func TestSecretRemoveErrors(t *testing.T) {
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,9 +55,9 @@ func TestSecretRemoveWithName(t *testing.T) {
|
||||||
}, buf)
|
}, buf)
|
||||||
cmd := newSecretRemoveCommand(cli)
|
cmd := newSecretRemoveCommand(cli)
|
||||||
cmd.SetArgs(names)
|
cmd.SetArgs(names)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.EqualStringSlice(t, strings.Split(strings.TrimSpace(buf.String()), "\n"), names)
|
assert.Equal(t, names, strings.Split(strings.TrimSpace(buf.String()), "\n"))
|
||||||
assert.EqualStringSlice(t, removedSecrets, names)
|
assert.Equal(t, names, removedSecrets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretRemoveContinueAfterError(t *testing.T) {
|
func TestSecretRemoveContinueAfterError(t *testing.T) {
|
||||||
|
@ -76,6 +77,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
|
||||||
|
|
||||||
cmd := newSecretRemoveCommand(cli)
|
cmd := newSecretRemoveCommand(cli)
|
||||||
cmd.SetArgs(names)
|
cmd.SetArgs(names)
|
||||||
assert.Error(t, cmd.Execute(), "error removing secret: foo")
|
assert.EqualError(t, cmd.Execute(), "error removing secret: foo")
|
||||||
assert.EqualStringSlice(t, removedSecrets, names)
|
assert.Equal(t, names, removedSecrets)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli/command/formatter"
|
"github.com/docker/docker/cli/command/formatter"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string {
|
func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string {
|
||||||
|
@ -136,5 +136,5 @@ func TestJSONFormatWithNoUpdateConfig(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
t.Logf("m2=%+v", m2)
|
t.Logf("m2=%+v", m2)
|
||||||
assert.DeepEqual(t, m2, m1)
|
assert.Equal(t, m1, m2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,71 +1,70 @@
|
||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemBytesString(t *testing.T) {
|
func TestMemBytesString(t *testing.T) {
|
||||||
var mem opts.MemBytes = 1048576
|
var mem opts.MemBytes = 1048576
|
||||||
assert.Equal(t, mem.String(), "1MiB")
|
assert.Equal(t, "1MiB", mem.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemBytesSetAndValue(t *testing.T) {
|
func TestMemBytesSetAndValue(t *testing.T) {
|
||||||
var mem opts.MemBytes
|
var mem opts.MemBytes
|
||||||
assert.NilError(t, mem.Set("5kb"))
|
assert.NoError(t, mem.Set("5kb"))
|
||||||
assert.Equal(t, mem.Value(), int64(5120))
|
assert.Equal(t, int64(5120), mem.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNanoCPUsString(t *testing.T) {
|
func TestNanoCPUsString(t *testing.T) {
|
||||||
var cpus opts.NanoCPUs = 6100000000
|
var cpus opts.NanoCPUs = 6100000000
|
||||||
assert.Equal(t, cpus.String(), "6.100")
|
assert.Equal(t, "6.100", cpus.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNanoCPUsSetAndValue(t *testing.T) {
|
func TestNanoCPUsSetAndValue(t *testing.T) {
|
||||||
var cpus opts.NanoCPUs
|
var cpus opts.NanoCPUs
|
||||||
assert.NilError(t, cpus.Set("0.35"))
|
assert.NoError(t, cpus.Set("0.35"))
|
||||||
assert.Equal(t, cpus.Value(), int64(350000000))
|
assert.Equal(t, int64(350000000), cpus.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationOptString(t *testing.T) {
|
func TestDurationOptString(t *testing.T) {
|
||||||
dur := time.Duration(300 * 10e8)
|
dur := time.Duration(300 * 10e8)
|
||||||
duration := DurationOpt{value: &dur}
|
duration := DurationOpt{value: &dur}
|
||||||
assert.Equal(t, duration.String(), "5m0s")
|
assert.Equal(t, "5m0s", duration.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationOptSetAndValue(t *testing.T) {
|
func TestDurationOptSetAndValue(t *testing.T) {
|
||||||
var duration DurationOpt
|
var duration DurationOpt
|
||||||
assert.NilError(t, duration.Set("300s"))
|
assert.NoError(t, duration.Set("300s"))
|
||||||
assert.Equal(t, *duration.Value(), time.Duration(300*10e8))
|
assert.Equal(t, time.Duration(300*10e8), *duration.Value())
|
||||||
assert.NilError(t, duration.Set("-300s"))
|
assert.NoError(t, duration.Set("-300s"))
|
||||||
assert.Equal(t, *duration.Value(), time.Duration(-300*10e8))
|
assert.Equal(t, time.Duration(-300*10e8), *duration.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPositiveDurationOptSetAndValue(t *testing.T) {
|
func TestPositiveDurationOptSetAndValue(t *testing.T) {
|
||||||
var duration PositiveDurationOpt
|
var duration PositiveDurationOpt
|
||||||
assert.NilError(t, duration.Set("300s"))
|
assert.NoError(t, duration.Set("300s"))
|
||||||
assert.Equal(t, *duration.Value(), time.Duration(300*10e8))
|
assert.Equal(t, time.Duration(300*10e8), *duration.Value())
|
||||||
assert.Error(t, duration.Set("-300s"), "cannot be negative")
|
assert.EqualError(t, duration.Set("-300s"), "duration cannot be negative")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUint64OptString(t *testing.T) {
|
func TestUint64OptString(t *testing.T) {
|
||||||
value := uint64(2345678)
|
value := uint64(2345678)
|
||||||
opt := Uint64Opt{value: &value}
|
opt := Uint64Opt{value: &value}
|
||||||
assert.Equal(t, opt.String(), "2345678")
|
assert.Equal(t, "2345678", opt.String())
|
||||||
|
|
||||||
opt = Uint64Opt{}
|
opt = Uint64Opt{}
|
||||||
assert.Equal(t, opt.String(), "")
|
assert.Equal(t, "", opt.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUint64OptSetAndValue(t *testing.T) {
|
func TestUint64OptSetAndValue(t *testing.T) {
|
||||||
var opt Uint64Opt
|
var opt Uint64Opt
|
||||||
assert.NilError(t, opt.Set("14445"))
|
assert.NoError(t, opt.Set("14445"))
|
||||||
assert.Equal(t, *opt.Value(), uint64(14445))
|
assert.Equal(t, uint64(14445), *opt.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
|
func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
|
||||||
|
@ -78,14 +77,14 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
|
||||||
retries: 10,
|
retries: 10,
|
||||||
}
|
}
|
||||||
config, err := opt.toHealthConfig()
|
config, err := opt.toHealthConfig()
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{
|
assert.Equal(t, &container.HealthConfig{
|
||||||
Test: []string{"CMD-SHELL", "curl"},
|
Test: []string{"CMD-SHELL", "curl"},
|
||||||
Interval: time.Second,
|
Interval: time.Second,
|
||||||
Timeout: time.Second,
|
Timeout: time.Second,
|
||||||
StartPeriod: time.Second,
|
StartPeriod: time.Second,
|
||||||
Retries: 10,
|
Retries: 10,
|
||||||
}), true)
|
}, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
|
func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
|
||||||
|
@ -93,10 +92,10 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
|
||||||
noHealthcheck: true,
|
noHealthcheck: true,
|
||||||
}
|
}
|
||||||
config, err := opt.toHealthConfig()
|
config, err := opt.toHealthConfig()
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{
|
assert.Equal(t, &container.HealthConfig{
|
||||||
Test: []string{"NONE"},
|
Test: []string{"NONE"},
|
||||||
}), true)
|
}, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
||||||
|
@ -105,5 +104,5 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
||||||
noHealthcheck: true,
|
noHealthcheck: true,
|
||||||
}
|
}
|
||||||
_, err := opt.toHealthConfig()
|
_, err := opt.toHealthConfig()
|
||||||
assert.Error(t, err, "--no-healthcheck conflicts with --health-* options")
|
assert.EqualError(t, err, "--no-healthcheck conflicts with --health-* options")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
mounttypes "github.com/docker/docker/api/types/mount"
|
mounttypes "github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ func TestUpdateServiceArgs(t *testing.T) {
|
||||||
cspec.Args = []string{"old", "args"}
|
cspec.Args = []string{"old", "args"}
|
||||||
|
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.EqualStringSlice(t, cspec.Args, []string{"the", "new args"})
|
assert.Equal(t, []string{"the", "new args"}, cspec.Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateLabels(t *testing.T) {
|
func TestUpdateLabels(t *testing.T) {
|
||||||
|
@ -37,9 +38,9 @@ func TestUpdateLabels(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLabels(flags, &labels)
|
updateLabels(flags, &labels)
|
||||||
assert.Equal(t, len(labels), 2)
|
assert.Len(t, labels, 2)
|
||||||
assert.Equal(t, labels["tokeep"], "value")
|
assert.Equal(t, "value", labels["tokeep"])
|
||||||
assert.Equal(t, labels["toadd"], "newlabel")
|
assert.Equal(t, "newlabel", labels["toadd"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
|
func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
|
||||||
|
@ -48,7 +49,7 @@ func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
|
||||||
|
|
||||||
labels := map[string]string{"foo": "theoldlabel"}
|
labels := map[string]string{"foo": "theoldlabel"}
|
||||||
updateLabels(flags, &labels)
|
updateLabels(flags, &labels)
|
||||||
assert.Equal(t, len(labels), 1)
|
assert.Len(t, labels, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePlacementConstraints(t *testing.T) {
|
func TestUpdatePlacementConstraints(t *testing.T) {
|
||||||
|
@ -61,9 +62,9 @@ func TestUpdatePlacementConstraints(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlacementConstraints(flags, placement)
|
updatePlacementConstraints(flags, placement)
|
||||||
assert.Equal(t, len(placement.Constraints), 2)
|
require.Len(t, placement.Constraints, 2)
|
||||||
assert.Equal(t, placement.Constraints[0], "container=tokeep")
|
assert.Equal(t, "container=tokeep", placement.Constraints[0])
|
||||||
assert.Equal(t, placement.Constraints[1], "node=toadd")
|
assert.Equal(t, "node=toadd", placement.Constraints[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePlacementPrefs(t *testing.T) {
|
func TestUpdatePlacementPrefs(t *testing.T) {
|
||||||
|
@ -87,9 +88,9 @@ func TestUpdatePlacementPrefs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlacementPreferences(flags, placement)
|
updatePlacementPreferences(flags, placement)
|
||||||
assert.Equal(t, len(placement.Preferences), 2)
|
require.Len(t, placement.Preferences, 2)
|
||||||
assert.Equal(t, placement.Preferences[0].Spread.SpreadDescriptor, "node.labels.row")
|
assert.Equal(t, "node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor)
|
||||||
assert.Equal(t, placement.Preferences[1].Spread.SpreadDescriptor, "node.labels.dc")
|
assert.Equal(t, "node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateEnvironment(t *testing.T) {
|
func TestUpdateEnvironment(t *testing.T) {
|
||||||
|
@ -100,11 +101,11 @@ func TestUpdateEnvironment(t *testing.T) {
|
||||||
envs := []string{"toremove=theenvtoremove", "tokeep=value"}
|
envs := []string{"toremove=theenvtoremove", "tokeep=value"}
|
||||||
|
|
||||||
updateEnvironment(flags, &envs)
|
updateEnvironment(flags, &envs)
|
||||||
assert.Equal(t, len(envs), 2)
|
require.Len(t, envs, 2)
|
||||||
// Order has been removed in updateEnvironment (map)
|
// Order has been removed in updateEnvironment (map)
|
||||||
sort.Strings(envs)
|
sort.Strings(envs)
|
||||||
assert.Equal(t, envs[0], "toadd=newenv")
|
assert.Equal(t, "toadd=newenv", envs[0])
|
||||||
assert.Equal(t, envs[1], "tokeep=value")
|
assert.Equal(t, "tokeep=value", envs[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
|
func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
|
||||||
|
@ -116,7 +117,7 @@ func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
|
||||||
envs := []string{"foo=value"}
|
envs := []string{"foo=value"}
|
||||||
|
|
||||||
updateEnvironment(flags, &envs)
|
updateEnvironment(flags, &envs)
|
||||||
assert.Equal(t, len(envs), 0)
|
assert.Len(t, envs, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
|
func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
|
||||||
|
@ -127,8 +128,8 @@ func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
|
||||||
envs := []string{"A=c"}
|
envs := []string{"A=c"}
|
||||||
|
|
||||||
updateEnvironment(flags, &envs)
|
updateEnvironment(flags, &envs)
|
||||||
assert.Equal(t, len(envs), 1)
|
require.Len(t, envs, 1)
|
||||||
assert.Equal(t, envs[0], "A=b")
|
assert.Equal(t, "A=b", envs[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateGroups(t *testing.T) {
|
func TestUpdateGroups(t *testing.T) {
|
||||||
|
@ -142,10 +143,10 @@ func TestUpdateGroups(t *testing.T) {
|
||||||
groups := []string{"bar", "root"}
|
groups := []string{"bar", "root"}
|
||||||
|
|
||||||
updateGroups(flags, &groups)
|
updateGroups(flags, &groups)
|
||||||
assert.Equal(t, len(groups), 3)
|
require.Len(t, groups, 3)
|
||||||
assert.Equal(t, groups[0], "bar")
|
assert.Equal(t, "bar", groups[0])
|
||||||
assert.Equal(t, groups[1], "foo")
|
assert.Equal(t, "foo", groups[1])
|
||||||
assert.Equal(t, groups[2], "wheel")
|
assert.Equal(t, "wheel", groups[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateDNSConfig(t *testing.T) {
|
func TestUpdateDNSConfig(t *testing.T) {
|
||||||
|
@ -160,7 +161,7 @@ func TestUpdateDNSConfig(t *testing.T) {
|
||||||
// IPv6
|
// IPv6
|
||||||
flags.Set("dns-add", "2001:db8:abc8::1")
|
flags.Set("dns-add", "2001:db8:abc8::1")
|
||||||
// Invalid dns record
|
// Invalid dns record
|
||||||
assert.Error(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address")
|
assert.EqualError(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address")
|
||||||
|
|
||||||
// domains with duplicates
|
// domains with duplicates
|
||||||
flags.Set("dns-search-add", "example.com")
|
flags.Set("dns-search-add", "example.com")
|
||||||
|
@ -168,7 +169,7 @@ func TestUpdateDNSConfig(t *testing.T) {
|
||||||
flags.Set("dns-search-add", "example.org")
|
flags.Set("dns-search-add", "example.org")
|
||||||
flags.Set("dns-search-rm", "example.org")
|
flags.Set("dns-search-rm", "example.org")
|
||||||
// Invalid dns search domain
|
// Invalid dns search domain
|
||||||
assert.Error(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
|
assert.EqualError(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
|
||||||
|
|
||||||
flags.Set("dns-option-add", "ndots:9")
|
flags.Set("dns-option-add", "ndots:9")
|
||||||
flags.Set("dns-option-rm", "timeout:3")
|
flags.Set("dns-option-rm", "timeout:3")
|
||||||
|
@ -181,16 +182,16 @@ func TestUpdateDNSConfig(t *testing.T) {
|
||||||
|
|
||||||
updateDNSConfig(flags, &config)
|
updateDNSConfig(flags, &config)
|
||||||
|
|
||||||
assert.Equal(t, len(config.Nameservers), 3)
|
require.Len(t, config.Nameservers, 3)
|
||||||
assert.Equal(t, config.Nameservers[0], "1.1.1.1")
|
assert.Equal(t, "1.1.1.1", config.Nameservers[0])
|
||||||
assert.Equal(t, config.Nameservers[1], "2001:db8:abc8::1")
|
assert.Equal(t, "2001:db8:abc8::1", config.Nameservers[1])
|
||||||
assert.Equal(t, config.Nameservers[2], "5.5.5.5")
|
assert.Equal(t, "5.5.5.5", config.Nameservers[2])
|
||||||
|
|
||||||
assert.Equal(t, len(config.Search), 2)
|
require.Len(t, config.Search, 2)
|
||||||
assert.Equal(t, config.Search[0], "example.com")
|
assert.Equal(t, "example.com", config.Search[0])
|
||||||
assert.Equal(t, config.Search[1], "localdomain")
|
assert.Equal(t, "localdomain", config.Search[1])
|
||||||
|
|
||||||
assert.Equal(t, len(config.Options), 1)
|
require.Len(t, config.Options, 1)
|
||||||
assert.Equal(t, config.Options[0], "ndots:9")
|
assert.Equal(t, config.Options[0], "ndots:9")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,10 +206,9 @@ func TestUpdateMounts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMounts(flags, &mounts)
|
updateMounts(flags, &mounts)
|
||||||
assert.Equal(t, len(mounts), 2)
|
require.Len(t, mounts, 2)
|
||||||
assert.Equal(t, mounts[0].Target, "/toadd")
|
assert.Equal(t, "/toadd", mounts[0].Target)
|
||||||
assert.Equal(t, mounts[1].Target, "/tokeep")
|
assert.Equal(t, "/tokeep", mounts[1].Target)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
|
func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
|
||||||
|
@ -222,10 +222,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMounts(flags, &mounts)
|
updateMounts(flags, &mounts)
|
||||||
assert.Equal(t, len(mounts), 3)
|
require.Len(t, mounts, 3)
|
||||||
assert.Equal(t, mounts[0].Target, "/tokeep1")
|
assert.Equal(t, "/tokeep1", mounts[0].Target)
|
||||||
assert.Equal(t, mounts[1].Target, "/tokeep2")
|
assert.Equal(t, "/tokeep2", mounts[1].Target)
|
||||||
assert.Equal(t, mounts[2].Target, "/toadd")
|
assert.Equal(t, "/toadd", mounts[2].Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePorts(t *testing.T) {
|
func TestUpdatePorts(t *testing.T) {
|
||||||
|
@ -239,13 +239,13 @@ func TestUpdatePorts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := updatePorts(flags, &portConfigs)
|
err := updatePorts(flags, &portConfigs)
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(portConfigs), 2)
|
require.Len(t, portConfigs, 2)
|
||||||
// Do a sort to have the order (might have changed by map)
|
// Do a sort to have the order (might have changed by map)
|
||||||
targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)}
|
targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)}
|
||||||
sort.Ints(targetPorts)
|
sort.Ints(targetPorts)
|
||||||
assert.Equal(t, targetPorts[0], 555)
|
assert.Equal(t, 555, targetPorts[0])
|
||||||
assert.Equal(t, targetPorts[1], 1000)
|
assert.Equal(t, 1000, targetPorts[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePortsDuplicate(t *testing.T) {
|
func TestUpdatePortsDuplicate(t *testing.T) {
|
||||||
|
@ -263,9 +263,9 @@ func TestUpdatePortsDuplicate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := updatePorts(flags, &portConfigs)
|
err := updatePorts(flags, &portConfigs)
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(portConfigs), 1)
|
require.Len(t, portConfigs, 1)
|
||||||
assert.Equal(t, portConfigs[0].TargetPort, uint32(80))
|
assert.Equal(t, uint32(80), portConfigs[0].TargetPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateHealthcheckTable(t *testing.T) {
|
func TestUpdateHealthcheckTable(t *testing.T) {
|
||||||
|
@ -339,9 +339,9 @@ func TestUpdateHealthcheckTable(t *testing.T) {
|
||||||
}
|
}
|
||||||
err := updateHealthcheck(flags, cspec)
|
err := updateHealthcheck(flags, cspec)
|
||||||
if c.err != "" {
|
if c.err != "" {
|
||||||
assert.Error(t, err, c.err)
|
assert.EqualError(t, err, c.err)
|
||||||
} else {
|
} else {
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) {
|
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) {
|
||||||
t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck)
|
t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck)
|
||||||
}
|
}
|
||||||
|
@ -358,15 +358,15 @@ func TestUpdateHosts(t *testing.T) {
|
||||||
// just hostname should work as well
|
// just hostname should work as well
|
||||||
flags.Set("host-rm", "example.net")
|
flags.Set("host-rm", "example.net")
|
||||||
// bad format error
|
// bad format error
|
||||||
assert.Error(t, flags.Set("host-add", "$example.com$"), "bad format for add-host:")
|
assert.EqualError(t, flags.Set("host-add", "$example.com$"), `bad format for add-host: "$example.com$"`)
|
||||||
|
|
||||||
hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"}
|
hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"}
|
||||||
|
|
||||||
updateHosts(flags, &hosts)
|
updateHosts(flags, &hosts)
|
||||||
assert.Equal(t, len(hosts), 3)
|
require.Len(t, hosts, 3)
|
||||||
assert.Equal(t, hosts[0], "1.2.3.4 example.com")
|
assert.Equal(t, "1.2.3.4 example.com", hosts[0])
|
||||||
assert.Equal(t, hosts[1], "2001:db8:abc8::1 ipv6.net")
|
assert.Equal(t, "2001:db8:abc8::1 ipv6.net", hosts[1])
|
||||||
assert.Equal(t, hosts[2], "4.3.2.1 example.org")
|
assert.Equal(t, "4.3.2.1 example.org", hosts[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePortsRmWithProtocol(t *testing.T) {
|
func TestUpdatePortsRmWithProtocol(t *testing.T) {
|
||||||
|
@ -387,10 +387,10 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := updatePorts(flags, &portConfigs)
|
err := updatePorts(flags, &portConfigs)
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(portConfigs), 2)
|
require.Len(t, portConfigs, 2)
|
||||||
assert.Equal(t, portConfigs[0].TargetPort, uint32(81))
|
assert.Equal(t, uint32(81), portConfigs[0].TargetPort)
|
||||||
assert.Equal(t, portConfigs[1].TargetPort, uint32(82))
|
assert.Equal(t, uint32(82), portConfigs[1].TargetPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
type secretAPIClientMock struct {
|
type secretAPIClientMock struct {
|
||||||
|
@ -444,11 +444,11 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) {
|
||||||
|
|
||||||
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
|
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
|
||||||
|
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(updatedSecrets), 1)
|
require.Len(t, updatedSecrets, 1)
|
||||||
assert.Equal(t, updatedSecrets[0].SecretID, "tn9qiblgnuuut11eufquw5dev")
|
assert.Equal(t, "tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID)
|
||||||
assert.Equal(t, updatedSecrets[0].SecretName, "foo")
|
assert.Equal(t, "foo", updatedSecrets[0].SecretName)
|
||||||
assert.Equal(t, updatedSecrets[0].File.Name, "foo2")
|
assert.Equal(t, "foo2", updatedSecrets[0].File.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateReadOnly(t *testing.T) {
|
func TestUpdateReadOnly(t *testing.T) {
|
||||||
|
@ -459,18 +459,18 @@ func TestUpdateReadOnly(t *testing.T) {
|
||||||
flags := newUpdateCommand(nil).Flags()
|
flags := newUpdateCommand(nil).Flags()
|
||||||
flags.Set("read-only", "true")
|
flags.Set("read-only", "true")
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.ReadOnly, true)
|
assert.True(t, cspec.ReadOnly)
|
||||||
|
|
||||||
// Update without --read-only, no change
|
// Update without --read-only, no change
|
||||||
flags = newUpdateCommand(nil).Flags()
|
flags = newUpdateCommand(nil).Flags()
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.ReadOnly, true)
|
assert.True(t, cspec.ReadOnly)
|
||||||
|
|
||||||
// Update with --read-only=false, changed to false
|
// Update with --read-only=false, changed to false
|
||||||
flags = newUpdateCommand(nil).Flags()
|
flags = newUpdateCommand(nil).Flags()
|
||||||
flags.Set("read-only", "false")
|
flags.Set("read-only", "false")
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.ReadOnly, false)
|
assert.False(t, cspec.ReadOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateStopSignal(t *testing.T) {
|
func TestUpdateStopSignal(t *testing.T) {
|
||||||
|
@ -481,16 +481,16 @@ func TestUpdateStopSignal(t *testing.T) {
|
||||||
flags := newUpdateCommand(nil).Flags()
|
flags := newUpdateCommand(nil).Flags()
|
||||||
flags.Set("stop-signal", "SIGUSR1")
|
flags.Set("stop-signal", "SIGUSR1")
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.StopSignal, "SIGUSR1")
|
assert.Equal(t, "SIGUSR1", cspec.StopSignal)
|
||||||
|
|
||||||
// Update without --stop-signal, no change
|
// Update without --stop-signal, no change
|
||||||
flags = newUpdateCommand(nil).Flags()
|
flags = newUpdateCommand(nil).Flags()
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.StopSignal, "SIGUSR1")
|
assert.Equal(t, "SIGUSR1", cspec.StopSignal)
|
||||||
|
|
||||||
// Update with --stop-signal=SIGWINCH
|
// Update with --stop-signal=SIGWINCH
|
||||||
flags = newUpdateCommand(nil).Flags()
|
flags = newUpdateCommand(nil).Flags()
|
||||||
flags.Set("stop-signal", "SIGWINCH")
|
flags.Set("stop-signal", "SIGWINCH")
|
||||||
updateService(nil, nil, flags, spec)
|
updateService(nil, nil, flags, spec)
|
||||||
assert.Equal(t, cspec.StopSignal, "SIGWINCH")
|
assert.Equal(t, "SIGWINCH", cspec.StopSignal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/cli/compose/convert"
|
"github.com/docker/docker/cli/compose/convert"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,5 +23,5 @@ func TestPruneServices(t *testing.T) {
|
||||||
|
|
||||||
pruneServices(ctx, dockerCli, namespace, services)
|
pruneServices(ctx, dockerCli, namespace, services)
|
||||||
|
|
||||||
assert.DeepEqual(t, client.removedServices, buildObjectIDs([]string{objectName("foo", "remove")}))
|
assert.Equal(t, buildObjectIDs([]string{objectName("foo", "remove")}), client.removedServices)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRemoveStack(t *testing.T) {
|
func TestRemoveStack(t *testing.T) {
|
||||||
|
@ -17,20 +17,20 @@ func TestRemoveStack(t *testing.T) {
|
||||||
objectName("bar", "service1"),
|
objectName("bar", "service1"),
|
||||||
objectName("bar", "service2"),
|
objectName("bar", "service2"),
|
||||||
}
|
}
|
||||||
allServicesIDs := buildObjectIDs(allServices)
|
allServiceIDs := buildObjectIDs(allServices)
|
||||||
|
|
||||||
allNetworks := []string{
|
allNetworks := []string{
|
||||||
objectName("foo", "network1"),
|
objectName("foo", "network1"),
|
||||||
objectName("bar", "network1"),
|
objectName("bar", "network1"),
|
||||||
}
|
}
|
||||||
allNetworksIDs := buildObjectIDs(allNetworks)
|
allNetworkIDs := buildObjectIDs(allNetworks)
|
||||||
|
|
||||||
allSecrets := []string{
|
allSecrets := []string{
|
||||||
objectName("foo", "secret1"),
|
objectName("foo", "secret1"),
|
||||||
objectName("foo", "secret2"),
|
objectName("foo", "secret2"),
|
||||||
objectName("bar", "secret1"),
|
objectName("bar", "secret1"),
|
||||||
}
|
}
|
||||||
allSecretsIDs := buildObjectIDs(allSecrets)
|
allSecretIDs := buildObjectIDs(allSecrets)
|
||||||
|
|
||||||
cli := &fakeClient{
|
cli := &fakeClient{
|
||||||
services: allServices,
|
services: allServices,
|
||||||
|
@ -40,22 +40,22 @@ func TestRemoveStack(t *testing.T) {
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.DeepEqual(t, cli.removedServices, allServicesIDs)
|
assert.Equal(t, allServiceIDs, cli.removedServices)
|
||||||
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs)
|
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
||||||
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs)
|
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSkipEmptyStack(t *testing.T) {
|
func TestSkipEmptyStack(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
allServices := []string{objectName("bar", "service1"), objectName("bar", "service2")}
|
allServices := []string{objectName("bar", "service1"), objectName("bar", "service2")}
|
||||||
allServicesIDs := buildObjectIDs(allServices)
|
allServiceIDs := buildObjectIDs(allServices)
|
||||||
|
|
||||||
allNetworks := []string{objectName("bar", "network1")}
|
allNetworks := []string{objectName("bar", "network1")}
|
||||||
allNetworksIDs := buildObjectIDs(allNetworks)
|
allNetworkIDs := buildObjectIDs(allNetworks)
|
||||||
|
|
||||||
allSecrets := []string{objectName("bar", "secret1")}
|
allSecrets := []string{objectName("bar", "secret1")}
|
||||||
allSecretsIDs := buildObjectIDs(allSecrets)
|
allSecretIDs := buildObjectIDs(allSecrets)
|
||||||
|
|
||||||
cli := &fakeClient{
|
cli := &fakeClient{
|
||||||
services: allServices,
|
services: allServices,
|
||||||
|
@ -65,22 +65,22 @@ func TestSkipEmptyStack(t *testing.T) {
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(cli, buf))
|
cmd := newRemoveCommand(test.NewFakeCli(cli, buf))
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Contains(t, buf.String(), "Nothing found in stack: foo")
|
assert.Contains(t, buf.String(), "Nothing found in stack: foo")
|
||||||
assert.DeepEqual(t, cli.removedServices, allServicesIDs)
|
assert.Equal(t, allServiceIDs, cli.removedServices)
|
||||||
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs)
|
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
||||||
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs)
|
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContinueAfterError(t *testing.T) {
|
func TestContinueAfterError(t *testing.T) {
|
||||||
allServices := []string{objectName("foo", "service1"), objectName("bar", "service1")}
|
allServices := []string{objectName("foo", "service1"), objectName("bar", "service1")}
|
||||||
allServicesIDs := buildObjectIDs(allServices)
|
allServiceIDs := buildObjectIDs(allServices)
|
||||||
|
|
||||||
allNetworks := []string{objectName("foo", "network1"), objectName("bar", "network1")}
|
allNetworks := []string{objectName("foo", "network1"), objectName("bar", "network1")}
|
||||||
allNetworksIDs := buildObjectIDs(allNetworks)
|
allNetworkIDs := buildObjectIDs(allNetworks)
|
||||||
|
|
||||||
allSecrets := []string{objectName("foo", "secret1"), objectName("bar", "secret1")}
|
allSecrets := []string{objectName("foo", "secret1"), objectName("bar", "secret1")}
|
||||||
allSecretsIDs := buildObjectIDs(allSecrets)
|
allSecretIDs := buildObjectIDs(allSecrets)
|
||||||
|
|
||||||
removedServices := []string{}
|
removedServices := []string{}
|
||||||
cli := &fakeClient{
|
cli := &fakeClient{
|
||||||
|
@ -100,8 +100,8 @@ func TestContinueAfterError(t *testing.T) {
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.Error(t, cmd.Execute(), "Failed to remove some resources from stack: foo")
|
assert.EqualError(t, cmd.Execute(), "Failed to remove some resources from stack: foo")
|
||||||
assert.DeepEqual(t, removedServices, allServicesIDs)
|
assert.Equal(t, allServiceIDs, removedServices)
|
||||||
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs)
|
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
||||||
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs)
|
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,10 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||||
|
@ -76,7 +77,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
assert.EqualError(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +123,9 @@ func TestSwarmInit(t *testing.T) {
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmJoinErrors(t *testing.T) {
|
func TestSwarmJoinErrors(t *testing.T) {
|
||||||
|
@ -56,7 +57,7 @@ func TestSwarmJoinErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ func TestSwarmJoin(t *testing.T) {
|
||||||
infoFunc: tc.infoFunc,
|
infoFunc: tc.infoFunc,
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs([]string{"remote"})
|
cmd.SetArgs([]string{"remote"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected)
|
assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmJoinTokenErrors(t *testing.T) {
|
func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||||
|
@ -102,7 +103,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,9 +209,9 @@ func TestSwarmJoinToken(t *testing.T) {
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("jointoken-%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("jointoken-%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmLeaveErrors(t *testing.T) {
|
func TestSwarmLeaveErrors(t *testing.T) {
|
||||||
|
@ -39,7 +40,7 @@ func TestSwarmLeaveErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +48,6 @@ func TestSwarmLeave(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cmd := newLeaveCommand(
|
cmd := newLeaveCommand(
|
||||||
test.NewFakeCli(&fakeClient{}, buf))
|
test.NewFakeCli(&fakeClient{}, buf))
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), "Node left the swarm.")
|
assert.Equal(t, "Node left the swarm.", strings.TrimSpace(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,37 +3,37 @@ package swarm
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
|
func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
|
||||||
opt := NewNodeAddrOption("old:123")
|
opt := NewNodeAddrOption("old:123")
|
||||||
addr := "newhost:5555"
|
addr := "newhost:5555"
|
||||||
assert.NilError(t, opt.Set(addr))
|
assert.NoError(t, opt.Set(addr))
|
||||||
assert.Equal(t, opt.Value(), addr)
|
assert.Equal(t, addr, opt.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeAddrOptionSetHostOnly(t *testing.T) {
|
func TestNodeAddrOptionSetHostOnly(t *testing.T) {
|
||||||
opt := NewListenAddrOption()
|
opt := NewListenAddrOption()
|
||||||
assert.NilError(t, opt.Set("newhost"))
|
assert.NoError(t, opt.Set("newhost"))
|
||||||
assert.Equal(t, opt.Value(), "newhost:2377")
|
assert.Equal(t, "newhost:2377", opt.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
|
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
|
||||||
opt := NewListenAddrOption()
|
opt := NewListenAddrOption()
|
||||||
assert.NilError(t, opt.Set("::1"))
|
assert.NoError(t, opt.Set("::1"))
|
||||||
assert.Equal(t, opt.Value(), "[::1]:2377")
|
assert.Equal(t, "[::1]:2377", opt.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeAddrOptionSetPortOnly(t *testing.T) {
|
func TestNodeAddrOptionSetPortOnly(t *testing.T) {
|
||||||
opt := NewListenAddrOption()
|
opt := NewListenAddrOption()
|
||||||
assert.NilError(t, opt.Set(":4545"))
|
assert.NoError(t, opt.Set(":4545"))
|
||||||
assert.Equal(t, opt.Value(), "0.0.0.0:4545")
|
assert.Equal(t, "0.0.0.0:4545", opt.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
|
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
|
||||||
opt := NewListenAddrOption()
|
opt := NewListenAddrOption()
|
||||||
assert.Error(t, opt.Set("http://localhost:4545"), "Invalid")
|
assert.EqualError(t, opt.Set("http://localhost:4545"), "Invalid proto, expected tcp: http://localhost:4545")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExternalCAOptionErrors(t *testing.T) {
|
func TestExternalCAOptionErrors(t *testing.T) {
|
||||||
|
@ -64,7 +64,7 @@ func TestExternalCAOptionErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
opt := &ExternalCAOption{}
|
opt := &ExternalCAOption{}
|
||||||
assert.Error(t, opt.Set(tc.externalCA), tc.expectedError)
|
assert.EqualError(t, opt.Set(tc.externalCA), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,15 +96,15 @@ func TestExternalCAOption(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
opt := &ExternalCAOption{}
|
opt := &ExternalCAOption{}
|
||||||
assert.NilError(t, opt.Set(tc.externalCA))
|
assert.NoError(t, opt.Set(tc.externalCA))
|
||||||
assert.Equal(t, opt.String(), tc.expected)
|
assert.Equal(t, tc.expected, opt.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExternalCAOptionMultiple(t *testing.T) {
|
func TestExternalCAOptionMultiple(t *testing.T) {
|
||||||
opt := &ExternalCAOption{}
|
opt := &ExternalCAOption{}
|
||||||
assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com"))
|
assert.NoError(t, opt.Set("protocol=cfssl,url=https://example.com"))
|
||||||
assert.NilError(t, opt.Set("protocol=CFSSL,url=anything"))
|
assert.NoError(t, opt.Set("protocol=CFSSL,url=anything"))
|
||||||
assert.Equal(t, len(opt.Value()), 2)
|
assert.Len(t, opt.Value(), 2)
|
||||||
assert.Equal(t, opt.String(), "cfssl: https://example.com, cfssl: anything")
|
assert.Equal(t, "cfssl: https://example.com, cfssl: anything", opt.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmUnlockKeyErrors(t *testing.T) {
|
func TestSwarmUnlockKeyErrors(t *testing.T) {
|
||||||
|
@ -94,7 +95,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,9 +169,9 @@ func TestSwarmUnlockKey(t *testing.T) {
|
||||||
for key, value := range tc.flags {
|
for key, value := range tc.flags {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmUnlockErrors(t *testing.T) {
|
func TestSwarmUnlockErrors(t *testing.T) {
|
||||||
|
@ -73,7 +74,7 @@ func TestSwarmUnlockErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,5 +98,5 @@ func TestSwarmUnlock(t *testing.T) {
|
||||||
}, buf)
|
}, buf)
|
||||||
dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input)))
|
dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input)))
|
||||||
cmd := newUnlockCommand(dockerCli)
|
cmd := newUnlockCommand(dockerCli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwarmUpdateErrors(t *testing.T) {
|
func TestSwarmUpdateErrors(t *testing.T) {
|
||||||
|
@ -79,7 +80,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +176,9 @@ func TestSwarmUpdate(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(buf)
|
cmd.SetOutput(buf)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("update-%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("update-%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
volumetypes "github.com/docker/docker/api/types/volume"
|
volumetypes "github.com/docker/docker/api/types/volume"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumeCreateErrors(t *testing.T) {
|
func TestVolumeCreateErrors(t *testing.T) {
|
||||||
|
@ -50,7 +51,7 @@ func TestVolumeCreateErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,15 +72,15 @@ func TestVolumeCreateWithName(t *testing.T) {
|
||||||
// Test by flags
|
// Test by flags
|
||||||
cmd := newCreateCommand(cli)
|
cmd := newCreateCommand(cli)
|
||||||
cmd.Flags().Set("name", name)
|
cmd.Flags().Set("name", name)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), name)
|
assert.Equal(t, name, strings.TrimSpace(buf.String()))
|
||||||
|
|
||||||
// Then by args
|
// Then by args
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
cmd = newCreateCommand(cli)
|
cmd = newCreateCommand(cli)
|
||||||
cmd.SetArgs([]string{name})
|
cmd.SetArgs([]string{name})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), name)
|
assert.Equal(t, name, strings.TrimSpace(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVolumeCreateWithFlags(t *testing.T) {
|
func TestVolumeCreateWithFlags(t *testing.T) {
|
||||||
|
@ -121,8 +122,8 @@ func TestVolumeCreateWithFlags(t *testing.T) {
|
||||||
cmd.Flags().Set("opt", "baz=baz")
|
cmd.Flags().Set("opt", "baz=baz")
|
||||||
cmd.Flags().Set("label", "lbl1=v1")
|
cmd.Flags().Set("label", "lbl1=v1")
|
||||||
cmd.Flags().Set("label", "lbl2=v2")
|
cmd.Flags().Set("label", "lbl2=v2")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
assert.Equal(t, strings.TrimSpace(buf.String()), name)
|
assert.Equal(t, name, strings.TrimSpace(buf.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareMap(actual map[string]string, expected map[string]string) bool {
|
func compareMap(actual map[string]string, expected map[string]string) bool {
|
||||||
|
|
|
@ -11,8 +11,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumeInspectErrors(t *testing.T) {
|
func TestVolumeInspectErrors(t *testing.T) {
|
||||||
|
@ -64,7 +65,7 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,10 +103,10 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
|
||||||
}, buf),
|
}, buf),
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-without-format.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-without-format.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,9 +144,9 @@ func TestVolumeInspectWithFormat(t *testing.T) {
|
||||||
)
|
)
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.Flags().Set("format", tc.format)
|
cmd.Flags().Set("format", tc.format)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
// Import builders to get the builder function as package function
|
// Import builders to get the builder function as package function
|
||||||
. "github.com/docker/docker/cli/internal/test/builders"
|
. "github.com/docker/docker/cli/internal/test/builders"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumeListErrors(t *testing.T) {
|
func TestVolumeListErrors(t *testing.T) {
|
||||||
|
@ -47,7 +48,7 @@ func TestVolumeListErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,10 +69,10 @@ func TestVolumeListWithoutFormat(t *testing.T) {
|
||||||
}, buf)
|
}, buf)
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "volume-list-without-format.golden")
|
expected := golden.Get(t, []byte(actual), "volume-list-without-format.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVolumeListWithConfigFormat(t *testing.T) {
|
func TestVolumeListWithConfigFormat(t *testing.T) {
|
||||||
|
@ -93,10 +94,10 @@ func TestVolumeListWithConfigFormat(t *testing.T) {
|
||||||
VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}",
|
VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}",
|
||||||
})
|
})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "volume-list-with-config-format.golden")
|
expected := golden.Get(t, []byte(actual), "volume-list-with-config-format.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVolumeListWithFormat(t *testing.T) {
|
func TestVolumeListWithFormat(t *testing.T) {
|
||||||
|
@ -117,8 +118,8 @@ func TestVolumeListWithFormat(t *testing.T) {
|
||||||
cli.SetConfigfile(&configfile.ConfigFile{})
|
cli.SetConfigfile(&configfile.ConfigFile{})
|
||||||
cmd := newListCommand(cli)
|
cmd := newListCommand(cli)
|
||||||
cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")
|
cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "volume-list-with-format.golden")
|
expected := golden.Get(t, []byte(actual), "volume-list-with-format.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,10 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/golden"
|
"github.com/docker/docker/pkg/testutil/golden"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumePruneErrors(t *testing.T) {
|
func TestVolumePruneErrors(t *testing.T) {
|
||||||
|
@ -48,7 +49,7 @@ func TestVolumePruneErrors(t *testing.T) {
|
||||||
cmd.Flags().Set(key, value)
|
cmd.Flags().Set(key, value)
|
||||||
}
|
}
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,10 +74,10 @@ func TestVolumePruneForce(t *testing.T) {
|
||||||
}, buf),
|
}, buf),
|
||||||
)
|
)
|
||||||
cmd.Flags().Set("force", "true")
|
cmd.Flags().Set("force", "true")
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-prune.%s.golden", tc.name))
|
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-prune.%s.golden", tc.name))
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestVolumePrunePromptYes(t *testing.T) {
|
func TestVolumePrunePromptYes(t *testing.T) {
|
||||||
|
@ -94,10 +95,10 @@ func TestVolumePrunePromptYes(t *testing.T) {
|
||||||
cmd := NewPruneCommand(
|
cmd := NewPruneCommand(
|
||||||
cli,
|
cli,
|
||||||
)
|
)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "volume-prune-yes.golden")
|
expected := golden.Get(t, []byte(actual), "volume-prune-yes.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +117,10 @@ func TestVolumePrunePromptNo(t *testing.T) {
|
||||||
cmd := NewPruneCommand(
|
cmd := NewPruneCommand(
|
||||||
cli,
|
cli,
|
||||||
)
|
)
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
actual := buf.String()
|
actual := buf.String()
|
||||||
expected := golden.Get(t, []byte(actual), "volume-prune-no.golden")
|
expected := golden.Get(t, []byte(actual), "volume-prune-no.golden")
|
||||||
assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected))
|
testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/internal/test"
|
"github.com/docker/docker/cli/internal/test"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVolumeRemoveErrors(t *testing.T) {
|
func TestVolumeRemoveErrors(t *testing.T) {
|
||||||
|
@ -35,7 +36,7 @@ func TestVolumeRemoveErrors(t *testing.T) {
|
||||||
}, buf))
|
}, buf))
|
||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
assert.Error(t, cmd.Execute(), tc.expectedError)
|
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,5 +44,5 @@ func TestNodeRemoveMultiple(t *testing.T) {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
|
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
|
||||||
cmd.SetArgs([]string{"volume1", "volume2"})
|
cmd.SetArgs([]string{"volume1", "volume2"})
|
||||||
assert.NilError(t, cmd.Execute())
|
assert.NoError(t, cmd.Execute())
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/network"
|
"github.com/docker/docker/api/types/network"
|
||||||
composetypes "github.com/docker/docker/cli/compose/types"
|
composetypes "github.com/docker/docker/cli/compose/types"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/docker/docker/pkg/testutil/tempfile"
|
"github.com/docker/docker/pkg/testutil/tempfile"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNamespaceScope(t *testing.T) {
|
func TestNamespaceScope(t *testing.T) {
|
||||||
scoped := Namespace{name: "foo"}.Scope("bar")
|
scoped := Namespace{name: "foo"}.Scope("bar")
|
||||||
assert.Equal(t, scoped, "foo_bar")
|
assert.Equal(t, "foo_bar", scoped)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddStackLabel(t *testing.T) {
|
func TestAddStackLabel(t *testing.T) {
|
||||||
|
@ -24,7 +25,7 @@ func TestAddStackLabel(t *testing.T) {
|
||||||
"something": "labeled",
|
"something": "labeled",
|
||||||
LabelNamespace: "foo",
|
LabelNamespace: "foo",
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNetworks(t *testing.T) {
|
func TestNetworks(t *testing.T) {
|
||||||
|
@ -98,8 +99,8 @@ func TestNetworks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
networks, externals := Networks(namespace, source, serviceNetworks)
|
networks, externals := Networks(namespace, source, serviceNetworks)
|
||||||
assert.DeepEqual(t, networks, expected)
|
assert.Equal(t, expected, networks)
|
||||||
assert.DeepEqual(t, externals, []string{"special"})
|
assert.Equal(t, []string{"special"}, externals)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecrets(t *testing.T) {
|
func TestSecrets(t *testing.T) {
|
||||||
|
@ -122,13 +123,13 @@ func TestSecrets(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
specs, err := Secrets(namespace, source)
|
specs, err := Secrets(namespace, source)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(specs), 1)
|
require.Len(t, specs, 1)
|
||||||
secret := specs[0]
|
secret := specs[0]
|
||||||
assert.Equal(t, secret.Name, "foo_one")
|
assert.Equal(t, "foo_one", secret.Name)
|
||||||
assert.DeepEqual(t, secret.Labels, map[string]string{
|
assert.Equal(t, map[string]string{
|
||||||
"monster": "mash",
|
"monster": "mash",
|
||||||
LabelNamespace: "foo",
|
LabelNamespace: "foo",
|
||||||
})
|
}, secret.Labels)
|
||||||
assert.DeepEqual(t, secret.Data, []byte(secretText))
|
assert.Equal(t, []byte(secretText), secret.Data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,18 +9,18 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
composetypes "github.com/docker/docker/cli/compose/types"
|
composetypes "github.com/docker/docker/cli/compose/types"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromNone(t *testing.T) {
|
func TestConvertRestartPolicyFromNone(t *testing.T) {
|
||||||
policy, err := convertRestartPolicy("no", nil)
|
policy, err := convertRestartPolicy("no", nil)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, policy, (*swarm.RestartPolicy)(nil))
|
assert.Equal(t, (*swarm.RestartPolicy)(nil), policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
func TestConvertRestartPolicyFromUnknown(t *testing.T) {
|
||||||
_, err := convertRestartPolicy("unknown", nil)
|
_, err := convertRestartPolicy("unknown", nil)
|
||||||
assert.Error(t, err, "unknown restart policy: unknown")
|
assert.EqualError(t, err, "unknown restart policy: unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
||||||
|
@ -28,8 +28,8 @@ func TestConvertRestartPolicyFromAlways(t *testing.T) {
|
||||||
expected := &swarm.RestartPolicy{
|
expected := &swarm.RestartPolicy{
|
||||||
Condition: swarm.RestartPolicyConditionAny,
|
Condition: swarm.RestartPolicyConditionAny,
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, policy, expected)
|
assert.Equal(t, expected, policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertRestartPolicyFromFailure(t *testing.T) {
|
func TestConvertRestartPolicyFromFailure(t *testing.T) {
|
||||||
|
@ -39,8 +39,8 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) {
|
||||||
Condition: swarm.RestartPolicyConditionOnFailure,
|
Condition: swarm.RestartPolicyConditionOnFailure,
|
||||||
MaxAttempts: &attempts,
|
MaxAttempts: &attempts,
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, policy, expected)
|
assert.Equal(t, expected, policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func strPtr(val string) *string {
|
func strPtr(val string) *string {
|
||||||
|
@ -54,7 +54,7 @@ func TestConvertEnvironment(t *testing.T) {
|
||||||
}
|
}
|
||||||
env := convertEnvironment(source)
|
env := convertEnvironment(source)
|
||||||
sort.Strings(env)
|
sort.Strings(env)
|
||||||
assert.DeepEqual(t, env, []string{"foo=bar", "key=value"})
|
assert.Equal(t, []string{"foo=bar", "key=value"}, env)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertResourcesFull(t *testing.T) {
|
func TestConvertResourcesFull(t *testing.T) {
|
||||||
|
@ -69,7 +69,7 @@ func TestConvertResourcesFull(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resources, err := convertResources(source)
|
resources, err := convertResources(source)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := &swarm.ResourceRequirements{
|
expected := &swarm.ResourceRequirements{
|
||||||
Limits: &swarm.Resources{
|
Limits: &swarm.Resources{
|
||||||
|
@ -81,7 +81,7 @@ func TestConvertResourcesFull(t *testing.T) {
|
||||||
MemoryBytes: 200000000,
|
MemoryBytes: 200000000,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, resources, expected)
|
assert.Equal(t, expected, resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertResourcesOnlyMemory(t *testing.T) {
|
func TestConvertResourcesOnlyMemory(t *testing.T) {
|
||||||
|
@ -94,7 +94,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
resources, err := convertResources(source)
|
resources, err := convertResources(source)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expected := &swarm.ResourceRequirements{
|
expected := &swarm.ResourceRequirements{
|
||||||
Limits: &swarm.Resources{
|
Limits: &swarm.Resources{
|
||||||
|
@ -104,7 +104,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
|
||||||
MemoryBytes: 200000000,
|
MemoryBytes: 200000000,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.DeepEqual(t, resources, expected)
|
assert.Equal(t, expected, resources)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertHealthcheck(t *testing.T) {
|
func TestConvertHealthcheck(t *testing.T) {
|
||||||
|
@ -123,8 +123,8 @@ func TestConvertHealthcheck(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
healthcheck, err := convertHealthcheck(source)
|
healthcheck, err := convertHealthcheck(source)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, healthcheck, expected)
|
assert.Equal(t, expected, healthcheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertHealthcheckDisable(t *testing.T) {
|
func TestConvertHealthcheckDisable(t *testing.T) {
|
||||||
|
@ -134,8 +134,8 @@ func TestConvertHealthcheckDisable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
healthcheck, err := convertHealthcheck(source)
|
healthcheck, err := convertHealthcheck(source)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, healthcheck, expected)
|
assert.Equal(t, expected, healthcheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertHealthcheckDisableWithTest(t *testing.T) {
|
func TestConvertHealthcheckDisableWithTest(t *testing.T) {
|
||||||
|
@ -144,7 +144,7 @@ func TestConvertHealthcheckDisableWithTest(t *testing.T) {
|
||||||
Test: []string{"EXEC", "touch"},
|
Test: []string{"EXEC", "touch"},
|
||||||
}
|
}
|
||||||
_, err := convertHealthcheck(source)
|
_, err := convertHealthcheck(source)
|
||||||
assert.Error(t, err, "test and disable can't be set")
|
assert.EqualError(t, err, "test and disable can't be set at the same time")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertEndpointSpec(t *testing.T) {
|
func TestConvertEndpointSpec(t *testing.T) {
|
||||||
|
@ -178,8 +178,8 @@ func TestConvertEndpointSpec(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, *endpoint, expected)
|
assert.Equal(t, expected, *endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertServiceNetworksOnlyDefault(t *testing.T) {
|
func TestConvertServiceNetworksOnlyDefault(t *testing.T) {
|
||||||
|
@ -195,8 +195,8 @@ func TestConvertServiceNetworksOnlyDefault(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, configs, expected)
|
assert.Equal(t, expected, configs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertServiceNetworks(t *testing.T) {
|
func TestConvertServiceNetworks(t *testing.T) {
|
||||||
|
@ -235,8 +235,8 @@ func TestConvertServiceNetworks(t *testing.T) {
|
||||||
sortedConfigs := byTargetSort(configs)
|
sortedConfigs := byTargetSort(configs)
|
||||||
sort.Sort(&sortedConfigs)
|
sort.Sort(&sortedConfigs)
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(sortedConfigs), expected)
|
assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(sortedConfigs))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertServiceNetworksCustomDefault(t *testing.T) {
|
func TestConvertServiceNetworksCustomDefault(t *testing.T) {
|
||||||
|
@ -260,8 +260,8 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(configs), expected)
|
assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(configs))
|
||||||
}
|
}
|
||||||
|
|
||||||
type byTargetSort []swarm.NetworkAttachmentConfig
|
type byTargetSort []swarm.NetworkAttachmentConfig
|
||||||
|
@ -281,8 +281,8 @@ func (s byTargetSort) Swap(i, j int) {
|
||||||
func TestConvertDNSConfigEmpty(t *testing.T) {
|
func TestConvertDNSConfigEmpty(t *testing.T) {
|
||||||
dnsConfig, err := convertDNSConfig(nil, nil)
|
dnsConfig, err := convertDNSConfig(nil, nil)
|
||||||
|
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, dnsConfig, (*swarm.DNSConfig)(nil))
|
assert.Equal(t, (*swarm.DNSConfig)(nil), dnsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -292,27 +292,27 @@ var (
|
||||||
|
|
||||||
func TestConvertDNSConfigAll(t *testing.T) {
|
func TestConvertDNSConfigAll(t *testing.T) {
|
||||||
dnsConfig, err := convertDNSConfig(nameservers, search)
|
dnsConfig, err := convertDNSConfig(nameservers, search)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
|
assert.Equal(t, &swarm.DNSConfig{
|
||||||
Nameservers: nameservers,
|
Nameservers: nameservers,
|
||||||
Search: search,
|
Search: search,
|
||||||
})
|
}, dnsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertDNSConfigNameservers(t *testing.T) {
|
func TestConvertDNSConfigNameservers(t *testing.T) {
|
||||||
dnsConfig, err := convertDNSConfig(nameservers, nil)
|
dnsConfig, err := convertDNSConfig(nameservers, nil)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
|
assert.Equal(t, &swarm.DNSConfig{
|
||||||
Nameservers: nameservers,
|
Nameservers: nameservers,
|
||||||
Search: nil,
|
Search: nil,
|
||||||
})
|
}, dnsConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertDNSConfigSearch(t *testing.T) {
|
func TestConvertDNSConfigSearch(t *testing.T) {
|
||||||
dnsConfig, err := convertDNSConfig(nil, search)
|
dnsConfig, err := convertDNSConfig(nil, search)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{
|
assert.Equal(t, &swarm.DNSConfig{
|
||||||
Nameservers: nil,
|
Nameservers: nil,
|
||||||
Search: search,
|
Search: search,
|
||||||
})
|
}, dnsConfig)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
composetypes "github.com/docker/docker/cli/compose/types"
|
composetypes "github.com/docker/docker/cli/compose/types"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
||||||
|
@ -18,8 +18,8 @@ func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
||||||
Target: "/foo/bar",
|
Target: "/foo/bar",
|
||||||
}
|
}
|
||||||
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
|
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, mount, expected)
|
assert.Equal(t, expected, mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
|
func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
|
||||||
|
@ -34,7 +34,7 @@ func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
||||||
assert.Error(t, err, "bind options are incompatible")
|
assert.EqualError(t, err, "bind options are incompatible with type volume")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
|
func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
|
||||||
|
@ -49,7 +49,7 @@ func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
||||||
assert.Error(t, err, "volume options are incompatible")
|
assert.EqualError(t, err, "volume options are incompatible with type bind")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
||||||
|
@ -94,8 +94,8 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, mount, expected)
|
assert.Equal(t, expected, mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
|
func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
|
||||||
|
@ -122,8 +122,8 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
|
||||||
Target: "/foo",
|
Target: "/foo",
|
||||||
}
|
}
|
||||||
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, mount, expected)
|
assert.Equal(t, expected, mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
|
func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
|
||||||
|
@ -153,8 +153,8 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, mount, expected)
|
assert.Equal(t, expected, mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountBind(t *testing.T) {
|
func TestConvertVolumeToMountBind(t *testing.T) {
|
||||||
|
@ -175,8 +175,8 @@ func TestConvertVolumeToMountBind(t *testing.T) {
|
||||||
Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"},
|
Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"},
|
||||||
}
|
}
|
||||||
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
mount, err := convertVolumeToMount(config, stackVolumes, namespace)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, mount, expected)
|
assert.Equal(t, expected, mount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
||||||
|
@ -188,5 +188,5 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
}
|
}
|
||||||
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
_, err := convertVolumeToMount(config, volumes{}, namespace)
|
||||||
assert.Error(t, err, "undefined volume \"unknown\"")
|
assert.EqualError(t, err, "undefined volume \"unknown\"")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,16 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/cli/compose/types"
|
"github.com/docker/docker/cli/compose/types"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseVolumeAnonymousVolume(t *testing.T) {
|
func TestParseVolumeAnonymousVolume(t *testing.T) {
|
||||||
for _, path := range []string{"/path", "/path/foo"} {
|
for _, path := range []string{"/path", "/path/foo"} {
|
||||||
volume, err := parseVolume(path)
|
volume, err := parseVolume(path)
|
||||||
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,29 +21,29 @@ func TestParseVolumeAnonymousVolumeWindows(t *testing.T) {
|
||||||
for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
|
for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
|
||||||
volume, err := parseVolume(path)
|
volume, err := parseVolume(path)
|
||||||
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeTooManyColons(t *testing.T) {
|
func TestParseVolumeTooManyColons(t *testing.T) {
|
||||||
_, err := parseVolume("/foo:/foo:ro:foo")
|
_, err := parseVolume("/foo:/foo:ro:foo")
|
||||||
assert.Error(t, err, "too many colons")
|
assert.EqualError(t, err, "invalid spec: /foo:/foo:ro:foo: too many colons")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeShortVolumes(t *testing.T) {
|
func TestParseVolumeShortVolumes(t *testing.T) {
|
||||||
for _, path := range []string{".", "/a"} {
|
for _, path := range []string{".", "/a"} {
|
||||||
volume, err := parseVolume(path)
|
volume, err := parseVolume(path)
|
||||||
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeMissingSource(t *testing.T) {
|
func TestParseVolumeMissingSource(t *testing.T) {
|
||||||
for _, spec := range []string{":foo", "/foo::ro"} {
|
for _, spec := range []string{":foo", "/foo::ro"} {
|
||||||
_, err := parseVolume(spec)
|
_, err := parseVolume(spec)
|
||||||
assert.Error(t, err, "empty section between colons")
|
testutil.ErrorContains(t, err, "empty section between colons")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +55,8 @@ func TestParseVolumeBindMount(t *testing.T) {
|
||||||
Source: path,
|
Source: path,
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +73,8 @@ func TestParseVolumeRelativeBindMountWindows(t *testing.T) {
|
||||||
Source: path,
|
Source: path,
|
||||||
Target: "d:\\target",
|
Target: "d:\\target",
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +86,8 @@ func TestParseVolumeWithBindOptions(t *testing.T) {
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
Bind: &types.ServiceVolumeBind{Propagation: "slave"},
|
Bind: &types.ServiceVolumeBind{Propagation: "slave"},
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
|
func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
|
||||||
|
@ -98,13 +99,13 @@ func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
Bind: &types.ServiceVolumeBind{Propagation: "rprivate"},
|
Bind: &types.ServiceVolumeBind{Propagation: "rprivate"},
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) {
|
func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) {
|
||||||
_, err := parseVolume("name:/target:bogus")
|
_, err := parseVolume("name:/target:bogus")
|
||||||
assert.Error(t, err, "invalid spec: name:/target:bogus: unknown option: bogus")
|
assert.EqualError(t, err, "invalid spec: name:/target:bogus: unknown option: bogus")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeWithVolumeOptions(t *testing.T) {
|
func TestParseVolumeWithVolumeOptions(t *testing.T) {
|
||||||
|
@ -115,8 +116,8 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) {
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
Volume: &types.ServiceVolumeVolume{NoCopy: true},
|
Volume: &types.ServiceVolumeVolume{NoCopy: true},
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseVolumeWithReadOnly(t *testing.T) {
|
func TestParseVolumeWithReadOnly(t *testing.T) {
|
||||||
|
@ -128,8 +129,8 @@ func TestParseVolumeWithReadOnly(t *testing.T) {
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +143,7 @@ func TestParseVolumeWithRW(t *testing.T) {
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
}
|
}
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.DeepEqual(t, volume, expected)
|
assert.Equal(t, expected, volume)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func defaultMapping(name string) (string, bool) {
|
||||||
|
|
||||||
func TestEscaped(t *testing.T) {
|
func TestEscaped(t *testing.T) {
|
||||||
result, err := Substitute("$${foo}", defaultMapping)
|
result, err := Substitute("$${foo}", defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "${foo}", result)
|
assert.Equal(t, "${foo}", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func TestInvalid(t *testing.T) {
|
||||||
func TestNoValueNoDefault(t *testing.T) {
|
func TestNoValueNoDefault(t *testing.T) {
|
||||||
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
|
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
|
||||||
result, err := Substitute(template, defaultMapping)
|
result, err := Substitute(template, defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "This var", result)
|
assert.Equal(t, "This var", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func TestNoValueNoDefault(t *testing.T) {
|
||||||
func TestValueNoDefault(t *testing.T) {
|
func TestValueNoDefault(t *testing.T) {
|
||||||
for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
|
for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
|
||||||
result, err := Substitute(template, defaultMapping)
|
result, err := Substitute(template, defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "This first var", result)
|
assert.Equal(t, "This first var", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,25 +59,25 @@ func TestValueNoDefault(t *testing.T) {
|
||||||
func TestNoValueWithDefault(t *testing.T) {
|
func TestNoValueWithDefault(t *testing.T) {
|
||||||
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
|
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
|
||||||
result, err := Substitute(template, defaultMapping)
|
result, err := Substitute(template, defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "ok def", result)
|
assert.Equal(t, "ok def", result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyValueWithSoftDefault(t *testing.T) {
|
func TestEmptyValueWithSoftDefault(t *testing.T) {
|
||||||
result, err := Substitute("ok ${BAR:-def}", defaultMapping)
|
result, err := Substitute("ok ${BAR:-def}", defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "ok def", result)
|
assert.Equal(t, "ok def", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyValueWithHardDefault(t *testing.T) {
|
func TestEmptyValueWithHardDefault(t *testing.T) {
|
||||||
result, err := Substitute("ok ${BAR-def}", defaultMapping)
|
result, err := Substitute("ok ${BAR-def}", defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "ok ", result)
|
assert.Equal(t, "ok ", result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNonAlphanumericDefault(t *testing.T) {
|
func TestNonAlphanumericDefault(t *testing.T) {
|
||||||
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping)
|
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping)
|
||||||
assert.NoError(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, "ok /non:-alphanumeric", result)
|
assert.Equal(t, "ok /non:-alphanumeric", result)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
cliconfig "github.com/docker/docker/cli/config"
|
cliconfig "github.com/docker/docker/cli/config"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCommonOptionsInstallFlags(t *testing.T) {
|
func TestCommonOptionsInstallFlags(t *testing.T) {
|
||||||
|
@ -19,9 +19,9 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
|
||||||
"--tlscert=\"/foo/cert\"",
|
"--tlscert=\"/foo/cert\"",
|
||||||
"--tlskey=\"/foo/key\"",
|
"--tlskey=\"/foo/key\"",
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile")
|
assert.Equal(t, "/foo/cafile", opts.TLSOptions.CAFile)
|
||||||
assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert")
|
assert.Equal(t, "/foo/cert", opts.TLSOptions.CertFile)
|
||||||
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
|
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
|
||||||
opts.InstallFlags(flags)
|
opts.InstallFlags(flags)
|
||||||
|
|
||||||
err := flags.Parse([]string{})
|
err := flags.Parse([]string{})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem"))
|
assert.Equal(t, defaultPath("ca.pem"), opts.TLSOptions.CAFile)
|
||||||
assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem"))
|
assert.Equal(t, defaultPath("cert.pem"), opts.TLSOptions.CertFile)
|
||||||
assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem"))
|
assert.Equal(t, defaultPath("key.pem"), opts.TLSOptions.KeyFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestContainersPruneError(t *testing.T) {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
_, err := client.ContainersPrune(context.Background(), filters)
|
_, err := client.ContainersPrune(context.Background(), filters)
|
||||||
assert.Error(t, err, "Error response from daemon: Server error")
|
assert.EqualError(t, err, "Error response from daemon: Server error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainersPrune(t *testing.T) {
|
func TestContainersPrune(t *testing.T) {
|
||||||
|
@ -99,7 +99,7 @@ func TestContainersPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.ContainersPruneReport{
|
content, err := json.Marshal(types.ContainersPruneReport{
|
||||||
ContainersDeleted: []string{"container_id1", "container_id2"},
|
ContainersDeleted: []string{"container_id1", "container_id2"},
|
||||||
|
@ -117,8 +117,8 @@ func TestContainersPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.ContainersPrune(context.Background(), listCase.filters)
|
report, err := client.ContainersPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.ContainersDeleted), 2)
|
assert.Len(t, report.ContainersDeleted, 2)
|
||||||
assert.Equal(t, report.SpaceReclaimed, uint64(9999))
|
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func TestImagesPruneError(t *testing.T) {
|
||||||
filters := filters.NewArgs()
|
filters := filters.NewArgs()
|
||||||
|
|
||||||
_, err := client.ImagesPrune(context.Background(), filters)
|
_, err := client.ImagesPrune(context.Background(), filters)
|
||||||
assert.Error(t, err, "Error response from daemon: Server error")
|
assert.EqualError(t, err, "Error response from daemon: Server error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImagesPrune(t *testing.T) {
|
func TestImagesPrune(t *testing.T) {
|
||||||
|
@ -87,7 +87,7 @@ func TestImagesPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.ImagesPruneReport{
|
content, err := json.Marshal(types.ImagesPruneReport{
|
||||||
ImagesDeleted: []types.ImageDeleteResponseItem{
|
ImagesDeleted: []types.ImageDeleteResponseItem{
|
||||||
|
@ -112,8 +112,8 @@ func TestImagesPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.ImagesPrune(context.Background(), listCase.filters)
|
report, err := client.ImagesPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.ImagesDeleted), 2)
|
assert.Len(t, report.ImagesDeleted, 2)
|
||||||
assert.Equal(t, report.SpaceReclaimed, uint64(9999))
|
assert.Equal(t, uint64(9999), report.SpaceReclaimed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
query := req.URL.Query()
|
query := req.URL.Query()
|
||||||
for key, expected := range listCase.expectedQueryParams {
|
for key, expected := range listCase.expectedQueryParams {
|
||||||
actual := query.Get(key)
|
actual := query.Get(key)
|
||||||
assert.Equal(t, actual, expected)
|
assert.Equal(t, expected, actual)
|
||||||
}
|
}
|
||||||
content, err := json.Marshal(types.NetworksPruneReport{
|
content, err := json.Marshal(types.NetworksPruneReport{
|
||||||
NetworksDeleted: []string{"network_id1", "network_id2"},
|
NetworksDeleted: []string{"network_id1", "network_id2"},
|
||||||
|
@ -106,7 +106,7 @@ func TestNetworksPrune(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report, err := client.NetworksPrune(context.Background(), listCase.filters)
|
report, err := client.NetworksPrune(context.Background(), listCase.filters)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, len(report.NetworksDeleted), 2)
|
assert.Len(t, report.NetworksDeleted, 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDaemonCommand(t *testing.T) {
|
func TestDaemonCommand(t *testing.T) {
|
||||||
|
@ -13,5 +13,5 @@ func TestDaemonCommand(t *testing.T) {
|
||||||
cmd.SetArgs([]string{"--version"})
|
cmd.SetArgs([]string{"--version"})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
|
|
||||||
assert.Error(t, err, "Please run `dockerd`")
|
assert.EqualError(t, err, "Please run `dockerd`")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func stubRun(cmd *cobra.Command, args []string) error {
|
func stubRun(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -18,7 +18,7 @@ func TestDaemonCommandHelp(t *testing.T) {
|
||||||
cmd.RunE = stubRun
|
cmd.RunE = stubRun
|
||||||
cmd.SetArgs([]string{"--help"})
|
cmd.SetArgs([]string{"--help"})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDaemonCommand(t *testing.T) {
|
func TestDaemonCommand(t *testing.T) {
|
||||||
|
@ -26,5 +26,5 @@ func TestDaemonCommand(t *testing.T) {
|
||||||
cmd.RunE = stubRun
|
cmd.RunE = stubRun
|
||||||
cmd.SetArgs([]string{"--containerd", "/foo"})
|
cmd.SetArgs([]string{"--containerd", "/foo"})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/cli/command"
|
"github.com/docker/docker/cli/command"
|
||||||
"github.com/docker/docker/cli/debug"
|
"github.com/docker/docker/cli/debug"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClientDebugEnabled(t *testing.T) {
|
func TestClientDebugEnabled(t *testing.T) {
|
||||||
|
@ -18,9 +18,9 @@ func TestClientDebugEnabled(t *testing.T) {
|
||||||
cmd.Flags().Set("debug", "true")
|
cmd.Flags().Set("debug", "true")
|
||||||
|
|
||||||
err := cmd.PersistentPreRunE(cmd, []string{})
|
err := cmd.PersistentPreRunE(cmd, []string{})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, os.Getenv("DEBUG"), "1")
|
assert.Equal(t, "1", os.Getenv("DEBUG"))
|
||||||
assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel)
|
assert.Equal(t, logrus.DebugLevel, logrus.GetLevel())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
||||||
|
@ -28,5 +28,5 @@ func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
||||||
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
|
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
|
||||||
cmd.SetArgs([]string{"help", "invalid"})
|
cmd.SetArgs([]string{"help", "invalid"})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.Error(t, err, "unknown help topic: invalid")
|
assert.EqualError(t, err, "unknown help topic: invalid")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDaemonParseShmSize(t *testing.T) {
|
func TestDaemonParseShmSize(t *testing.T) {
|
||||||
|
@ -20,13 +20,7 @@ func TestDaemonParseShmSize(t *testing.T) {
|
||||||
conf := &config.Config{}
|
conf := &config.Config{}
|
||||||
installConfigFlags(conf, flags)
|
installConfigFlags(conf, flags)
|
||||||
// By default `--default-shm-size=64M`
|
// By default `--default-shm-size=64M`
|
||||||
expectedValue := 64 * 1024 * 1024
|
assert.Equal(t, int64(64*1024*1024), conf.ShmSize.Value())
|
||||||
if conf.ShmSize.Value() != int64(expectedValue) {
|
assert.NoError(t, flags.Set("default-shm-size", "128M"))
|
||||||
t.Fatalf("expected default shm size %d, got %d", expectedValue, conf.ShmSize.Value())
|
assert.Equal(t, int64(128*1024*1024), conf.ShmSize.Value())
|
||||||
}
|
|
||||||
assert.NilError(t, flags.Set("default-shm-size", "128M"))
|
|
||||||
expectedValue = 128 * 1024 * 1024
|
|
||||||
if conf.ShmSize.Value() != int64(expectedValue) {
|
|
||||||
t.Fatalf("expected default shm size %d, got %d", expectedValue, conf.ShmSize.Value())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
cliflags "github.com/docker/docker/cli/flags"
|
cliflags "github.com/docker/docker/cli/flags"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/docker/docker/pkg/testutil/tempfile"
|
"github.com/docker/docker/pkg/testutil/tempfile"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultOptions(configFile string) daemonOptions {
|
func defaultOptions(configFile string) daemonOptions {
|
||||||
|
@ -29,8 +31,8 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
|
||||||
opts.common.Debug = true
|
opts.common.Debug = true
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
if !loadedConfig.Debug {
|
if !loadedConfig.Debug {
|
||||||
t.Fatalf("expected debug to be copied from the common flags, got false")
|
t.Fatalf("expected debug to be copied from the common flags, got false")
|
||||||
}
|
}
|
||||||
|
@ -42,9 +44,9 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
|
||||||
opts.common.TLS = true
|
opts.common.TLS = true
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.CommonTLSOptions.CAFile, "/tmp/ca.pem")
|
assert.Equal(t, "/tmp/ca.pem", loadedConfig.CommonTLSOptions.CAFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
|
func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
|
||||||
|
@ -55,12 +57,12 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
|
||||||
opts := defaultOptions(configFile)
|
opts := defaultOptions(configFile)
|
||||||
flags := opts.flags
|
flags := opts.flags
|
||||||
|
|
||||||
assert.NilError(t, flags.Set("config-file", configFile))
|
assert.NoError(t, flags.Set("config-file", configFile))
|
||||||
assert.NilError(t, flags.Set("label", "l1=bar"))
|
assert.NoError(t, flags.Set("label", "l1=bar"))
|
||||||
assert.NilError(t, flags.Set("label", "l2=baz"))
|
assert.NoError(t, flags.Set("label", "l2=baz"))
|
||||||
|
|
||||||
_, err := loadDaemonCliConfig(opts)
|
_, err := loadDaemonCliConfig(opts)
|
||||||
assert.Error(t, err, "as a flag and in the configuration file: labels")
|
testutil.ErrorContains(t, err, "as a flag and in the configuration file: labels")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
|
func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
|
||||||
|
@ -71,8 +73,8 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
|
||||||
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.TLS, true)
|
assert.Equal(t, loadedConfig.TLS, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +86,9 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
|
||||||
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.TLS, true)
|
assert.True(t, loadedConfig.TLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
|
func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
|
||||||
|
@ -97,9 +99,9 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
|
||||||
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
opts.common.TLSOptions.CAFile = "/tmp/ca.pem"
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.TLS, false)
|
assert.False(t, loadedConfig.TLS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
|
func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
|
||||||
|
@ -108,10 +110,10 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.LogLevel, "warn")
|
assert.Equal(t, "warn", loadedConfig.LogLevel)
|
||||||
assert.Equal(t, logrus.GetLevel(), logrus.WarnLevel)
|
assert.Equal(t, logrus.WarnLevel, logrus.GetLevel())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
|
func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
|
||||||
|
@ -121,10 +123,10 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.CommonTLSOptions.CAFile, "/etc/certs/ca.pem")
|
assert.Equal(t, "/etc/certs/ca.pem", loadedConfig.CommonTLSOptions.CAFile)
|
||||||
assert.Equal(t, loadedConfig.LogConfig.Type, "syslog")
|
assert.Equal(t, "syslog", loadedConfig.LogConfig.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
|
func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
|
||||||
|
@ -137,9 +139,9 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
|
|
||||||
assert.Equal(t, len(loadedConfig.Mirrors), 1)
|
assert.Len(t, loadedConfig.Mirrors, 1)
|
||||||
assert.Equal(t, len(loadedConfig.InsecureRegistries), 1)
|
assert.Len(t, loadedConfig.InsecureRegistries, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"github.com/docker/docker/pkg/testutil/tempfile"
|
"github.com/docker/docker/pkg/testutil/tempfile"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
||||||
|
@ -21,17 +22,17 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
opts.common.Debug = true
|
opts.common.Debug = true
|
||||||
opts.common.LogLevel = "info"
|
opts.common.LogLevel = "info"
|
||||||
assert.NilError(t, opts.flags.Set("selinux-enabled", "true"))
|
assert.NoError(t, opts.flags.Set("selinux-enabled", "true"))
|
||||||
|
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
|
|
||||||
assert.Equal(t, loadedConfig.Debug, true)
|
assert.True(t, loadedConfig.Debug)
|
||||||
assert.Equal(t, loadedConfig.LogLevel, "info")
|
assert.Equal(t, "info", loadedConfig.LogLevel)
|
||||||
assert.Equal(t, loadedConfig.EnableSelinuxSupport, true)
|
assert.True(t, loadedConfig.EnableSelinuxSupport)
|
||||||
assert.Equal(t, loadedConfig.LogConfig.Type, "json-file")
|
assert.Equal(t, "json-file", loadedConfig.LogConfig.Type)
|
||||||
assert.Equal(t, loadedConfig.LogConfig.Config["max-size"], "1k")
|
assert.Equal(t, "1k", loadedConfig.LogConfig.Config["max-size"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
|
func TestLoadDaemonConfigWithNetwork(t *testing.T) {
|
||||||
|
@ -41,11 +42,11 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
|
|
||||||
assert.Equal(t, loadedConfig.IP, "127.0.0.2")
|
assert.Equal(t, "127.0.0.2", loadedConfig.IP)
|
||||||
assert.Equal(t, loadedConfig.DefaultIP.String(), "127.0.0.1")
|
assert.Equal(t, "127.0.0.1", loadedConfig.DefaultIP.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
|
func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
|
||||||
|
@ -58,14 +59,14 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.NotNil(t, loadedConfig.ClusterOpts)
|
assert.NotNil(t, loadedConfig.ClusterOpts)
|
||||||
|
|
||||||
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
|
expectedPath := "/var/lib/docker/discovery_certs/ca.pem"
|
||||||
assert.Equal(t, loadedConfig.ClusterOpts["kv.cacertfile"], expectedPath)
|
assert.Equal(t, expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])
|
||||||
assert.NotNil(t, loadedConfig.LogConfig.Config)
|
assert.NotNil(t, loadedConfig.LogConfig.Config)
|
||||||
assert.Equal(t, loadedConfig.LogConfig.Config["tag"], "test")
|
assert.Equal(t, "test", loadedConfig.LogConfig.Config["tag"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
|
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
|
||||||
|
@ -75,18 +76,17 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.NotNil(t, loadedConfig.ClusterOpts)
|
|
||||||
|
|
||||||
assert.Equal(t, loadedConfig.EnableUserlandProxy, false)
|
assert.False(t, loadedConfig.EnableUserlandProxy)
|
||||||
|
|
||||||
// make sure reloading doesn't generate configuration
|
// make sure reloading doesn't generate configuration
|
||||||
// conflicts after normalizing boolean values.
|
// conflicts after normalizing boolean values.
|
||||||
reload := func(reloadedConfig *config.Config) {
|
reload := func(reloadedConfig *config.Config) {
|
||||||
assert.Equal(t, reloadedConfig.EnableUserlandProxy, false)
|
assert.False(t, reloadedConfig.EnableUserlandProxy)
|
||||||
}
|
}
|
||||||
assert.NilError(t, config.Reload(opts.configFile, opts.flags, reload))
|
assert.NoError(t, config.Reload(opts.configFile, opts.flags, reload))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
||||||
|
@ -95,11 +95,10 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.NotNil(t, loadedConfig.ClusterOpts)
|
|
||||||
|
|
||||||
assert.Equal(t, loadedConfig.EnableUserlandProxy, true)
|
assert.True(t, loadedConfig.EnableUserlandProxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
|
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
|
||||||
|
@ -109,7 +108,7 @@ func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
|
||||||
|
|
||||||
opts := defaultOptions(tempFile.Name())
|
opts := defaultOptions(tempFile.Name())
|
||||||
loadedConfig, err := loadDaemonCliConfig(opts)
|
loadedConfig, err := loadDaemonCliConfig(opts)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NotNil(t, loadedConfig)
|
require.NotNil(t, loadedConfig)
|
||||||
assert.Equal(t, loadedConfig.V2Only, true)
|
assert.True(t, loadedConfig.V2Only)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/daemon/discovery"
|
"github.com/docker/docker/daemon/discovery"
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDaemonConfigurationNotFound(t *testing.T) {
|
func TestDaemonConfigurationNotFound(t *testing.T) {
|
||||||
|
@ -61,9 +62,9 @@ func TestFindConfigurationConflicts(t *testing.T) {
|
||||||
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||||
|
|
||||||
flags.String("authorization-plugins", "", "")
|
flags.String("authorization-plugins", "", "")
|
||||||
assert.NilError(t, flags.Set("authorization-plugins", "asdf"))
|
assert.NoError(t, flags.Set("authorization-plugins", "asdf"))
|
||||||
|
|
||||||
assert.Error(t,
|
testutil.ErrorContains(t,
|
||||||
findConfigurationConflicts(config, flags),
|
findConfigurationConflicts(config, flags),
|
||||||
"authorization-plugins: (from flag: asdf, from file: foobar)")
|
"authorization-plugins: (from flag: asdf, from file: foobar)")
|
||||||
}
|
}
|
||||||
|
@ -74,10 +75,10 @@ func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) {
|
||||||
|
|
||||||
var hosts []string
|
var hosts []string
|
||||||
flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to")
|
flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to")
|
||||||
assert.NilError(t, flags.Set("host", "tcp://127.0.0.1:4444"))
|
assert.NoError(t, flags.Set("host", "tcp://127.0.0.1:4444"))
|
||||||
assert.NilError(t, flags.Set("host", "unix:///var/run/docker.sock"))
|
assert.NoError(t, flags.Set("host", "unix:///var/run/docker.sock"))
|
||||||
|
|
||||||
assert.Error(t, findConfigurationConflicts(config, flags), "hosts")
|
testutil.ErrorContains(t, findConfigurationConflicts(config, flags), "hosts")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDaemonConfigurationMergeConflicts(t *testing.T) {
|
func TestDaemonConfigurationMergeConflicts(t *testing.T) {
|
||||||
|
|
|
@ -9,12 +9,13 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newDaemonWithTmpRoot(t *testing.T) (*Daemon, func()) {
|
func newDaemonWithTmpRoot(t *testing.T) (*Daemon, func()) {
|
||||||
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
d := &Daemon{
|
d := &Daemon{
|
||||||
repository: tmp,
|
repository: tmp,
|
||||||
root: tmp,
|
root: tmp,
|
||||||
|
@ -40,8 +41,8 @@ func TestContainerDeletePaused(t *testing.T) {
|
||||||
|
|
||||||
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
||||||
|
|
||||||
assert.Error(t, err, "cannot remove a paused container")
|
testutil.ErrorContains(t, err, "cannot remove a paused container")
|
||||||
assert.Error(t, err, "Unpause and then stop the container before attempting removal or force remove")
|
testutil.ErrorContains(t, err, "Unpause and then stop the container before attempting removal or force remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestContainerDeleteRestarting tests that a useful error message and instructions is given when attempting
|
// TestContainerDeleteRestarting tests that a useful error message and instructions is given when attempting
|
||||||
|
@ -63,8 +64,8 @@ func TestContainerDeleteRestarting(t *testing.T) {
|
||||||
d.containers.Add(c.ID, c)
|
d.containers.Add(c.ID, c)
|
||||||
|
|
||||||
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
||||||
assert.Error(t, err, "cannot remove a restarting container")
|
testutil.ErrorContains(t, err, "cannot remove a restarting container")
|
||||||
assert.Error(t, err, "Stop the container before attempting removal or force remove")
|
testutil.ErrorContains(t, err, "Stop the container before attempting removal or force remove")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestContainerDeleteRunning tests that a useful error message and instructions is given when attempting
|
// TestContainerDeleteRunning tests that a useful error message and instructions is given when attempting
|
||||||
|
@ -83,8 +84,7 @@ func TestContainerDeleteRunning(t *testing.T) {
|
||||||
d.containers.Add(c.ID, c)
|
d.containers.Add(c.ID, c)
|
||||||
|
|
||||||
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false})
|
||||||
assert.Error(t, err, "cannot remove a running container")
|
testutil.ErrorContains(t, err, "cannot remove a running container")
|
||||||
assert.Error(t, err, "Stop the container before attempting removal or force remove")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerDoubleDelete(t *testing.T) {
|
func TestContainerDoubleDelete(t *testing.T) {
|
||||||
|
@ -106,5 +106,5 @@ func TestContainerDoubleDelete(t *testing.T) {
|
||||||
// Try to remove the container when its state is removalInProgress.
|
// Try to remove the container when its state is removalInProgress.
|
||||||
// It should return an error indicating it is under removal progress.
|
// It should return an error indicating it is under removal progress.
|
||||||
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true})
|
err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true})
|
||||||
assert.Error(t, err, fmt.Sprintf("removal of container %s is already in progress", c.ID))
|
testutil.ErrorContains(t, err, fmt.Sprintf("removal of container %s is already in progress", c.ID))
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,17 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultFSStoreBackend(t *testing.T) (StoreBackend, func()) {
|
func defaultFSStoreBackend(t *testing.T) (StoreBackend, func()) {
|
||||||
tmpdir, err := ioutil.TempDir("", "images-fs-store")
|
tmpdir, err := ioutil.TempDir("", "images-fs-store")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
fsBackend, err := NewFSStoreBackend(tmpdir)
|
fsBackend, err := NewFSStoreBackend(tmpdir)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
return fsBackend, func() { os.RemoveAll(tmpdir) }
|
return fsBackend, func() { os.RemoveAll(tmpdir) }
|
||||||
}
|
}
|
||||||
|
@ -30,15 +31,15 @@ func TestFSGetInvalidData(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := store.Set([]byte("foobar"))
|
id, err := store.Set([]byte("foobar"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
dgst := digest.Digest(id)
|
dgst := digest.Digest(id)
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600)
|
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = store.Get(id)
|
_, err = store.Get(id)
|
||||||
assert.Error(t, err, "failed to verify")
|
testutil.ErrorContains(t, err, "failed to verify")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSInvalidSet(t *testing.T) {
|
func TestFSInvalidSet(t *testing.T) {
|
||||||
|
@ -47,15 +48,15 @@ func TestFSInvalidSet(t *testing.T) {
|
||||||
|
|
||||||
id := digest.FromBytes([]byte("foobar"))
|
id := digest.FromBytes([]byte("foobar"))
|
||||||
err := os.Mkdir(filepath.Join(store.(*fs).root, contentDirName, string(id.Algorithm()), id.Hex()), 0700)
|
err := os.Mkdir(filepath.Join(store.(*fs).root, contentDirName, string(id.Algorithm()), id.Hex()), 0700)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = store.Set([]byte("foobar"))
|
_, err = store.Set([]byte("foobar"))
|
||||||
assert.Error(t, err, "failed to write digest data")
|
testutil.ErrorContains(t, err, "failed to write digest data")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSInvalidRoot(t *testing.T) {
|
func TestFSInvalidRoot(t *testing.T) {
|
||||||
tmpdir, err := ioutil.TempDir("", "images-fs-store")
|
tmpdir, err := ioutil.TempDir("", "images-fs-store")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
|
@ -70,14 +71,14 @@ func TestFSInvalidRoot(t *testing.T) {
|
||||||
root := filepath.Join(tmpdir, tc.root)
|
root := filepath.Join(tmpdir, tc.root)
|
||||||
filePath := filepath.Join(tmpdir, tc.invalidFile)
|
filePath := filepath.Join(tmpdir, tc.invalidFile)
|
||||||
err := os.MkdirAll(filepath.Dir(filePath), 0700)
|
err := os.MkdirAll(filepath.Dir(filePath), 0700)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
f, err := os.Create(filePath)
|
f, err := os.Create(filePath)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
_, err = NewFSStoreBackend(root)
|
_, err = NewFSStoreBackend(root)
|
||||||
assert.Error(t, err, "failed to create storage backend")
|
testutil.ErrorContains(t, err, "failed to create storage backend")
|
||||||
|
|
||||||
os.RemoveAll(root)
|
os.RemoveAll(root)
|
||||||
}
|
}
|
||||||
|
@ -89,10 +90,10 @@ func TestFSMetadataGetSet(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := store.Set([]byte("foo"))
|
id, err := store.Set([]byte("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id2, err := store.Set([]byte("bar"))
|
id2, err := store.Set([]byte("bar"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
id digest.Digest
|
id digest.Digest
|
||||||
|
@ -106,10 +107,10 @@ func TestFSMetadataGetSet(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
err = store.SetMetadata(tc.id, tc.key, tc.value)
|
err = store.SetMetadata(tc.id, tc.key, tc.value)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
actual, err := store.GetMetadata(tc.id, tc.key)
|
actual, err := store.GetMetadata(tc.id, tc.key)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
if bytes.Compare(actual, tc.value) != 0 {
|
if bytes.Compare(actual, tc.value) != 0 {
|
||||||
t.Fatalf("Metadata expected %q, got %q", tc.value, actual)
|
t.Fatalf("Metadata expected %q, got %q", tc.value, actual)
|
||||||
|
@ -117,14 +118,14 @@ func TestFSMetadataGetSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = store.GetMetadata(id2, "tkey2")
|
_, err = store.GetMetadata(id2, "tkey2")
|
||||||
assert.Error(t, err, "failed to read metadata")
|
testutil.ErrorContains(t, err, "failed to read metadata")
|
||||||
|
|
||||||
id3 := digest.FromBytes([]byte("baz"))
|
id3 := digest.FromBytes([]byte("baz"))
|
||||||
err = store.SetMetadata(id3, "tkey", []byte("tval"))
|
err = store.SetMetadata(id3, "tkey", []byte("tval"))
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
|
|
||||||
_, err = store.GetMetadata(id3, "tkey")
|
_, err = store.GetMetadata(id3, "tkey")
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSInvalidWalker(t *testing.T) {
|
func TestFSInvalidWalker(t *testing.T) {
|
||||||
|
@ -132,19 +133,19 @@ func TestFSInvalidWalker(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
fooID, err := store.Set([]byte("foo"))
|
fooID, err := store.Set([]byte("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, "sha256/foobar"), []byte("foobar"), 0600)
|
err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, "sha256/foobar"), []byte("foobar"), 0600)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
n := 0
|
n := 0
|
||||||
err = store.Walk(func(id digest.Digest) error {
|
err = store.Walk(func(id digest.Digest) error {
|
||||||
assert.Equal(t, id, fooID)
|
assert.Equal(t, fooID, id)
|
||||||
n++
|
n++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, n, 1)
|
assert.Equal(t, 1, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSGetSet(t *testing.T) {
|
func TestFSGetSet(t *testing.T) {
|
||||||
|
@ -161,12 +162,12 @@ func TestFSGetSet(t *testing.T) {
|
||||||
|
|
||||||
randomInput := make([]byte, 8*1024)
|
randomInput := make([]byte, 8*1024)
|
||||||
_, err := rand.Read(randomInput)
|
_, err := rand.Read(randomInput)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// skipping use of digest pkg because it is used by the implementation
|
// skipping use of digest pkg because it is used by the implementation
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
_, err = h.Write(randomInput)
|
_, err = h.Write(randomInput)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
tcases = append(tcases, tcase{
|
tcases = append(tcases, tcase{
|
||||||
input: randomInput,
|
input: randomInput,
|
||||||
|
@ -175,13 +176,13 @@ func TestFSGetSet(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
id, err := store.Set([]byte(tc.input))
|
id, err := store.Set([]byte(tc.input))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id, tc.expected)
|
assert.Equal(t, tc.expected, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
data, err := store.Get(tc.expected)
|
data, err := store.Get(tc.expected)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
if bytes.Compare(data, tc.input) != 0 {
|
if bytes.Compare(data, tc.input) != 0 {
|
||||||
t.Fatalf("expected data %q, got %q", tc.input, data)
|
t.Fatalf("expected data %q, got %q", tc.input, data)
|
||||||
}
|
}
|
||||||
|
@ -194,7 +195,7 @@ func TestFSGetUnsetKey(t *testing.T) {
|
||||||
|
|
||||||
for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
|
for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
|
||||||
_, err := store.Get(key)
|
_, err := store.Get(key)
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +205,7 @@ func TestFSGetEmptyData(t *testing.T) {
|
||||||
|
|
||||||
for _, emptyData := range [][]byte{nil, {}} {
|
for _, emptyData := range [][]byte{nil, {}} {
|
||||||
_, err := store.Set(emptyData)
|
_, err := store.Set(emptyData)
|
||||||
assert.Error(t, err, "invalid empty data")
|
testutil.ErrorContains(t, err, "invalid empty data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,25 +214,25 @@ func TestFSDelete(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := store.Set([]byte("foo"))
|
id, err := store.Set([]byte("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id2, err := store.Set([]byte("bar"))
|
id2, err := store.Set([]byte("bar"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = store.Delete(id)
|
err = store.Delete(id)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = store.Get(id)
|
_, err = store.Get(id)
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
|
|
||||||
_, err = store.Get(id2)
|
_, err = store.Get(id2)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = store.Delete(id2)
|
err = store.Delete(id2)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = store.Get(id2)
|
_, err = store.Get(id2)
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSWalker(t *testing.T) {
|
func TestFSWalker(t *testing.T) {
|
||||||
|
@ -239,10 +240,10 @@ func TestFSWalker(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := store.Set([]byte("foo"))
|
id, err := store.Set([]byte("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id2, err := store.Set([]byte("bar"))
|
id2, err := store.Set([]byte("bar"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
tcases := make(map[digest.Digest]struct{})
|
tcases := make(map[digest.Digest]struct{})
|
||||||
tcases[id] = struct{}{}
|
tcases[id] = struct{}{}
|
||||||
|
@ -253,9 +254,9 @@ func TestFSWalker(t *testing.T) {
|
||||||
n++
|
n++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, n, 2)
|
assert.Equal(t, 2, n)
|
||||||
assert.Equal(t, len(tcases), 0)
|
assert.Len(t, tcases, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFSWalkerStopOnError(t *testing.T) {
|
func TestFSWalkerStopOnError(t *testing.T) {
|
||||||
|
@ -263,12 +264,12 @@ func TestFSWalkerStopOnError(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := store.Set([]byte("foo"))
|
id, err := store.Set([]byte("foo"))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
tcases := make(map[digest.Digest]struct{})
|
tcases := make(map[digest.Digest]struct{})
|
||||||
tcases[id] = struct{}{}
|
tcases[id] = struct{}{}
|
||||||
err = store.Walk(func(id digest.Digest) error {
|
err = store.Walk(func(id digest.Digest) error {
|
||||||
return errors.New("what")
|
return errors.New("what")
|
||||||
})
|
})
|
||||||
assert.Error(t, err, "what")
|
testutil.ErrorContains(t, err, "what")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sampleImageJSON = `{
|
const sampleImageJSON = `{
|
||||||
|
@ -21,13 +22,13 @@ const sampleImageJSON = `{
|
||||||
|
|
||||||
func TestNewFromJSON(t *testing.T) {
|
func TestNewFromJSON(t *testing.T) {
|
||||||
img, err := NewFromJSON([]byte(sampleImageJSON))
|
img, err := NewFromJSON([]byte(sampleImageJSON))
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, string(img.RawJSON()), sampleImageJSON)
|
assert.Equal(t, sampleImageJSON, string(img.RawJSON()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewFromJSONWithInvalidJSON(t *testing.T) {
|
func TestNewFromJSONWithInvalidJSON(t *testing.T) {
|
||||||
_, err := NewFromJSON([]byte("{}"))
|
_, err := NewFromJSON([]byte("{}"))
|
||||||
assert.Error(t, err, "invalid image JSON, no RootFS key")
|
assert.EqualError(t, err, "invalid image JSON, no RootFS key")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalKeyOrder(t *testing.T) {
|
func TestMarshalKeyOrder(t *testing.T) {
|
||||||
|
@ -38,7 +39,7 @@ func TestMarshalKeyOrder(t *testing.T) {
|
||||||
Architecture: "c",
|
Architecture: "c",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
expectedOrder := []string{"architecture", "author", "comment"}
|
expectedOrder := []string{"architecture", "author", "comment"}
|
||||||
var indexes []int
|
var indexes []int
|
||||||
|
|
|
@ -4,8 +4,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/layer"
|
"github.com/docker/docker/layer"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRestore(t *testing.T) {
|
func TestRestore(t *testing.T) {
|
||||||
|
@ -13,55 +14,55 @@ func TestRestore(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
|
id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = fs.Set([]byte(`invalid`))
|
_, err = fs.Set([]byte(`invalid`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = fs.SetMetadata(id2, "parent", []byte(id1))
|
err = fs.SetMetadata(id2, "parent", []byte(id1))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
|
is, err := NewImageStore(fs, &mockLayerGetReleaser{})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, len(is.Map()), 2)
|
assert.Len(t, is.Map(), 2)
|
||||||
|
|
||||||
img1, err := is.Get(ID(id1))
|
img1, err := is.Get(ID(id1))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, img1.computedID, ID(id1))
|
assert.Equal(t, ID(id1), img1.computedID)
|
||||||
assert.Equal(t, img1.computedID.String(), string(id1))
|
assert.Equal(t, string(id1), img1.computedID.String())
|
||||||
|
|
||||||
img2, err := is.Get(ID(id2))
|
img2, err := is.Get(ID(id2))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, img1.Comment, "abc")
|
assert.Equal(t, "abc", img1.Comment)
|
||||||
assert.Equal(t, img2.Comment, "def")
|
assert.Equal(t, "def", img2.Comment)
|
||||||
|
|
||||||
p, err := is.GetParent(ID(id1))
|
p, err := is.GetParent(ID(id1))
|
||||||
assert.Error(t, err, "failed to read metadata")
|
testutil.ErrorContains(t, err, "failed to read metadata")
|
||||||
|
|
||||||
p, err = is.GetParent(ID(id2))
|
p, err = is.GetParent(ID(id2))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, p, ID(id1))
|
assert.Equal(t, ID(id1), p)
|
||||||
|
|
||||||
children := is.Children(ID(id1))
|
children := is.Children(ID(id1))
|
||||||
assert.Equal(t, len(children), 1)
|
assert.Len(t, children, 1)
|
||||||
assert.Equal(t, children[0], ID(id2))
|
assert.Equal(t, ID(id2), children[0])
|
||||||
assert.Equal(t, len(is.Heads()), 1)
|
assert.Len(t, is.Heads(), 1)
|
||||||
|
|
||||||
sid1, err := is.Search(string(id1)[:10])
|
sid1, err := is.Search(string(id1)[:10])
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, sid1, ID(id1))
|
assert.Equal(t, ID(id1), sid1)
|
||||||
|
|
||||||
sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
|
sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, sid1, ID(id1))
|
assert.Equal(t, ID(id1), sid1)
|
||||||
|
|
||||||
invalidPattern := digest.Digest(id1).Hex()[1:6]
|
invalidPattern := digest.Digest(id1).Hex()[1:6]
|
||||||
_, err = is.Search(invalidPattern)
|
_, err = is.Search(invalidPattern)
|
||||||
assert.Error(t, err, "No such image")
|
testutil.ErrorContains(t, err, "No such image")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddDelete(t *testing.T) {
|
func TestAddDelete(t *testing.T) {
|
||||||
|
@ -69,34 +70,34 @@ func TestAddDelete(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id1, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"))
|
assert.Equal(t, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1)
|
||||||
|
|
||||||
img, err := is.Get(id1)
|
img, err := is.Get(id1)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, img.Comment, "abc")
|
assert.Equal(t, "abc", img.Comment)
|
||||||
|
|
||||||
id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
err = is.SetParent(id2, id1)
|
err = is.SetParent(id2, id1)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
pid1, err := is.GetParent(id2)
|
pid1, err := is.GetParent(id2)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, pid1, id1)
|
assert.Equal(t, pid1, id1)
|
||||||
|
|
||||||
_, err = is.Delete(id1)
|
_, err = is.Delete(id1)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = is.Get(id1)
|
_, err = is.Get(id1)
|
||||||
assert.Error(t, err, "failed to get digest")
|
testutil.ErrorContains(t, err, "failed to get digest")
|
||||||
|
|
||||||
_, err = is.Get(id2)
|
_, err = is.Get(id2)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = is.GetParent(id2)
|
_, err = is.GetParent(id2)
|
||||||
assert.Error(t, err, "failed to read metadata")
|
testutil.ErrorContains(t, err, "failed to read metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchAfterDelete(t *testing.T) {
|
func TestSearchAfterDelete(t *testing.T) {
|
||||||
|
@ -104,17 +105,17 @@ func TestSearchAfterDelete(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
|
id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id1, err := is.Search(string(id)[:15])
|
id1, err := is.Search(string(id)[:15])
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, id1, id)
|
assert.Equal(t, id1, id)
|
||||||
|
|
||||||
_, err = is.Delete(id)
|
_, err = is.Delete(id)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = is.Search(string(id)[:15])
|
_, err = is.Search(string(id)[:15])
|
||||||
assert.Error(t, err, "No such image")
|
testutil.ErrorContains(t, err, "No such image")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParentReset(t *testing.T) {
|
func TestParentReset(t *testing.T) {
|
||||||
|
@ -122,27 +123,27 @@ func TestParentReset(t *testing.T) {
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
|
id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
|
id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
|
id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.NilError(t, is.SetParent(id, id2))
|
assert.NoError(t, is.SetParent(id, id2))
|
||||||
assert.Equal(t, len(is.Children(id2)), 1)
|
assert.Len(t, is.Children(id2), 1)
|
||||||
|
|
||||||
assert.NilError(t, is.SetParent(id, id3))
|
assert.NoError(t, is.SetParent(id, id3))
|
||||||
assert.Equal(t, len(is.Children(id2)), 0)
|
assert.Len(t, is.Children(id2), 0)
|
||||||
assert.Equal(t, len(is.Children(id3)), 1)
|
assert.Len(t, is.Children(id3), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultImageStore(t *testing.T) (Store, func()) {
|
func defaultImageStore(t *testing.T) (Store, func()) {
|
||||||
fsBackend, cleanup := defaultFSStoreBackend(t)
|
fsBackend, cleanup := defaultFSStoreBackend(t)
|
||||||
|
|
||||||
store, err := NewImageStore(fsBackend, &mockLayerGetReleaser{})
|
store, err := NewImageStore(fsBackend, &mockLayerGetReleaser{})
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
return store, cleanup
|
return store, cleanup
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
mounttypes "github.com/docker/docker/api/types/mount"
|
mounttypes "github.com/docker/docker/api/types/mount"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMountOptString(t *testing.T) {
|
func TestMountOptString(t *testing.T) {
|
||||||
|
@ -24,7 +26,7 @@ func TestMountOptString(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := "bind /home/path /target, volume foo /target/foo"
|
expected := "bind /home/path /target, volume foo /target/foo"
|
||||||
assert.Equal(t, mount.String(), expected)
|
assert.Equal(t, expected, mount.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetBindNoErrorBind(t *testing.T) {
|
func TestMountOptSetBindNoErrorBind(t *testing.T) {
|
||||||
|
@ -37,15 +39,15 @@ func TestMountOptSetBindNoErrorBind(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
|
|
||||||
assert.NilError(t, mount.Set(testcase))
|
assert.NoError(t, mount.Set(testcase))
|
||||||
|
|
||||||
mounts := mount.Value()
|
mounts := mount.Value()
|
||||||
assert.Equal(t, len(mounts), 1)
|
require.Len(t, mounts, 1)
|
||||||
assert.Equal(t, mounts[0], mounttypes.Mount{
|
assert.Equal(t, mounttypes.Mount{
|
||||||
Type: mounttypes.TypeBind,
|
Type: mounttypes.TypeBind,
|
||||||
Source: "/source",
|
Source: "/source",
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
})
|
}, mounts[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,15 +61,15 @@ func TestMountOptSetVolumeNoError(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
|
|
||||||
assert.NilError(t, mount.Set(testcase))
|
assert.NoError(t, mount.Set(testcase))
|
||||||
|
|
||||||
mounts := mount.Value()
|
mounts := mount.Value()
|
||||||
assert.Equal(t, len(mounts), 1)
|
require.Len(t, mounts, 1)
|
||||||
assert.Equal(t, mounts[0], mounttypes.Mount{
|
assert.Equal(t, mounttypes.Mount{
|
||||||
Type: mounttypes.TypeVolume,
|
Type: mounttypes.TypeVolume,
|
||||||
Source: "/source",
|
Source: "/source",
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
})
|
}, mounts[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,82 +77,82 @@ func TestMountOptSetVolumeNoError(t *testing.T) {
|
||||||
// volume mount.
|
// volume mount.
|
||||||
func TestMountOptDefaultType(t *testing.T) {
|
func TestMountOptDefaultType(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
assert.NilError(t, mount.Set("target=/target,source=/foo"))
|
assert.NoError(t, mount.Set("target=/target,source=/foo"))
|
||||||
assert.Equal(t, mount.values[0].Type, mounttypes.TypeVolume)
|
assert.Equal(t, mounttypes.TypeVolume, mount.values[0].Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetErrorNoTarget(t *testing.T) {
|
func TestMountOptSetErrorNoTarget(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
assert.Error(t, mount.Set("type=volume,source=/foo"), "target is required")
|
assert.EqualError(t, mount.Set("type=volume,source=/foo"), "target is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetErrorInvalidKey(t *testing.T) {
|
func TestMountOptSetErrorInvalidKey(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
assert.Error(t, mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus'")
|
assert.EqualError(t, mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus' in 'bogus=foo'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetErrorInvalidField(t *testing.T) {
|
func TestMountOptSetErrorInvalidField(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
assert.Error(t, mount.Set("type=volume,bogus"), "invalid field 'bogus'")
|
assert.EqualError(t, mount.Set("type=volume,bogus"), "invalid field 'bogus' must be a key=value pair")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetErrorInvalidReadOnly(t *testing.T) {
|
func TestMountOptSetErrorInvalidReadOnly(t *testing.T) {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
assert.Error(t, mount.Set("type=volume,readonly=no"), "invalid value for readonly: no")
|
assert.EqualError(t, mount.Set("type=volume,readonly=no"), "invalid value for readonly: no")
|
||||||
assert.Error(t, mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid")
|
assert.EqualError(t, mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptDefaultEnableReadOnly(t *testing.T) {
|
func TestMountOptDefaultEnableReadOnly(t *testing.T) {
|
||||||
var m MountOpt
|
var m MountOpt
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo"))
|
assert.NoError(t, m.Set("type=bind,target=/foo,source=/foo"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, false)
|
assert.False(t, m.values[0].ReadOnly)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
|
assert.NoError(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
assert.True(t, m.values[0].ReadOnly)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
|
assert.NoError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
assert.True(t, m.values[0].ReadOnly)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true"))
|
assert.NoError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, true)
|
assert.True(t, m.values[0].ReadOnly)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
assert.NoError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
|
||||||
assert.Equal(t, m.values[0].ReadOnly, false)
|
assert.False(t, m.values[0].ReadOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptVolumeNoCopy(t *testing.T) {
|
func TestMountOptVolumeNoCopy(t *testing.T) {
|
||||||
var m MountOpt
|
var m MountOpt
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy"))
|
assert.NoError(t, m.Set("type=volume,target=/foo,volume-nocopy"))
|
||||||
assert.Equal(t, m.values[0].Source, "")
|
assert.Equal(t, "", m.values[0].Source)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
|
assert.NoError(t, m.Set("type=volume,target=/foo,source=foo"))
|
||||||
assert.Equal(t, m.values[0].VolumeOptions == nil, true)
|
assert.True(t, m.values[0].VolumeOptions == nil)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true"))
|
assert.NoError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true"))
|
||||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
assert.True(t, m.values[0].VolumeOptions != nil)
|
||||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
assert.True(t, m.values[0].VolumeOptions.NoCopy)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy"))
|
assert.NoError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy"))
|
||||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
assert.True(t, m.values[0].VolumeOptions != nil)
|
||||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
assert.True(t, m.values[0].VolumeOptions.NoCopy)
|
||||||
|
|
||||||
m = MountOpt{}
|
m = MountOpt{}
|
||||||
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1"))
|
assert.NoError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1"))
|
||||||
assert.Equal(t, m.values[0].VolumeOptions != nil, true)
|
assert.True(t, m.values[0].VolumeOptions != nil)
|
||||||
assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true)
|
assert.True(t, m.values[0].VolumeOptions.NoCopy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptTypeConflict(t *testing.T) {
|
func TestMountOptTypeConflict(t *testing.T) {
|
||||||
var m MountOpt
|
var m MountOpt
|
||||||
assert.Error(t, m.Set("type=bind,target=/foo,source=/foo,volume-nocopy=true"), "cannot mix")
|
testutil.ErrorContains(t, m.Set("type=bind,target=/foo,source=/foo,volume-nocopy=true"), "cannot mix")
|
||||||
assert.Error(t, m.Set("type=volume,target=/foo,source=/foo,bind-propagation=rprivate"), "cannot mix")
|
testutil.ErrorContains(t, m.Set("type=volume,target=/foo,source=/foo,bind-propagation=rprivate"), "cannot mix")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetTmpfsNoError(t *testing.T) {
|
func TestMountOptSetTmpfsNoError(t *testing.T) {
|
||||||
|
@ -161,24 +163,24 @@ func TestMountOptSetTmpfsNoError(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
var mount MountOpt
|
var mount MountOpt
|
||||||
|
|
||||||
assert.NilError(t, mount.Set(testcase))
|
assert.NoError(t, mount.Set(testcase))
|
||||||
|
|
||||||
mounts := mount.Value()
|
mounts := mount.Value()
|
||||||
assert.Equal(t, len(mounts), 1)
|
require.Len(t, mounts, 1)
|
||||||
assert.DeepEqual(t, mounts[0], mounttypes.Mount{
|
assert.Equal(t, mounttypes.Mount{
|
||||||
Type: mounttypes.TypeTmpfs,
|
Type: mounttypes.TypeTmpfs,
|
||||||
Target: "/target",
|
Target: "/target",
|
||||||
TmpfsOptions: &mounttypes.TmpfsOptions{
|
TmpfsOptions: &mounttypes.TmpfsOptions{
|
||||||
SizeBytes: 1024 * 1024, // not 1000 * 1000
|
SizeBytes: 1024 * 1024, // not 1000 * 1000
|
||||||
Mode: os.FileMode(0700),
|
Mode: os.FileMode(0700),
|
||||||
},
|
},
|
||||||
})
|
}, mounts[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountOptSetTmpfsError(t *testing.T) {
|
func TestMountOptSetTmpfsError(t *testing.T) {
|
||||||
var m MountOpt
|
var m MountOpt
|
||||||
assert.Error(t, m.Set("type=tmpfs,target=/foo,tmpfs-size=foo"), "invalid value for tmpfs-size")
|
testutil.ErrorContains(t, m.Set("type=tmpfs,target=/foo,tmpfs-size=foo"), "invalid value for tmpfs-size")
|
||||||
assert.Error(t, m.Set("type=tmpfs,target=/foo,tmpfs-mode=foo"), "invalid value for tmpfs-mode")
|
testutil.ErrorContains(t, m.Set("type=tmpfs,target=/foo,tmpfs-mode=foo"), "invalid value for tmpfs-mode")
|
||||||
assert.Error(t, m.Set("type=tmpfs"), "target is required")
|
testutil.ErrorContains(t, m.Set("type=tmpfs"), "target is required")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/docker/docker/pkg/testutil"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPortOptValidSimpleSyntax(t *testing.T) {
|
func TestPortOptValidSimpleSyntax(t *testing.T) {
|
||||||
|
@ -98,8 +99,8 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var port PortOpt
|
var port PortOpt
|
||||||
assert.NilError(t, port.Set(tc.value))
|
assert.NoError(t, port.Set(tc.value))
|
||||||
assert.Equal(t, len(port.Value()), len(tc.expected))
|
assert.Len(t, port.Value(), len(tc.expected))
|
||||||
for _, expectedPortConfig := range tc.expected {
|
for _, expectedPortConfig := range tc.expected {
|
||||||
assertContains(t, port.Value(), expectedPortConfig)
|
assertContains(t, port.Value(), expectedPortConfig)
|
||||||
}
|
}
|
||||||
|
@ -189,8 +190,8 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var port PortOpt
|
var port PortOpt
|
||||||
assert.NilError(t, port.Set(tc.value))
|
assert.NoError(t, port.Set(tc.value))
|
||||||
assert.Equal(t, len(port.Value()), len(tc.expected))
|
assert.Len(t, port.Value(), len(tc.expected))
|
||||||
for _, expectedPortConfig := range tc.expected {
|
for _, expectedPortConfig := range tc.expected {
|
||||||
assertContains(t, port.Value(), expectedPortConfig)
|
assertContains(t, port.Value(), expectedPortConfig)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +242,7 @@ func TestPortOptInvalidComplexSyntax(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var port PortOpt
|
var port PortOpt
|
||||||
assert.Error(t, port.Set(tc.value), tc.expectedError)
|
testutil.ErrorContains(t, port.Set(tc.value), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,16 +269,16 @@ func TestPortOptInvalidSimpleSyntax(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "",
|
value: "",
|
||||||
expectedError: "No port specified",
|
expectedError: "No port specified: <empty>",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: "1.1.1.1:80:80",
|
value: "1.1.1.1:80:80",
|
||||||
expectedError: "HostIP is not supported",
|
expectedError: "HostIP is not supported.",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
var port PortOpt
|
var port PortOpt
|
||||||
assert.Error(t, port.Set(tc.value), tc.expectedError)
|
assert.EqualError(t, port.Set(tc.value), tc.expectedError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,29 @@
|
||||||
package opts
|
package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestQuotedStringSetWithQuotes(t *testing.T) {
|
func TestQuotedStringSetWithQuotes(t *testing.T) {
|
||||||
value := ""
|
value := ""
|
||||||
qs := NewQuotedString(&value)
|
qs := NewQuotedString(&value)
|
||||||
assert.NilError(t, qs.Set("\"something\""))
|
assert.NoError(t, qs.Set(`"something"`))
|
||||||
assert.Equal(t, qs.String(), "something")
|
assert.Equal(t, "something", qs.String())
|
||||||
assert.Equal(t, value, "something")
|
assert.Equal(t, "something", value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
|
||||||
value := ""
|
value := ""
|
||||||
qs := NewQuotedString(&value)
|
qs := NewQuotedString(&value)
|
||||||
assert.NilError(t, qs.Set("\"something'"))
|
assert.NoError(t, qs.Set(`"something'`))
|
||||||
assert.Equal(t, qs.String(), "\"something'")
|
assert.Equal(t, `"something'`, qs.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
|
||||||
value := ""
|
value := ""
|
||||||
qs := NewQuotedString(&value)
|
qs := NewQuotedString(&value)
|
||||||
assert.NilError(t, qs.Set("something"))
|
assert.NoError(t, qs.Set("something"))
|
||||||
assert.Equal(t, qs.String(), "something")
|
assert.Equal(t, "something", qs.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,76 +4,77 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecretOptionsSimple(t *testing.T) {
|
func TestSecretOptionsSimple(t *testing.T) {
|
||||||
var opt SecretOpt
|
var opt SecretOpt
|
||||||
|
|
||||||
testCase := "app-secret"
|
testCase := "app-secret"
|
||||||
assert.NilError(t, opt.Set(testCase))
|
assert.NoError(t, opt.Set(testCase))
|
||||||
|
|
||||||
reqs := opt.Value()
|
reqs := opt.Value()
|
||||||
assert.Equal(t, len(reqs), 1)
|
require.Len(t, reqs, 1)
|
||||||
req := reqs[0]
|
req := reqs[0]
|
||||||
assert.Equal(t, req.SecretName, "app-secret")
|
assert.Equal(t, "app-secret", req.SecretName)
|
||||||
assert.Equal(t, req.File.Name, "app-secret")
|
assert.Equal(t, "app-secret", req.File.Name)
|
||||||
assert.Equal(t, req.File.UID, "0")
|
assert.Equal(t, "0", req.File.UID)
|
||||||
assert.Equal(t, req.File.GID, "0")
|
assert.Equal(t, "0", req.File.GID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretOptionsSourceTarget(t *testing.T) {
|
func TestSecretOptionsSourceTarget(t *testing.T) {
|
||||||
var opt SecretOpt
|
var opt SecretOpt
|
||||||
|
|
||||||
testCase := "source=foo,target=testing"
|
testCase := "source=foo,target=testing"
|
||||||
assert.NilError(t, opt.Set(testCase))
|
assert.NoError(t, opt.Set(testCase))
|
||||||
|
|
||||||
reqs := opt.Value()
|
reqs := opt.Value()
|
||||||
assert.Equal(t, len(reqs), 1)
|
require.Len(t, reqs, 1)
|
||||||
req := reqs[0]
|
req := reqs[0]
|
||||||
assert.Equal(t, req.SecretName, "foo")
|
assert.Equal(t, "foo", req.SecretName)
|
||||||
assert.Equal(t, req.File.Name, "testing")
|
assert.Equal(t, "testing", req.File.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretOptionsShorthand(t *testing.T) {
|
func TestSecretOptionsShorthand(t *testing.T) {
|
||||||
var opt SecretOpt
|
var opt SecretOpt
|
||||||
|
|
||||||
testCase := "src=foo,target=testing"
|
testCase := "src=foo,target=testing"
|
||||||
assert.NilError(t, opt.Set(testCase))
|
assert.NoError(t, opt.Set(testCase))
|
||||||
|
|
||||||
reqs := opt.Value()
|
reqs := opt.Value()
|
||||||
assert.Equal(t, len(reqs), 1)
|
require.Len(t, reqs, 1)
|
||||||
req := reqs[0]
|
req := reqs[0]
|
||||||
assert.Equal(t, req.SecretName, "foo")
|
assert.Equal(t, "foo", req.SecretName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
||||||
var opt SecretOpt
|
var opt SecretOpt
|
||||||
|
|
||||||
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
||||||
assert.NilError(t, opt.Set(testCase))
|
assert.NoError(t, opt.Set(testCase))
|
||||||
|
|
||||||
reqs := opt.Value()
|
reqs := opt.Value()
|
||||||
assert.Equal(t, len(reqs), 1)
|
require.Len(t, reqs, 1)
|
||||||
req := reqs[0]
|
req := reqs[0]
|
||||||
assert.Equal(t, req.SecretName, "foo")
|
assert.Equal(t, "foo", req.SecretName)
|
||||||
assert.Equal(t, req.File.Name, "testing")
|
assert.Equal(t, "testing", req.File.Name)
|
||||||
assert.Equal(t, req.File.UID, "1000")
|
assert.Equal(t, "1000", req.File.UID)
|
||||||
assert.Equal(t, req.File.GID, "1001")
|
assert.Equal(t, "1001", req.File.GID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSecretOptionsCustomMode(t *testing.T) {
|
func TestSecretOptionsCustomMode(t *testing.T) {
|
||||||
var opt SecretOpt
|
var opt SecretOpt
|
||||||
|
|
||||||
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
||||||
assert.NilError(t, opt.Set(testCase))
|
assert.NoError(t, opt.Set(testCase))
|
||||||
|
|
||||||
reqs := opt.Value()
|
reqs := opt.Value()
|
||||||
assert.Equal(t, len(reqs), 1)
|
require.Len(t, reqs, 1)
|
||||||
req := reqs[0]
|
req := reqs[0]
|
||||||
assert.Equal(t, req.SecretName, "foo")
|
assert.Equal(t, "foo", req.SecretName)
|
||||||
assert.Equal(t, req.File.Name, "testing")
|
assert.Equal(t, "testing", req.File.Name)
|
||||||
assert.Equal(t, req.File.UID, "1000")
|
assert.Equal(t, "1000", req.File.UID)
|
||||||
assert.Equal(t, req.File.GID, "1001")
|
assert.Equal(t, "1001", req.File.GID)
|
||||||
assert.Equal(t, req.File.Mode, os.FileMode(0444))
|
assert.Equal(t, os.FileMode(0444), req.File.Mode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tmp string
|
var tmp string
|
||||||
|
@ -1211,19 +1212,19 @@ func TestReplaceFileTarWrapper(t *testing.T) {
|
||||||
map[string]TarModifierFunc{testcase.filename: testcase.modifier})
|
map[string]TarModifierFunc{testcase.filename: testcase.modifier})
|
||||||
|
|
||||||
actual := readFileFromArchive(t, resultArchive, testcase.filename, testcase.fileCount, testcase.doc)
|
actual := readFileFromArchive(t, resultArchive, testcase.filename, testcase.fileCount, testcase.doc)
|
||||||
assert.Equal(t, actual, testcase.expected, testcase.doc)
|
assert.Equal(t, testcase.expected, actual, testcase.doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildSourceArchive(t *testing.T, numberOfFiles int) (io.ReadCloser, func()) {
|
func buildSourceArchive(t *testing.T, numberOfFiles int) (io.ReadCloser, func()) {
|
||||||
srcDir, err := ioutil.TempDir("", "docker-test-srcDir")
|
srcDir, err := ioutil.TempDir("", "docker-test-srcDir")
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = prepareUntarSourceDirectory(numberOfFiles, srcDir, false)
|
_, err = prepareUntarSourceDirectory(numberOfFiles, srcDir, false)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
sourceArchive, err := TarWithOptions(srcDir, &TarOptions{})
|
sourceArchive, err := TarWithOptions(srcDir, &TarOptions{})
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
return sourceArchive, func() {
|
return sourceArchive, func() {
|
||||||
os.RemoveAll(srcDir)
|
os.RemoveAll(srcDir)
|
||||||
sourceArchive.Close()
|
sourceArchive.Close()
|
||||||
|
@ -1257,16 +1258,16 @@ func appendModifier(path string, header *tar.Header, content io.Reader) (*tar.He
|
||||||
|
|
||||||
func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expectedCount int, doc string) string {
|
func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expectedCount int, doc string) string {
|
||||||
destDir, err := ioutil.TempDir("", "docker-test-destDir")
|
destDir, err := ioutil.TempDir("", "docker-test-destDir")
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(destDir)
|
defer os.RemoveAll(destDir)
|
||||||
|
|
||||||
err = Untar(archive, destDir, nil)
|
err = Untar(archive, destDir, nil)
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
files, _ := ioutil.ReadDir(destDir)
|
files, _ := ioutil.ReadDir(destDir)
|
||||||
assert.Equal(t, len(files), expectedCount, doc)
|
assert.Len(t, files, expectedCount, doc)
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(filepath.Join(destDir, name))
|
content, err := ioutil.ReadFile(filepath.Join(destDir, name))
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
return string(content)
|
return string(content)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,27 +4,27 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseStringFunctions(t *testing.T) {
|
func TestParseStringFunctions(t *testing.T) {
|
||||||
tm, err := Parse(`{{join (split . ":") "/"}}`)
|
tm, err := Parse(`{{join (split . ":") "/"}}`)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
assert.NilError(t, tm.Execute(&b, "text:with:colon"))
|
assert.NoError(t, tm.Execute(&b, "text:with:colon"))
|
||||||
want := "text/with/colon"
|
want := "text/with/colon"
|
||||||
assert.Equal(t, b.String(), want)
|
assert.Equal(t, want, b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewParse(t *testing.T) {
|
func TestNewParse(t *testing.T) {
|
||||||
tm, err := NewParse("foo", "this is a {{ . }}")
|
tm, err := NewParse("foo", "this is a {{ . }}")
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
assert.NilError(t, tm.Execute(&b, "string"))
|
assert.NoError(t, tm.Execute(&b, "string"))
|
||||||
want := "this is a string"
|
want := "this is a string"
|
||||||
assert.Equal(t, b.String(), want)
|
assert.Equal(t, want, b.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseTruncateFunction(t *testing.T) {
|
func TestParseTruncateFunction(t *testing.T) {
|
||||||
|
@ -50,10 +50,10 @@ func TestParseTruncateFunction(t *testing.T) {
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
tm, err := Parse(testCase.template)
|
tm, err := Parse(testCase.template)
|
||||||
assert.NilError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
assert.NilError(t, tm.Execute(&b, source))
|
assert.NoError(t, tm.Execute(&b, source))
|
||||||
assert.Equal(t, b.String(), testCase.expected)
|
assert.Equal(t, testCase.expected, b.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,132 +0,0 @@
|
||||||
// Package assert contains functions for making assertions in unit tests
|
|
||||||
package assert
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
|
||||||
)
|
|
||||||
|
|
||||||
// TestingT is an interface which defines the methods of testing.T that are
|
|
||||||
// required by this package
|
|
||||||
type TestingT interface {
|
|
||||||
Fatalf(string, ...interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equal compare the actual value to the expected value and fails the test if
|
|
||||||
// they are not equal.
|
|
||||||
func Equal(t TestingT, actual, expected interface{}, extra ...string) {
|
|
||||||
if expected != actual {
|
|
||||||
fatalWithExtra(t, extra, "Expected '%v' (%T) got '%v' (%T)", expected, expected, actual, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EqualNormalizedString compare the actual value to the expected value after applying the specified
|
|
||||||
// transform function. It fails the test if these two transformed string are not equal.
|
|
||||||
// For example `EqualNormalizedString(t, RemoveSpace, "foo\n", "foo")` wouldn't fail the test as
|
|
||||||
// spaces (and thus '\n') are removed before comparing the string.
|
|
||||||
func EqualNormalizedString(t TestingT, transformFun func(rune) rune, actual, expected string) {
|
|
||||||
if strings.Map(transformFun, actual) != strings.Map(transformFun, expected) {
|
|
||||||
fatal(t, "Expected '%v' got '%v'", expected, expected, actual, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveSpace returns -1 if the specified runes is considered as a space (unicode)
|
|
||||||
// and the rune itself otherwise.
|
|
||||||
func RemoveSpace(r rune) rune {
|
|
||||||
if unicode.IsSpace(r) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
//EqualStringSlice compares two slices and fails the test if they do not contain
|
|
||||||
// the same items.
|
|
||||||
func EqualStringSlice(t TestingT, actual, expected []string) {
|
|
||||||
if len(actual) != len(expected) {
|
|
||||||
fatal(t, "Expected (length %d): %q\nActual (length %d): %q",
|
|
||||||
len(expected), expected, len(actual), actual)
|
|
||||||
}
|
|
||||||
for i, item := range actual {
|
|
||||||
if item != expected[i] {
|
|
||||||
fatal(t, "Slices differ at element %d, expected %q got %q",
|
|
||||||
i, expected[i], item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NilError asserts that the error is nil, otherwise it fails the test.
|
|
||||||
func NilError(t TestingT, err error) {
|
|
||||||
if err != nil {
|
|
||||||
fatal(t, "Expected no error, got: %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepEqual compare the actual value to the expected value and fails the test if
|
|
||||||
// they are not "deeply equal".
|
|
||||||
func DeepEqual(t TestingT, actual, expected interface{}) {
|
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
|
||||||
fatal(t, "Expected (%T):\n%v\n\ngot (%T):\n%s\n",
|
|
||||||
expected, spew.Sdump(expected), actual, spew.Sdump(actual))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error asserts that error is not nil, and contains the expected text,
|
|
||||||
// otherwise it fails the test.
|
|
||||||
func Error(t TestingT, err error, contains string) {
|
|
||||||
if err == nil {
|
|
||||||
fatal(t, "Expected an error, but error was nil")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.Contains(err.Error(), contains) {
|
|
||||||
fatal(t, "Expected error to contain '%s', got '%s'", contains, err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Contains asserts that the string contains a substring, otherwise it fails the
|
|
||||||
// test.
|
|
||||||
func Contains(t TestingT, actual, contains string) {
|
|
||||||
if !strings.Contains(actual, contains) {
|
|
||||||
fatal(t, "Expected '%s' to contain '%s'", actual, contains)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotNil fails the test if the object is nil
|
|
||||||
func NotNil(t TestingT, obj interface{}) {
|
|
||||||
if obj == nil {
|
|
||||||
fatal(t, "Expected non-nil value.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nil fails the test if the object is not nil
|
|
||||||
func Nil(t TestingT, obj interface{}) {
|
|
||||||
if obj != nil {
|
|
||||||
fatal(t, "Expected nil value, got (%T) %s", obj, obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fatal(t TestingT, format string, args ...interface{}) {
|
|
||||||
t.Fatalf(errorSource()+format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fatalWithExtra(t TestingT, extra []string, format string, args ...interface{}) {
|
|
||||||
msg := fmt.Sprintf(errorSource()+format, args...)
|
|
||||||
if len(extra) > 0 {
|
|
||||||
msg += ": " + strings.Join(extra, ", ")
|
|
||||||
}
|
|
||||||
t.Fatalf(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// See testing.decorate()
|
|
||||||
func errorSource() string {
|
|
||||||
_, filename, line, ok := runtime.Caller(3)
|
|
||||||
if !ok {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("%s:%d: ", filepath.Base(filename), line)
|
|
||||||
}
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunCommand(t *testing.T) {
|
func TestRunCommand(t *testing.T) {
|
||||||
|
@ -74,7 +74,7 @@ func TestRunCommandWithTimeoutKilled(t *testing.T) {
|
||||||
result.Assert(t, Expected{Timeout: true})
|
result.Assert(t, Expected{Timeout: true})
|
||||||
|
|
||||||
ones := strings.Split(result.Stdout(), "\n")
|
ones := strings.Split(result.Stdout(), "\n")
|
||||||
assert.Equal(t, len(ones), 4)
|
assert.Len(t, ones, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunCommandWithErrors(t *testing.T) {
|
func TestRunCommandWithErrors(t *testing.T) {
|
||||||
|
|
33
pkg/testutil/helpers.go
Normal file
33
pkg/testutil/helpers.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package testutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ErrorContains checks that the error is not nil, and contains the expected
|
||||||
|
// substring.
|
||||||
|
func ErrorContains(t require.TestingT, err error, expectedError string) {
|
||||||
|
require.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), expectedError)
|
||||||
|
}
|
||||||
|
|
||||||
|
// EqualNormalizedString compare the actual value to the expected value after applying the specified
|
||||||
|
// transform function. It fails the test if these two transformed string are not equal.
|
||||||
|
// For example `EqualNormalizedString(t, RemoveSpace, "foo\n", "foo")` wouldn't fail the test as
|
||||||
|
// spaces (and thus '\n') are removed before comparing the string.
|
||||||
|
func EqualNormalizedString(t require.TestingT, transformFun func(rune) rune, actual, expected string) {
|
||||||
|
require.Equal(t, strings.Map(transformFun, expected), strings.Map(transformFun, actual))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSpace returns -1 if the specified runes is considered as a space (unicode)
|
||||||
|
// and the rune itself otherwise.
|
||||||
|
func RemoveSpace(r rune) rune {
|
||||||
|
if unicode.IsSpace(r) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
package tempfile
|
package tempfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/docker/docker/pkg/testutil/assert"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TempFile is a temporary file that can be used with unit tests. TempFile
|
// TempFile is a temporary file that can be used with unit tests. TempFile
|
||||||
|
@ -14,12 +15,12 @@ type TempFile struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTempFile returns a new temp file with contents
|
// NewTempFile returns a new temp file with contents
|
||||||
func NewTempFile(t assert.TestingT, prefix string, content string) *TempFile {
|
func NewTempFile(t require.TestingT, prefix string, content string) *TempFile {
|
||||||
file, err := ioutil.TempFile("", prefix+"-")
|
file, err := ioutil.TempFile("", prefix+"-")
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = file.Write([]byte(content))
|
_, err = file.Write([]byte(content))
|
||||||
assert.NilError(t, err)
|
require.NoError(t, err)
|
||||||
file.Close()
|
file.Close()
|
||||||
return &TempFile{File: file}
|
return &TempFile{File: file}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ github.com/Microsoft/hcsshim v0.5.13
|
||||||
# TODO: get rid of this fork once PR https://github.com/Microsoft/go-winio/pull/43 is merged
|
# TODO: get rid of this fork once PR https://github.com/Microsoft/go-winio/pull/43 is merged
|
||||||
github.com/Microsoft/go-winio 7c7d6b461cb10872c1138a0d7f3acf9a41b5c353 https://github.com/dgageot/go-winio.git
|
github.com/Microsoft/go-winio 7c7d6b461cb10872c1138a0d7f3acf9a41b5c353 https://github.com/dgageot/go-winio.git
|
||||||
github.com/Sirupsen/logrus v0.11.0
|
github.com/Sirupsen/logrus v0.11.0
|
||||||
github.com/davecgh/go-spew 6d212800a42e8ab5c146b8ace3490ee17e5225f9
|
github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76
|
||||||
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
||||||
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
|
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
|
||||||
github.com/gorilla/context v1.1
|
github.com/gorilla/context v1.1
|
||||||
|
@ -19,6 +19,7 @@ golang.org/x/sys 8f0908ab3b2457e2e15403d3697c9ef5cb4b57a9
|
||||||
github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
|
github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1
|
||||||
github.com/docker/go-connections e15c02316c12de00874640cd76311849de2aeed5
|
github.com/docker/go-connections e15c02316c12de00874640cd76311849de2aeed5
|
||||||
golang.org/x/text f72d8390a633d5dfb0cc84043294db9f6c935756
|
golang.org/x/text f72d8390a633d5dfb0cc84043294db9f6c935756
|
||||||
|
github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987
|
||||||
|
|
||||||
github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
|
github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5
|
||||||
github.com/imdario/mergo 0.2.1
|
github.com/imdario/mergo 0.2.1
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/LICENSE
generated
vendored
2
vendor/github.com/davecgh/go-spew/LICENSE
generated
vendored
|
@ -1,6 +1,6 @@
|
||||||
ISC License
|
ISC License
|
||||||
|
|
||||||
Copyright (c) 2012-2013 Dave Collins <dave@davec.name>
|
Copyright (c) 2012-2016 Dave Collins <dave@davec.name>
|
||||||
|
|
||||||
Permission to use, copy, modify, and distribute this software for any
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
21
vendor/github.com/davecgh/go-spew/README.md
generated
vendored
21
vendor/github.com/davecgh/go-spew/README.md
generated
vendored
|
@ -1,11 +1,13 @@
|
||||||
go-spew
|
go-spew
|
||||||
=======
|
=======
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/davecgh/go-spew.png?branch=master)]
|
[![Build Status](https://img.shields.io/travis/davecgh/go-spew.svg)]
|
||||||
(https://travis-ci.org/davecgh/go-spew) [![Coverage Status]
|
(https://travis-ci.org/davecgh/go-spew) [![ISC License]
|
||||||
(https://coveralls.io/repos/davecgh/go-spew/badge.png?branch=master)]
|
(http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) [![Coverage Status]
|
||||||
|
(https://img.shields.io/coveralls/davecgh/go-spew.svg)]
|
||||||
(https://coveralls.io/r/davecgh/go-spew?branch=master)
|
(https://coveralls.io/r/davecgh/go-spew?branch=master)
|
||||||
|
|
||||||
|
|
||||||
Go-spew implements a deep pretty printer for Go data structures to aid in
|
Go-spew implements a deep pretty printer for Go data structures to aid in
|
||||||
debugging. A comprehensive suite of tests with 100% test coverage is provided
|
debugging. A comprehensive suite of tests with 100% test coverage is provided
|
||||||
to ensure proper functionality. See `test_coverage.txt` for the gocov coverage
|
to ensure proper functionality. See `test_coverage.txt` for the gocov coverage
|
||||||
|
@ -19,7 +21,7 @@ post about it
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
[![GoDoc](https://godoc.org/github.com/davecgh/go-spew/spew?status.png)]
|
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)]
|
||||||
(http://godoc.org/github.com/davecgh/go-spew/spew)
|
(http://godoc.org/github.com/davecgh/go-spew/spew)
|
||||||
|
|
||||||
Full `go doc` style documentation for the project can be viewed online without
|
Full `go doc` style documentation for the project can be viewed online without
|
||||||
|
@ -160,6 +162,15 @@ options. See the ConfigState documentation for more details.
|
||||||
App Engine or with the "safe" build tag specified.
|
App Engine or with the "safe" build tag specified.
|
||||||
Pointer method invocation is enabled by default.
|
Pointer method invocation is enabled by default.
|
||||||
|
|
||||||
|
* DisablePointerAddresses
|
||||||
|
DisablePointerAddresses specifies whether to disable the printing of
|
||||||
|
pointer addresses. This is useful when diffing data structures in tests.
|
||||||
|
|
||||||
|
* DisableCapacities
|
||||||
|
DisableCapacities specifies whether to disable the printing of capacities
|
||||||
|
for arrays, slices, maps and channels. This is useful when diffing data
|
||||||
|
structures in tests.
|
||||||
|
|
||||||
* ContinueOnMethod
|
* ContinueOnMethod
|
||||||
Enables recursion into types after invoking error and Stringer interface
|
Enables recursion into types after invoking error and Stringer interface
|
||||||
methods. Recursion after method invocation is disabled by default.
|
methods. Recursion after method invocation is disabled by default.
|
||||||
|
@ -191,4 +202,4 @@ using the unsafe package.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Go-spew is licensed under the liberal ISC License.
|
Go-spew is licensed under the [copyfree](http://copyfree.org) ISC License.
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/spew/bypass.go
generated
vendored
2
vendor/github.com/davecgh/go-spew/spew/bypass.go
generated
vendored
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2015 Dave Collins <dave@davec.name>
|
// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
|
||||||
//
|
//
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
// Permission to use, copy, modify, and distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
generated
vendored
2
vendor/github.com/davecgh/go-spew/spew/bypasssafe.go
generated
vendored
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (c) 2015 Dave Collins <dave@davec.name>
|
// Copyright (c) 2015-2016 Dave Collins <dave@davec.name>
|
||||||
//
|
//
|
||||||
// Permission to use, copy, modify, and distribute this software for any
|
// Permission to use, copy, modify, and distribute this software for any
|
||||||
// purpose with or without fee is hereby granted, provided that the above
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/spew/common.go
generated
vendored
2
vendor/github.com/davecgh/go-spew/spew/common.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
11
vendor/github.com/davecgh/go-spew/spew/config.go
generated
vendored
11
vendor/github.com/davecgh/go-spew/spew/config.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -67,6 +67,15 @@ type ConfigState struct {
|
||||||
// Google App Engine or with the "safe" build tag specified.
|
// Google App Engine or with the "safe" build tag specified.
|
||||||
DisablePointerMethods bool
|
DisablePointerMethods bool
|
||||||
|
|
||||||
|
// DisablePointerAddresses specifies whether to disable the printing of
|
||||||
|
// pointer addresses. This is useful when diffing data structures in tests.
|
||||||
|
DisablePointerAddresses bool
|
||||||
|
|
||||||
|
// DisableCapacities specifies whether to disable the printing of capacities
|
||||||
|
// for arrays, slices, maps and channels. This is useful when diffing
|
||||||
|
// data structures in tests.
|
||||||
|
DisableCapacities bool
|
||||||
|
|
||||||
// ContinueOnMethod specifies whether or not recursion should continue once
|
// ContinueOnMethod specifies whether or not recursion should continue once
|
||||||
// a custom error or Stringer interface is invoked. The default, false,
|
// a custom error or Stringer interface is invoked. The default, false,
|
||||||
// means it will print the results of invoking the custom error or Stringer
|
// means it will print the results of invoking the custom error or Stringer
|
||||||
|
|
11
vendor/github.com/davecgh/go-spew/spew/doc.go
generated
vendored
11
vendor/github.com/davecgh/go-spew/spew/doc.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -91,6 +91,15 @@ The following configuration options are available:
|
||||||
which only accept pointer receivers from non-pointer variables.
|
which only accept pointer receivers from non-pointer variables.
|
||||||
Pointer method invocation is enabled by default.
|
Pointer method invocation is enabled by default.
|
||||||
|
|
||||||
|
* DisablePointerAddresses
|
||||||
|
DisablePointerAddresses specifies whether to disable the printing of
|
||||||
|
pointer addresses. This is useful when diffing data structures in tests.
|
||||||
|
|
||||||
|
* DisableCapacities
|
||||||
|
DisableCapacities specifies whether to disable the printing of
|
||||||
|
capacities for arrays, slices, maps and channels. This is useful when
|
||||||
|
diffing data structures in tests.
|
||||||
|
|
||||||
* ContinueOnMethod
|
* ContinueOnMethod
|
||||||
Enables recursion into types after invoking error and Stringer interface
|
Enables recursion into types after invoking error and Stringer interface
|
||||||
methods. Recursion after method invocation is disabled by default.
|
methods. Recursion after method invocation is disabled by default.
|
||||||
|
|
8
vendor/github.com/davecgh/go-spew/spew/dump.go
generated
vendored
8
vendor/github.com/davecgh/go-spew/spew/dump.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -129,7 +129,7 @@ func (d *dumpState) dumpPtr(v reflect.Value) {
|
||||||
d.w.Write(closeParenBytes)
|
d.w.Write(closeParenBytes)
|
||||||
|
|
||||||
// Display pointer information.
|
// Display pointer information.
|
||||||
if len(pointerChain) > 0 {
|
if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 {
|
||||||
d.w.Write(openParenBytes)
|
d.w.Write(openParenBytes)
|
||||||
for i, addr := range pointerChain {
|
for i, addr := range pointerChain {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -282,13 +282,13 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
case reflect.Map, reflect.String:
|
case reflect.Map, reflect.String:
|
||||||
valueLen = v.Len()
|
valueLen = v.Len()
|
||||||
}
|
}
|
||||||
if valueLen != 0 || valueCap != 0 {
|
if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 {
|
||||||
d.w.Write(openParenBytes)
|
d.w.Write(openParenBytes)
|
||||||
if valueLen != 0 {
|
if valueLen != 0 {
|
||||||
d.w.Write(lenEqualsBytes)
|
d.w.Write(lenEqualsBytes)
|
||||||
printInt(d.w, int64(valueLen), 10)
|
printInt(d.w, int64(valueLen), 10)
|
||||||
}
|
}
|
||||||
if valueCap != 0 {
|
if !d.cs.DisableCapacities && valueCap != 0 {
|
||||||
if valueLen != 0 {
|
if valueLen != 0 {
|
||||||
d.w.Write(spaceBytes)
|
d.w.Write(spaceBytes)
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/spew/format.go
generated
vendored
2
vendor/github.com/davecgh/go-spew/spew/format.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
2
vendor/github.com/davecgh/go-spew/spew/spew.go
generated
vendored
2
vendor/github.com/davecgh/go-spew/spew/spew.go
generated
vendored
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013 Dave Collins <dave@davec.name>
|
* Copyright (c) 2013-2016 Dave Collins <dave@davec.name>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
332
vendor/github.com/stretchr/testify/README.md
generated
vendored
Normal file
332
vendor/github.com/stretchr/testify/README.md
generated
vendored
Normal file
|
@ -0,0 +1,332 @@
|
||||||
|
Testify - Thou Shalt Write Tests
|
||||||
|
================================
|
||||||
|
|
||||||
|
[![Build Status](https://travis-ci.org/stretchr/testify.svg)](https://travis-ci.org/stretchr/testify) [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/testify)](https://goreportcard.com/report/github.com/stretchr/testify) [![GoDoc](https://godoc.org/github.com/stretchr/testify?status.svg)](https://godoc.org/github.com/stretchr/testify)
|
||||||
|
|
||||||
|
Go code (golang) set of packages that provide many tools for testifying that your code will behave as you intend.
|
||||||
|
|
||||||
|
Features include:
|
||||||
|
|
||||||
|
* [Easy assertions](#assert-package)
|
||||||
|
* [Mocking](#mock-package)
|
||||||
|
* [HTTP response trapping](#http-package)
|
||||||
|
* [Testing suite interfaces and functions](#suite-package)
|
||||||
|
|
||||||
|
Get started:
|
||||||
|
|
||||||
|
* Install testify with [one line of code](#installation), or [update it with another](#staying-up-to-date)
|
||||||
|
* For an introduction to writing test code in Go, see http://golang.org/doc/code.html#Testing
|
||||||
|
* Check out the API Documentation http://godoc.org/github.com/stretchr/testify
|
||||||
|
* To make your testing life easier, check out our other project, [gorc](http://github.com/stretchr/gorc)
|
||||||
|
* A little about [Test-Driven Development (TDD)](http://en.wikipedia.org/wiki/Test-driven_development)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[`assert`](http://godoc.org/github.com/stretchr/testify/assert "API documentation") package
|
||||||
|
-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The `assert` package provides some helpful methods that allow you to write better test code in Go.
|
||||||
|
|
||||||
|
* Prints friendly, easy to read failure descriptions
|
||||||
|
* Allows for very readable code
|
||||||
|
* Optionally annotate each assertion with a message
|
||||||
|
|
||||||
|
See it in action:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package yours
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
|
||||||
|
// assert equality
|
||||||
|
assert.Equal(t, 123, 123, "they should be equal")
|
||||||
|
|
||||||
|
// assert inequality
|
||||||
|
assert.NotEqual(t, 123, 456, "they should not be equal")
|
||||||
|
|
||||||
|
// assert for nil (good for errors)
|
||||||
|
assert.Nil(t, object)
|
||||||
|
|
||||||
|
// assert for not nil (good when you expect something)
|
||||||
|
if assert.NotNil(t, object) {
|
||||||
|
|
||||||
|
// now we know that object isn't nil, we are safe to make
|
||||||
|
// further assertions without causing any errors
|
||||||
|
assert.Equal(t, "Something", object.Value)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* Every assert func takes the `testing.T` object as the first argument. This is how it writes the errors out through the normal `go test` capabilities.
|
||||||
|
* Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions.
|
||||||
|
|
||||||
|
if you assert many times, use the below:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package yours
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
// assert equality
|
||||||
|
assert.Equal(123, 123, "they should be equal")
|
||||||
|
|
||||||
|
// assert inequality
|
||||||
|
assert.NotEqual(123, 456, "they should not be equal")
|
||||||
|
|
||||||
|
// assert for nil (good for errors)
|
||||||
|
assert.Nil(object)
|
||||||
|
|
||||||
|
// assert for not nil (good when you expect something)
|
||||||
|
if assert.NotNil(object) {
|
||||||
|
|
||||||
|
// now we know that object isn't nil, we are safe to make
|
||||||
|
// further assertions without causing any errors
|
||||||
|
assert.Equal("Something", object.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
[`require`](http://godoc.org/github.com/stretchr/testify/require "API documentation") package
|
||||||
|
---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The `require` package provides same global functions as the `assert` package, but instead of returning a boolean result they terminate current test.
|
||||||
|
|
||||||
|
See [t.FailNow](http://golang.org/pkg/testing/#T.FailNow) for details.
|
||||||
|
|
||||||
|
|
||||||
|
[`http`](http://godoc.org/github.com/stretchr/testify/http "API documentation") package
|
||||||
|
---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The `http` package contains test objects useful for testing code that relies on the `net/http` package. Check out the [(deprecated) API documentation for the `http` package](http://godoc.org/github.com/stretchr/testify/http).
|
||||||
|
|
||||||
|
We recommend you use [httptest](http://golang.org/pkg/net/http/httptest) instead.
|
||||||
|
|
||||||
|
[`mock`](http://godoc.org/github.com/stretchr/testify/mock "API documentation") package
|
||||||
|
----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The `mock` package provides a mechanism for easily writing mock objects that can be used in place of real objects when writing test code.
|
||||||
|
|
||||||
|
An example test function that tests a piece of code that relies on an external object `testObj`, can setup expectations (testify) and assert that they indeed happened:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package yours
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test objects
|
||||||
|
*/
|
||||||
|
|
||||||
|
// MyMockedObject is a mocked object that implements an interface
|
||||||
|
// that describes an object that the code I am testing relies on.
|
||||||
|
type MyMockedObject struct{
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// DoSomething is a method on MyMockedObject that implements some interface
|
||||||
|
// and just records the activity, and returns what the Mock object tells it to.
|
||||||
|
//
|
||||||
|
// In the real object, this method would do something useful, but since this
|
||||||
|
// is a mocked object - we're just going to stub it out.
|
||||||
|
//
|
||||||
|
// NOTE: This method is not being tested here, code that uses this object is.
|
||||||
|
func (m *MyMockedObject) DoSomething(number int) (bool, error) {
|
||||||
|
|
||||||
|
args := m.Called(number)
|
||||||
|
return args.Bool(0), args.Error(1)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Actual test functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TestSomething is an example of how to use our test object to
|
||||||
|
// make assertions about some target code we are testing.
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
|
||||||
|
// create an instance of our test object
|
||||||
|
testObj := new(MyMockedObject)
|
||||||
|
|
||||||
|
// setup expectations
|
||||||
|
testObj.On("DoSomething", 123).Return(true, nil)
|
||||||
|
|
||||||
|
// call the code we are testing
|
||||||
|
targetFuncThatDoesSomethingWithObj(testObj)
|
||||||
|
|
||||||
|
// assert that the expectations were met
|
||||||
|
testObj.AssertExpectations(t)
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock).
|
||||||
|
|
||||||
|
You can use the [mockery tool](http://github.com/vektra/mockery) to autogenerate the mock code against an interface as well, making using mocks much quicker.
|
||||||
|
|
||||||
|
[`suite`](http://godoc.org/github.com/stretchr/testify/suite "API documentation") package
|
||||||
|
-----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
The `suite` package provides functionality that you might be used to from more common object oriented languages. With it, you can build a testing suite as a struct, build setup/teardown methods and testing methods on your struct, and run them with 'go test' as per normal.
|
||||||
|
|
||||||
|
An example suite is shown below:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Basic imports
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Define the suite, and absorb the built-in basic suite
|
||||||
|
// functionality from testify - including a T() method which
|
||||||
|
// returns the current testing context
|
||||||
|
type ExampleTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
VariableThatShouldStartAtFive int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure that VariableThatShouldStartAtFive is set to five
|
||||||
|
// before each test
|
||||||
|
func (suite *ExampleTestSuite) SetupTest() {
|
||||||
|
suite.VariableThatShouldStartAtFive = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
// All methods that begin with "Test" are run as tests within a
|
||||||
|
// suite.
|
||||||
|
func (suite *ExampleTestSuite) TestExample() {
|
||||||
|
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
|
||||||
|
}
|
||||||
|
|
||||||
|
// In order for 'go test' to run this suite, we need to create
|
||||||
|
// a normal test function and pass our suite to suite.Run
|
||||||
|
func TestExampleTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(ExampleTestSuite))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go)
|
||||||
|
|
||||||
|
For more information on writing suites, check out the [API documentation for the `suite` package](http://godoc.org/github.com/stretchr/testify/suite).
|
||||||
|
|
||||||
|
`Suite` object has assertion methods:
|
||||||
|
|
||||||
|
```go
|
||||||
|
// Basic imports
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Define the suite, and absorb the built-in basic suite
|
||||||
|
// functionality from testify - including assertion methods.
|
||||||
|
type ExampleTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
VariableThatShouldStartAtFive int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure that VariableThatShouldStartAtFive is set to five
|
||||||
|
// before each test
|
||||||
|
func (suite *ExampleTestSuite) SetupTest() {
|
||||||
|
suite.VariableThatShouldStartAtFive = 5
|
||||||
|
}
|
||||||
|
|
||||||
|
// All methods that begin with "Test" are run as tests within a
|
||||||
|
// suite.
|
||||||
|
func (suite *ExampleTestSuite) TestExample() {
|
||||||
|
suite.Equal(suite.VariableThatShouldStartAtFive, 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
// In order for 'go test' to run this suite, we need to create
|
||||||
|
// a normal test function and pass our suite to suite.Run
|
||||||
|
func TestExampleTestSuite(t *testing.T) {
|
||||||
|
suite.Run(t, new(ExampleTestSuite))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
To install Testify, use `go get`:
|
||||||
|
|
||||||
|
* Latest version: go get github.com/stretchr/testify
|
||||||
|
* Specific version: go get gopkg.in/stretchr/testify.v1
|
||||||
|
|
||||||
|
This will then make the following packages available to you:
|
||||||
|
|
||||||
|
github.com/stretchr/testify/assert
|
||||||
|
github.com/stretchr/testify/mock
|
||||||
|
github.com/stretchr/testify/http
|
||||||
|
|
||||||
|
Import the `testify/assert` package into your code using this template:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package yours
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSomething(t *testing.T) {
|
||||||
|
|
||||||
|
assert.True(t, true, "True is true!")
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
Staying up to date
|
||||||
|
==================
|
||||||
|
|
||||||
|
To update Testify to the latest version, use `go get -u github.com/stretchr/testify`.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
Version History
|
||||||
|
===============
|
||||||
|
|
||||||
|
* 1.0 - New package versioning strategy adopted.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
Contributing
|
||||||
|
============
|
||||||
|
|
||||||
|
Please feel free to submit issues, fork the repository and send pull requests!
|
||||||
|
|
||||||
|
When submitting an issue, we ask that you please include a complete test function that demonstrates the issue. Extra credit for those using Testify to write the test code that demonstrates it.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
Licence
|
||||||
|
=======
|
||||||
|
Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell
|
||||||
|
|
||||||
|
Please consider promoting this project if you find it useful.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
173
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
173
vendor/github.com/stretchr/testify/assert/assertion_forward.go
generated
vendored
|
@ -1,386 +1,351 @@
|
||||||
/*
|
/*
|
||||||
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
|
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
|
||||||
* THIS FILE MUST NOT BE EDITED BY HAND
|
* THIS FILE MUST NOT BE EDITED BY HAND
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package assert
|
package assert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
||||||
http "net/http"
|
http "net/http"
|
||||||
url "net/url"
|
url "net/url"
|
||||||
time "time"
|
time "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Condition uses a Comparison to assert a complex condition.
|
// Condition uses a Comparison to assert a complex condition.
|
||||||
func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
|
||||||
return Condition(a.t, comp, msgAndArgs...)
|
return Condition(a.t, comp, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Contains asserts that the specified string, list(array, slice...) or map contains the
|
// Contains asserts that the specified string, list(array, slice...) or map contains the
|
||||||
// specified substring or element.
|
// specified substring or element.
|
||||||
//
|
//
|
||||||
// a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'")
|
// a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'")
|
||||||
// a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
|
// a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
|
||||||
// a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
|
// a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Contains(a.t, s, contains, msgAndArgs...)
|
return Contains(a.t, s, contains, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
||||||
// a slice or a channel with len == 0.
|
// a slice or a channel with len == 0.
|
||||||
//
|
//
|
||||||
// a.Empty(obj)
|
// a.Empty(obj)
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Empty(a.t, object, msgAndArgs...)
|
return Empty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Equal asserts that two objects are equal.
|
// Equal asserts that two objects are equal.
|
||||||
//
|
//
|
||||||
// a.Equal(123, 123, "123 and 123 should be equal")
|
// a.Equal(123, 123, "123 and 123 should be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Equal(a.t, expected, actual, msgAndArgs...)
|
return Equal(a.t, expected, actual, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
||||||
// and that it is equal to the provided error.
|
// and that it is equal to the provided error.
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if assert.Error(t, err, "An error was expected") {
|
// a.EqualError(err, expectedErrorString, "An error was expected")
|
||||||
// assert.Equal(t, err, expectedError)
|
//
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
|
||||||
return EqualError(a.t, theError, errString, msgAndArgs...)
|
return EqualError(a.t, theError, errString, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// EqualValues asserts that two objects are equal or convertable to the same types
|
// EqualValues asserts that two objects are equal or convertable to the same types
|
||||||
// and equal.
|
// and equal.
|
||||||
//
|
//
|
||||||
// a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal")
|
// a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return EqualValues(a.t, expected, actual, msgAndArgs...)
|
return EqualValues(a.t, expected, actual, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.Error(err, "An error was expected") {
|
// if a.Error(err, "An error was expected") {
|
||||||
// assert.Equal(t, err, expectedError)
|
// assert.Equal(t, err, expectedError)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
|
||||||
return Error(a.t, err, msgAndArgs...)
|
return Error(a.t, err, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Exactly asserts that two objects are equal is value and type.
|
// Exactly asserts that two objects are equal is value and type.
|
||||||
//
|
//
|
||||||
// a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal")
|
// a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Exactly(a.t, expected, actual, msgAndArgs...)
|
return Exactly(a.t, expected, actual, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Fail reports a failure through
|
// Fail reports a failure through
|
||||||
func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {
|
||||||
return Fail(a.t, failureMessage, msgAndArgs...)
|
return Fail(a.t, failureMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// FailNow fails test
|
// FailNow fails test
|
||||||
func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {
|
||||||
return FailNow(a.t, failureMessage, msgAndArgs...)
|
return FailNow(a.t, failureMessage, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// False asserts that the specified value is false.
|
// False asserts that the specified value is false.
|
||||||
//
|
//
|
||||||
// a.False(myBool, "myBool should be false")
|
// a.False(myBool, "myBool should be false")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {
|
||||||
return False(a.t, value, msgAndArgs...)
|
return False(a.t, value, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPBodyContains asserts that a specified handler returns a
|
// HTTPBodyContains asserts that a specified handler returns a
|
||||||
// body that contains a string.
|
// body that contains a string.
|
||||||
//
|
//
|
||||||
// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
|
func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
|
||||||
return HTTPBodyContains(a.t, handler, method, url, values, str)
|
return HTTPBodyContains(a.t, handler, method, url, values, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPBodyNotContains asserts that a specified handler returns a
|
// HTTPBodyNotContains asserts that a specified handler returns a
|
||||||
// body that does not contain a string.
|
// body that does not contain a string.
|
||||||
//
|
//
|
||||||
// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
|
func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
|
||||||
return HTTPBodyNotContains(a.t, handler, method, url, values, str)
|
return HTTPBodyNotContains(a.t, handler, method, url, values, str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPError asserts that a specified handler returns an error status code.
|
// HTTPError asserts that a specified handler returns an error status code.
|
||||||
//
|
//
|
||||||
// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
||||||
return HTTPError(a.t, handler, method, url, values)
|
return HTTPError(a.t, handler, method, url, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPRedirect asserts that a specified handler returns a redirect status code.
|
// HTTPRedirect asserts that a specified handler returns a redirect status code.
|
||||||
//
|
//
|
||||||
// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
||||||
return HTTPRedirect(a.t, handler, method, url, values)
|
return HTTPRedirect(a.t, handler, method, url, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// HTTPSuccess asserts that a specified handler returns a success status code.
|
// HTTPSuccess asserts that a specified handler returns a success status code.
|
||||||
//
|
//
|
||||||
// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
|
// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) bool {
|
||||||
return HTTPSuccess(a.t, handler, method, url, values)
|
return HTTPSuccess(a.t, handler, method, url, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implements asserts that an object is implemented by the specified interface.
|
// Implements asserts that an object is implemented by the specified interface.
|
||||||
//
|
//
|
||||||
// a.Implements((*MyInterface)(nil), new(MyObject), "MyObject")
|
// a.Implements((*MyInterface)(nil), new(MyObject), "MyObject")
|
||||||
func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Implements(a.t, interfaceObject, object, msgAndArgs...)
|
return Implements(a.t, interfaceObject, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InDelta asserts that the two numerals are within delta of each other.
|
// InDelta asserts that the two numerals are within delta of each other.
|
||||||
//
|
//
|
||||||
// a.InDelta(math.Pi, (22 / 7.0), 0.01)
|
// a.InDelta(math.Pi, (22 / 7.0), 0.01)
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
|
||||||
return InDelta(a.t, expected, actual, delta, msgAndArgs...)
|
return InDelta(a.t, expected, actual, delta, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InDeltaSlice is the same as InDelta, except it compares two slices.
|
// InDeltaSlice is the same as InDelta, except it compares two slices.
|
||||||
func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
|
||||||
return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
|
return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// InEpsilon asserts that expected and actual have a relative error less than epsilon
|
// InEpsilon asserts that expected and actual have a relative error less than epsilon
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
|
||||||
return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
|
return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
|
||||||
// InEpsilonSlice is the same as InEpsilon, except it compares two slices.
|
func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
|
||||||
func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
|
return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
|
||||||
return InEpsilonSlice(a.t, expected, actual, delta, msgAndArgs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// IsType asserts that the specified objects are of the same type.
|
// IsType asserts that the specified objects are of the same type.
|
||||||
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return IsType(a.t, expectedType, object, msgAndArgs...)
|
return IsType(a.t, expectedType, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// JSONEq asserts that two JSON strings are equivalent.
|
// JSONEq asserts that two JSON strings are equivalent.
|
||||||
//
|
//
|
||||||
// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
|
// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {
|
||||||
return JSONEq(a.t, expected, actual, msgAndArgs...)
|
return JSONEq(a.t, expected, actual, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Len asserts that the specified object has specific length.
|
// Len asserts that the specified object has specific length.
|
||||||
// Len also fails if the object has a type that len() not accept.
|
// Len also fails if the object has a type that len() not accept.
|
||||||
//
|
//
|
||||||
// a.Len(mySlice, 3, "The size of slice is not 3")
|
// a.Len(mySlice, 3, "The size of slice is not 3")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {
|
||||||
return Len(a.t, object, length, msgAndArgs...)
|
return Len(a.t, object, length, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Nil asserts that the specified object is nil.
|
// Nil asserts that the specified object is nil.
|
||||||
//
|
//
|
||||||
// a.Nil(err, "err should be nothing")
|
// a.Nil(err, "err should be nothing")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Nil(a.t, object, msgAndArgs...)
|
return Nil(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NoError asserts that a function returned no error (i.e. `nil`).
|
// NoError asserts that a function returned no error (i.e. `nil`).
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if a.NoError(err) {
|
// if a.NoError(err) {
|
||||||
// assert.Equal(t, actualObj, expectedObj)
|
// assert.Equal(t, actualObj, expectedObj)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {
|
||||||
return NoError(a.t, err, msgAndArgs...)
|
return NoError(a.t, err, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
|
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
|
||||||
// specified substring or element.
|
// specified substring or element.
|
||||||
//
|
//
|
||||||
// a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
|
// a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
|
||||||
// a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
|
// a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
|
||||||
// a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
|
// a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotContains(a.t, s, contains, msgAndArgs...)
|
return NotContains(a.t, s, contains, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
||||||
// a slice or a channel with len == 0.
|
// a slice or a channel with len == 0.
|
||||||
//
|
//
|
||||||
// if a.NotEmpty(obj) {
|
// if a.NotEmpty(obj) {
|
||||||
// assert.Equal(t, "two", obj[1])
|
// assert.Equal(t, "two", obj[1])
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotEmpty(a.t, object, msgAndArgs...)
|
return NotEmpty(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotEqual asserts that the specified values are NOT equal.
|
// NotEqual asserts that the specified values are NOT equal.
|
||||||
//
|
//
|
||||||
// a.NotEqual(obj1, obj2, "two objects shouldn't be equal")
|
// a.NotEqual(obj1, obj2, "two objects shouldn't be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotEqual(a.t, expected, actual, msgAndArgs...)
|
return NotEqual(a.t, expected, actual, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotNil asserts that the specified object is not nil.
|
// NotNil asserts that the specified object is not nil.
|
||||||
//
|
//
|
||||||
// a.NotNil(err, "err should be something")
|
// a.NotNil(err, "err should be something")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotNil(a.t, object, msgAndArgs...)
|
return NotNil(a.t, object, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
|
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
|
||||||
//
|
//
|
||||||
// a.NotPanics(func(){
|
// a.NotPanics(func(){
|
||||||
// RemainCalm()
|
// RemainCalm()
|
||||||
// }, "Calling RemainCalm() should NOT panic")
|
// }, "Calling RemainCalm() should NOT panic")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
|
||||||
return NotPanics(a.t, f, msgAndArgs...)
|
return NotPanics(a.t, f, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotRegexp asserts that a specified regexp does not match a string.
|
// NotRegexp asserts that a specified regexp does not match a string.
|
||||||
//
|
//
|
||||||
// a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
|
// a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
|
||||||
// a.NotRegexp("^start", "it's not starting")
|
// a.NotRegexp("^start", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotRegexp(a.t, rx, str, msgAndArgs...)
|
return NotRegexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NotZero asserts that i is not the zero value for its type and returns the truth.
|
// NotZero asserts that i is not the zero value for its type and returns the truth.
|
||||||
func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return NotZero(a.t, i, msgAndArgs...)
|
return NotZero(a.t, i, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Panics asserts that the code inside the specified PanicTestFunc panics.
|
// Panics asserts that the code inside the specified PanicTestFunc panics.
|
||||||
//
|
//
|
||||||
// a.Panics(func(){
|
// a.Panics(func(){
|
||||||
// GoCrazy()
|
// GoCrazy()
|
||||||
// }, "Calling GoCrazy() should panic")
|
// }, "Calling GoCrazy() should panic")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
|
||||||
return Panics(a.t, f, msgAndArgs...)
|
return Panics(a.t, f, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Regexp asserts that a specified regexp matches a string.
|
// Regexp asserts that a specified regexp matches a string.
|
||||||
//
|
//
|
||||||
// a.Regexp(regexp.MustCompile("start"), "it's starting")
|
// a.Regexp(regexp.MustCompile("start"), "it's starting")
|
||||||
// a.Regexp("start...$", "it's not starting")
|
// a.Regexp("start...$", "it's not starting")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Regexp(a.t, rx, str, msgAndArgs...)
|
return Regexp(a.t, rx, str, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// True asserts that the specified value is true.
|
// True asserts that the specified value is true.
|
||||||
//
|
//
|
||||||
// a.True(myBool, "myBool should be true")
|
// a.True(myBool, "myBool should be true")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {
|
||||||
return True(a.t, value, msgAndArgs...)
|
return True(a.t, value, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// WithinDuration asserts that the two times are within duration delta of each other.
|
// WithinDuration asserts that the two times are within duration delta of each other.
|
||||||
//
|
//
|
||||||
// a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
|
// a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
|
||||||
return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
|
return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Zero asserts that i is the zero value for its type and returns the truth.
|
// Zero asserts that i is the zero value for its type and returns the truth.
|
||||||
func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {
|
func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {
|
||||||
return Zero(a.t, i, msgAndArgs...)
|
return Zero(a.t, i, msgAndArgs...)
|
||||||
|
|
183
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
183
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
|
@ -65,7 +65,7 @@ func ObjectsAreEqualValues(expected, actual interface{}) bool {
|
||||||
|
|
||||||
/* CallerInfo is necessary because the assert functions use the testing object
|
/* CallerInfo is necessary because the assert functions use the testing object
|
||||||
internally, causing it to print the file:line of the assert method, rather than where
|
internally, causing it to print the file:line of the assert method, rather than where
|
||||||
the problem actually occured in calling code.*/
|
the problem actually occurred in calling code.*/
|
||||||
|
|
||||||
// CallerInfo returns an array of strings containing the file and line number
|
// CallerInfo returns an array of strings containing the file and line number
|
||||||
// of each stack frame leading from the current test to the assert call that
|
// of each stack frame leading from the current test to the assert call that
|
||||||
|
@ -82,7 +82,9 @@ func CallerInfo() []string {
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
pc, file, line, ok = runtime.Caller(i)
|
pc, file, line, ok = runtime.Caller(i)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
// The breaks below failed to terminate the loop, and we ran off the
|
||||||
|
// end of the call stack.
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a huge edge case, but it will panic if this is the case, see #180
|
// This is a huge edge case, but it will panic if this is the case, see #180
|
||||||
|
@ -90,6 +92,21 @@ func CallerInfo() []string {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f := runtime.FuncForPC(pc)
|
||||||
|
if f == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
name = f.Name()
|
||||||
|
|
||||||
|
// testing.tRunner is the standard library function that calls
|
||||||
|
// tests. Subtests are called directly by tRunner, without going through
|
||||||
|
// the Test/Benchmark/Example function that contains the t.Run calls, so
|
||||||
|
// with subtests we should break when we hit tRunner, without adding it
|
||||||
|
// to the list of callers.
|
||||||
|
if name == "testing.tRunner" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
parts := strings.Split(file, "/")
|
parts := strings.Split(file, "/")
|
||||||
dir := parts[len(parts)-2]
|
dir := parts[len(parts)-2]
|
||||||
file = parts[len(parts)-1]
|
file = parts[len(parts)-1]
|
||||||
|
@ -97,11 +114,6 @@ func CallerInfo() []string {
|
||||||
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
|
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
|
||||||
}
|
}
|
||||||
|
|
||||||
f := runtime.FuncForPC(pc)
|
|
||||||
if f == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
name = f.Name()
|
|
||||||
// Drop the package
|
// Drop the package
|
||||||
segments := strings.Split(name, ".")
|
segments := strings.Split(name, ".")
|
||||||
name = segments[len(segments)-1]
|
name = segments[len(segments)-1]
|
||||||
|
@ -141,7 +153,7 @@ func getWhitespaceString() string {
|
||||||
parts := strings.Split(file, "/")
|
parts := strings.Split(file, "/")
|
||||||
file = parts[len(parts)-1]
|
file = parts[len(parts)-1]
|
||||||
|
|
||||||
return strings.Repeat(" ", len(fmt.Sprintf("%s:%d: ", file, line)))
|
return strings.Repeat(" ", len(fmt.Sprintf("%s:%d: ", file, line)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,22 +170,18 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indents all lines of the message by appending a number of tabs to each line, in an output format compatible with Go's
|
// Aligns the provided message so that all lines after the first line start at the same location as the first line.
|
||||||
// test printing (see inner comment for specifics)
|
// Assumes that the first line starts at the correct location (after carriage return, tab, label, spacer and tab).
|
||||||
func indentMessageLines(message string, tabs int) string {
|
// The longestLabelLen parameter specifies the length of the longest label in the output (required becaues this is the
|
||||||
|
// basis on which the alignment occurs).
|
||||||
|
func indentMessageLines(message string, longestLabelLen int) string {
|
||||||
outBuf := new(bytes.Buffer)
|
outBuf := new(bytes.Buffer)
|
||||||
|
|
||||||
for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ {
|
for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ {
|
||||||
|
// no need to align first line because it starts at the correct location (after the label)
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
outBuf.WriteRune('\n')
|
// append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab
|
||||||
}
|
outBuf.WriteString("\n\r\t" + strings.Repeat(" ", longestLabelLen +1) + "\t")
|
||||||
for ii := 0; ii < tabs; ii++ {
|
|
||||||
outBuf.WriteRune('\t')
|
|
||||||
// Bizarrely, all lines except the first need one fewer tabs prepended, so deliberately advance the counter
|
|
||||||
// by 1 prematurely.
|
|
||||||
if ii == 0 && i > 0 {
|
|
||||||
ii++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
outBuf.WriteString(scanner.Text())
|
outBuf.WriteString(scanner.Text())
|
||||||
}
|
}
|
||||||
|
@ -205,29 +213,49 @@ func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
|
||||||
|
|
||||||
// Fail reports a failure through
|
// Fail reports a failure through
|
||||||
func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
|
func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
|
||||||
|
content := []labeledContent{
|
||||||
message := messageFromMsgAndArgs(msgAndArgs...)
|
{"Error Trace", strings.Join(CallerInfo(), "\n\r\t\t\t")},
|
||||||
|
{"Error", failureMessage},
|
||||||
errorTrace := strings.Join(CallerInfo(), "\n\r\t\t\t")
|
|
||||||
if len(message) > 0 {
|
|
||||||
t.Errorf("\r%s\r\tError Trace:\t%s\n"+
|
|
||||||
"\r\tError:%s\n"+
|
|
||||||
"\r\tMessages:\t%s\n\r",
|
|
||||||
getWhitespaceString(),
|
|
||||||
errorTrace,
|
|
||||||
indentMessageLines(failureMessage, 2),
|
|
||||||
message)
|
|
||||||
} else {
|
|
||||||
t.Errorf("\r%s\r\tError Trace:\t%s\n"+
|
|
||||||
"\r\tError:%s\n\r",
|
|
||||||
getWhitespaceString(),
|
|
||||||
errorTrace,
|
|
||||||
indentMessageLines(failureMessage, 2))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message := messageFromMsgAndArgs(msgAndArgs...)
|
||||||
|
if len(message) > 0 {
|
||||||
|
content = append(content, labeledContent{"Messages", message})
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Errorf("\r" + getWhitespaceString() + labeledOutput(content...))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type labeledContent struct {
|
||||||
|
label string
|
||||||
|
content string
|
||||||
|
}
|
||||||
|
|
||||||
|
// labeledOutput returns a string consisting of the provided labeledContent. Each labeled output is appended in the following manner:
|
||||||
|
//
|
||||||
|
// \r\t{{label}}:{{align_spaces}}\t{{content}}\n
|
||||||
|
//
|
||||||
|
// The initial carriage return is required to undo/erase any padding added by testing.T.Errorf. The "\t{{label}}:" is for the label.
|
||||||
|
// If a label is shorter than the longest label provided, padding spaces are added to make all the labels match in length. Once this
|
||||||
|
// alignment is achieved, "\t{{content}}\n" is added for the output.
|
||||||
|
//
|
||||||
|
// If the content of the labeledOutput contains line breaks, the subsequent lines are aligned so that they start at the same location as the first line.
|
||||||
|
func labeledOutput(content ...labeledContent) string {
|
||||||
|
longestLabel := 0
|
||||||
|
for _, v := range content {
|
||||||
|
if len(v.label) > longestLabel {
|
||||||
|
longestLabel = len(v.label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var output string
|
||||||
|
for _, v := range content {
|
||||||
|
output += "\r\t" + v.label + ":" + strings.Repeat(" ", longestLabel-len(v.label)) + "\t" + indentMessageLines(v.content, longestLabel) + "\n"
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
// Implements asserts that an object is implemented by the specified interface.
|
// Implements asserts that an object is implemented by the specified interface.
|
||||||
//
|
//
|
||||||
// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
|
// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
|
||||||
|
@ -258,18 +286,39 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs
|
||||||
// assert.Equal(t, 123, 123, "123 and 123 should be equal")
|
// assert.Equal(t, 123, 123, "123 and 123 should be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
if !ObjectsAreEqual(expected, actual) {
|
if !ObjectsAreEqual(expected, actual) {
|
||||||
diff := diff(expected, actual)
|
diff := diff(expected, actual)
|
||||||
return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
|
expected, actual = formatUnequalValues(expected, actual)
|
||||||
" != %#v (actual)%s", expected, actual, diff), msgAndArgs...)
|
return Fail(t, fmt.Sprintf("Not equal: \n"+
|
||||||
|
"expected: %s\n"+
|
||||||
|
"received: %s%s", expected, actual, diff), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// formatUnequalValues takes two values of arbitrary types and returns string
|
||||||
|
// representations appropriate to be presented to the user.
|
||||||
|
//
|
||||||
|
// If the values are not of like type, the returned strings will be prefixed
|
||||||
|
// with the type name, and the value will be enclosed in parenthesis similar
|
||||||
|
// to a type conversion in the Go grammar.
|
||||||
|
func formatUnequalValues(expected, actual interface{}) (e string, a string) {
|
||||||
|
if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
|
||||||
|
return fmt.Sprintf("%T(%#v)", expected, expected),
|
||||||
|
fmt.Sprintf("%T(%#v)", actual, actual)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%#v", expected),
|
||||||
|
fmt.Sprintf("%#v", actual)
|
||||||
|
}
|
||||||
|
|
||||||
// EqualValues asserts that two objects are equal or convertable to the same types
|
// EqualValues asserts that two objects are equal or convertable to the same types
|
||||||
// and equal.
|
// and equal.
|
||||||
//
|
//
|
||||||
|
@ -279,8 +328,11 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})
|
||||||
func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
if !ObjectsAreEqualValues(expected, actual) {
|
if !ObjectsAreEqualValues(expected, actual) {
|
||||||
return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
|
diff := diff(expected, actual)
|
||||||
" != %#v (actual)", expected, actual), msgAndArgs...)
|
expected, actual = formatUnequalValues(expected, actual)
|
||||||
|
return Fail(t, fmt.Sprintf("Not equal: \n"+
|
||||||
|
"expected: %s\n"+
|
||||||
|
"received: %s%s", expected, actual, diff), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -507,6 +559,9 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) bool {
|
||||||
// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
|
// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
if ObjectsAreEqual(expected, actual) {
|
if ObjectsAreEqual(expected, actual) {
|
||||||
|
@ -832,11 +887,11 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
||||||
if isNil(err) {
|
if err != nil {
|
||||||
return true
|
return Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err), msgAndArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Fail(t, fmt.Sprintf("Received unexpected error %q", err), msgAndArgs...)
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error asserts that a function returned an error (i.e. not `nil`).
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
|
@ -849,29 +904,33 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
|
||||||
|
|
||||||
message := messageFromMsgAndArgs(msgAndArgs...)
|
if err == nil {
|
||||||
return NotNil(t, err, "An error is expected but got nil. %s", message)
|
return Fail(t, "An error is expected but got nil.", msgAndArgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
||||||
// and that it is equal to the provided error.
|
// and that it is equal to the provided error.
|
||||||
//
|
//
|
||||||
// actualObj, err := SomeFunction()
|
// actualObj, err := SomeFunction()
|
||||||
// if assert.Error(t, err, "An error was expected") {
|
// assert.EqualError(t, err, expectedErrorString, "An error was expected")
|
||||||
// assert.Equal(t, err, expectedError)
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
// Returns whether the assertion was successful (true) or not (false).
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool {
|
func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool {
|
||||||
|
if !Error(t, theError, msgAndArgs...) {
|
||||||
message := messageFromMsgAndArgs(msgAndArgs...)
|
|
||||||
if !NotNil(t, theError, "An error is expected but got nil. %s", message) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
s := "An error with value \"%s\" is expected but got \"%s\". %s"
|
expected := errString
|
||||||
return Equal(t, errString, theError.Error(),
|
actual := theError.Error()
|
||||||
s, errString, theError.Error(), message)
|
// don't need to use deep equals here, we know they are both strings
|
||||||
|
if expected != actual {
|
||||||
|
return Fail(t, fmt.Sprintf("Error message not equal:\n"+
|
||||||
|
"expected: %q\n"+
|
||||||
|
"received: %q", expected, actual), msgAndArgs...)
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// matchRegexp return true if a specified regexp matches a string.
|
// matchRegexp return true if a specified regexp matches a string.
|
||||||
|
@ -986,9 +1045,8 @@ func diff(expected interface{}, actual interface{}) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
spew.Config.SortKeys = true
|
e := spewConfig.Sdump(expected)
|
||||||
e := spew.Sdump(expected)
|
a := spewConfig.Sdump(actual)
|
||||||
a := spew.Sdump(actual)
|
|
||||||
|
|
||||||
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{
|
||||||
A: difflib.SplitLines(e),
|
A: difflib.SplitLines(e),
|
||||||
|
@ -1002,3 +1060,10 @@ func diff(expected interface{}, actual interface{}) string {
|
||||||
|
|
||||||
return "\n\nDiff:\n" + diff
|
return "\n\nDiff:\n" + diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var spewConfig = spew.ConfigState{
|
||||||
|
Indent: " ",
|
||||||
|
DisablePointerAddresses: true,
|
||||||
|
DisableCapacities: true,
|
||||||
|
SortKeys: true,
|
||||||
|
}
|
||||||
|
|
2
vendor/github.com/stretchr/testify/assert/http_assertions.go
generated
vendored
2
vendor/github.com/stretchr/testify/assert/http_assertions.go
generated
vendored
|
@ -99,7 +99,7 @@ func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url strin
|
||||||
|
|
||||||
contains := strings.Contains(body, fmt.Sprint(str))
|
contains := strings.Contains(body, fmt.Sprint(str))
|
||||||
if contains {
|
if contains {
|
||||||
Fail(t, "Expected response body for %s to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)
|
Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body))
|
||||||
}
|
}
|
||||||
|
|
||||||
return !contains
|
return !contains
|
||||||
|
|
28
vendor/github.com/stretchr/testify/require/doc.go
generated
vendored
Normal file
28
vendor/github.com/stretchr/testify/require/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Package require implements the same assertions as the `assert` package but
|
||||||
|
// stops test execution when a test fails.
|
||||||
|
//
|
||||||
|
// Example Usage
|
||||||
|
//
|
||||||
|
// The following is a complete example using require in a standard test function:
|
||||||
|
// import (
|
||||||
|
// "testing"
|
||||||
|
// "github.com/stretchr/testify/require"
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// func TestSomething(t *testing.T) {
|
||||||
|
//
|
||||||
|
// var a string = "Hello"
|
||||||
|
// var b string = "Hello"
|
||||||
|
//
|
||||||
|
// require.Equal(t, a, b, "The two words should be the same.")
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Assertions
|
||||||
|
//
|
||||||
|
// The `require` package have same global functions as in the `assert` package,
|
||||||
|
// but instead of returning a boolean result they call `t.FailNow()`.
|
||||||
|
//
|
||||||
|
// Every assertion function also takes an optional string message as the final argument,
|
||||||
|
// allowing custom error messages to be appended to the message the assertion method outputs.
|
||||||
|
package require
|
16
vendor/github.com/stretchr/testify/require/forward_requirements.go
generated
vendored
Normal file
16
vendor/github.com/stretchr/testify/require/forward_requirements.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package require
|
||||||
|
|
||||||
|
// Assertions provides assertion methods around the
|
||||||
|
// TestingT interface.
|
||||||
|
type Assertions struct {
|
||||||
|
t TestingT
|
||||||
|
}
|
||||||
|
|
||||||
|
// New makes a new Assertions object for the specified TestingT.
|
||||||
|
func New(t TestingT) *Assertions {
|
||||||
|
return &Assertions{
|
||||||
|
t: t,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl
|
429
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
Normal file
429
vendor/github.com/stretchr/testify/require/require.go
generated
vendored
Normal file
|
@ -0,0 +1,429 @@
|
||||||
|
/*
|
||||||
|
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
|
||||||
|
* THIS FILE MUST NOT BE EDITED BY HAND
|
||||||
|
*/
|
||||||
|
|
||||||
|
package require
|
||||||
|
|
||||||
|
import (
|
||||||
|
assert "github.com/stretchr/testify/assert"
|
||||||
|
http "net/http"
|
||||||
|
url "net/url"
|
||||||
|
time "time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Condition uses a Comparison to assert a complex condition.
|
||||||
|
func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Condition(t, comp, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contains asserts that the specified string, list(array, slice...) or map contains the
|
||||||
|
// specified substring or element.
|
||||||
|
//
|
||||||
|
// assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'")
|
||||||
|
// assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
|
||||||
|
// assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Contains(t, s, contains, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
|
||||||
|
// a slice or a channel with len == 0.
|
||||||
|
//
|
||||||
|
// assert.Empty(t, obj)
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Empty(t, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equal asserts that two objects are equal.
|
||||||
|
//
|
||||||
|
// assert.Equal(t, 123, 123, "123 and 123 should be equal")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
|
func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Equal(t, expected, actual, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EqualError asserts that a function returned an error (i.e. not `nil`)
|
||||||
|
// and that it is equal to the provided error.
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// assert.EqualError(t, err, expectedErrorString, "An error was expected")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.EqualError(t, theError, errString, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EqualValues asserts that two objects are equal or convertable to the same types
|
||||||
|
// and equal.
|
||||||
|
//
|
||||||
|
// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.EqualValues(t, expected, actual, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error asserts that a function returned an error (i.e. not `nil`).
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// if assert.Error(t, err, "An error was expected") {
|
||||||
|
// assert.Equal(t, err, expectedError)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Error(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Error(t, err, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exactly asserts that two objects are equal is value and type.
|
||||||
|
//
|
||||||
|
// assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Exactly(t, expected, actual, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fail reports a failure through
|
||||||
|
func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Fail(t, failureMessage, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FailNow fails test
|
||||||
|
func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.FailNow(t, failureMessage, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// False asserts that the specified value is false.
|
||||||
|
//
|
||||||
|
// assert.False(t, myBool, "myBool should be false")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func False(t TestingT, value bool, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.False(t, value, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPBodyContains asserts that a specified handler returns a
|
||||||
|
// body that contains a string.
|
||||||
|
//
|
||||||
|
// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
|
||||||
|
if !assert.HTTPBodyContains(t, handler, method, url, values, str) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPBodyNotContains asserts that a specified handler returns a
|
||||||
|
// body that does not contain a string.
|
||||||
|
//
|
||||||
|
// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
|
||||||
|
if !assert.HTTPBodyNotContains(t, handler, method, url, values, str) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPError asserts that a specified handler returns an error status code.
|
||||||
|
//
|
||||||
|
// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
|
||||||
|
if !assert.HTTPError(t, handler, method, url, values) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPRedirect asserts that a specified handler returns a redirect status code.
|
||||||
|
//
|
||||||
|
// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
|
||||||
|
if !assert.HTTPRedirect(t, handler, method, url, values) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPSuccess asserts that a specified handler returns a success status code.
|
||||||
|
//
|
||||||
|
// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) {
|
||||||
|
if !assert.HTTPSuccess(t, handler, method, url, values) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements asserts that an object is implemented by the specified interface.
|
||||||
|
//
|
||||||
|
// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
|
||||||
|
func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Implements(t, interfaceObject, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InDelta asserts that the two numerals are within delta of each other.
|
||||||
|
//
|
||||||
|
// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01)
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InDeltaSlice is the same as InDelta, except it compares two slices.
|
||||||
|
func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InEpsilon asserts that expected and actual have a relative error less than epsilon
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
|
||||||
|
func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsType asserts that the specified objects are of the same type.
|
||||||
|
func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.IsType(t, expectedType, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONEq asserts that two JSON strings are equivalent.
|
||||||
|
//
|
||||||
|
// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.JSONEq(t, expected, actual, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Len asserts that the specified object has specific length.
|
||||||
|
// Len also fails if the object has a type that len() not accept.
|
||||||
|
//
|
||||||
|
// assert.Len(t, mySlice, 3, "The size of slice is not 3")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Len(t, object, length, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nil asserts that the specified object is nil.
|
||||||
|
//
|
||||||
|
// assert.Nil(t, err, "err should be nothing")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Nil(t, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoError asserts that a function returned no error (i.e. `nil`).
|
||||||
|
//
|
||||||
|
// actualObj, err := SomeFunction()
|
||||||
|
// if assert.NoError(t, err) {
|
||||||
|
// assert.Equal(t, actualObj, expectedObj)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NoError(t TestingT, err error, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NoError(t, err, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
|
||||||
|
// specified substring or element.
|
||||||
|
//
|
||||||
|
// assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
|
||||||
|
// assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
|
||||||
|
// assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotContains(t, s, contains, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
|
||||||
|
// a slice or a channel with len == 0.
|
||||||
|
//
|
||||||
|
// if assert.NotEmpty(t, obj) {
|
||||||
|
// assert.Equal(t, "two", obj[1])
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotEmpty(t, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotEqual asserts that the specified values are NOT equal.
|
||||||
|
//
|
||||||
|
// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
//
|
||||||
|
// Pointer variable equality is determined based on the equality of the
|
||||||
|
// referenced values (as opposed to the memory addresses).
|
||||||
|
func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotEqual(t, expected, actual, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotNil asserts that the specified object is not nil.
|
||||||
|
//
|
||||||
|
// assert.NotNil(t, err, "err should be something")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotNil(t, object, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
|
||||||
|
//
|
||||||
|
// assert.NotPanics(t, func(){
|
||||||
|
// RemainCalm()
|
||||||
|
// }, "Calling RemainCalm() should NOT panic")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotPanics(t, f, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotRegexp asserts that a specified regexp does not match a string.
|
||||||
|
//
|
||||||
|
// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
|
||||||
|
// assert.NotRegexp(t, "^start", "it's not starting")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotRegexp(t, rx, str, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotZero asserts that i is not the zero value for its type and returns the truth.
|
||||||
|
func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.NotZero(t, i, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panics asserts that the code inside the specified PanicTestFunc panics.
|
||||||
|
//
|
||||||
|
// assert.Panics(t, func(){
|
||||||
|
// GoCrazy()
|
||||||
|
// }, "Calling GoCrazy() should panic")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Panics(t, f, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regexp asserts that a specified regexp matches a string.
|
||||||
|
//
|
||||||
|
// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
|
||||||
|
// assert.Regexp(t, "start...$", "it's not starting")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Regexp(t, rx, str, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// True asserts that the specified value is true.
|
||||||
|
//
|
||||||
|
// assert.True(t, myBool, "myBool should be true")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func True(t TestingT, value bool, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.True(t, value, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithinDuration asserts that the two times are within duration delta of each other.
|
||||||
|
//
|
||||||
|
// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
|
||||||
|
//
|
||||||
|
// Returns whether the assertion was successful (true) or not (false).
|
||||||
|
func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zero asserts that i is the zero value for its type and returns the truth.
|
||||||
|
func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) {
|
||||||
|
if !assert.Zero(t, i, msgAndArgs...) {
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue