mirror of https://github.com/docker/cli.git
replace uses of deprecated env.Patch()
Also removing redundant defer for env.PatchAll(), which is now automatically handled in t.Cleanup() Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
320337f17a
commit
28b0aa9f1a
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/fs"
|
"gotest.tools/v3/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,8 +88,8 @@ func TestNewAPIClientFromFlagsWithCustomHeaders(t *testing.T) {
|
||||||
|
|
||||||
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
||||||
customVersion := "v3.3.3"
|
customVersion := "v3.3.3"
|
||||||
defer env.Patch(t, "DOCKER_API_VERSION", customVersion)()
|
t.Setenv("DOCKER_API_VERSION", customVersion)
|
||||||
defer env.Patch(t, "DOCKER_HOST", ":2375")()
|
t.Setenv("DOCKER_HOST", ":2375")
|
||||||
|
|
||||||
opts := &flags.CommonOptions{}
|
opts := &flags.CommonOptions{}
|
||||||
configFile := &configfile.ConfigFile{}
|
configFile := &configfile.ConfigFile{}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
cliflags "github.com/docker/cli/cli/flags"
|
cliflags "github.com/docker/cli/cli/flags"
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@ func testStore(t *testing.T, meta store.Metadata, tls store.ContextTLSData) stor
|
||||||
func TestDefaultContextInitializer(t *testing.T) {
|
func TestDefaultContextInitializer(t *testing.T) {
|
||||||
cli, err := NewDockerCli()
|
cli, err := NewDockerCli()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
defer env.Patch(t, "DOCKER_HOST", "ssh://someswarmserver")()
|
t.Setenv("DOCKER_HOST", "ssh://someswarmserver")
|
||||||
cli.configFile = &configfile.ConfigFile{}
|
cli.configFile = &configfile.ConfigFile{}
|
||||||
ctx, err := ResolveDefaultContext(&cliflags.CommonOptions{
|
ctx, err := ResolveDefaultContext(&cliflags.CommonOptions{
|
||||||
TLS: true,
|
TLS: true,
|
||||||
|
|
|
@ -17,13 +17,12 @@ import (
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/fs"
|
"gotest.tools/v3/fs"
|
||||||
"gotest.tools/v3/skip"
|
"gotest.tools/v3/skip"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
fakeBuild := newFakeBuild()
|
fakeBuild := newFakeBuild()
|
||||||
fakeImageBuild := func(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
fakeImageBuild := func(ctx context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
|
||||||
|
@ -59,8 +58,8 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
|
func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
|
||||||
skip.If(t, os.Getuid() != 0, "root is required to chown files")
|
skip.If(t, os.Getuid() != 0, "root is required to chown files")
|
||||||
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
fakeBuild := newFakeBuild()
|
fakeBuild := newFakeBuild()
|
||||||
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
|
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunBuildDockerfileOutsideContext(t *testing.T) {
|
func TestRunBuildDockerfileOutsideContext(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
dir := fs.NewDir(t, t.Name(),
|
dir := fs.NewDir(t, t.Name(),
|
||||||
fs.WithFile("data", "data file"))
|
fs.WithFile("data", "data file"))
|
||||||
defer dir.Remove()
|
defer dir.Remove()
|
||||||
|
@ -123,7 +122,7 @@ COPY data /data
|
||||||
// TODO: test "context selection" logic directly when runBuild is refactored
|
// TODO: test "context selection" logic directly when runBuild is refactored
|
||||||
// to support testing (ex: docker/cli#294)
|
// to support testing (ex: docker/cli#294)
|
||||||
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
|
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
|
||||||
// Clone a small repo that exists so git doesn't prompt for credentials
|
// Clone a small repo that exists so git doesn't prompt for credentials
|
||||||
cmd.SetArgs([]string{"github.com/docker/for-win"})
|
cmd.SetArgs([]string{"github.com/docker/for-win"})
|
||||||
|
@ -137,7 +136,7 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
||||||
// starting with `github.com` takes precedence over the `github.com` special
|
// starting with `github.com` takes precedence over the `github.com` special
|
||||||
// case.
|
// case.
|
||||||
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
buildDir := filepath.Join(t.TempDir(), "github.com", "docker", "no-such-repository")
|
buildDir := filepath.Join(t.TempDir(), "github.com", "docker", "no-such-repository")
|
||||||
err := os.MkdirAll(buildDir, 0777)
|
err := os.MkdirAll(buildDir, 0777)
|
||||||
|
@ -154,7 +153,7 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunBuildWithSymlinkedContext(t *testing.T) {
|
func TestRunBuildWithSymlinkedContext(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
dockerfile := `
|
dockerfile := `
|
||||||
FROM alpine:3.6
|
FROM alpine:3.6
|
||||||
RUN echo hello world
|
RUN echo hello world
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestENVTrustServer(t *testing.T) {
|
func TestENVTrustServer(t *testing.T) {
|
||||||
defer env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "https://notary-test.example.com:5000"})()
|
env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "https://notary-test.example.com:5000"})
|
||||||
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
||||||
output, err := trust.Server(indexInfo)
|
output, err := trust.Server(indexInfo)
|
||||||
expectedStr := "https://notary-test.example.com:5000"
|
expectedStr := "https://notary-test.example.com:5000"
|
||||||
|
@ -23,7 +23,7 @@ func TestENVTrustServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPENVTrustServer(t *testing.T) {
|
func TestHTTPENVTrustServer(t *testing.T) {
|
||||||
defer env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "http://notary-test.example.com:5000"})()
|
env.PatchAll(t, map[string]string{"DOCKER_CONTENT_TRUST_SERVER": "http://notary-test.example.com:5000"})
|
||||||
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
indexInfo := ®istrytypes.IndexInfo{Name: "testserver"}
|
||||||
_, err := trust.Server(indexInfo)
|
_, err := trust.Server(indexInfo)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package interpolation
|
package interpolation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaults = map[string]string{
|
var defaults = map[string]string{
|
||||||
|
@ -62,7 +60,7 @@ func TestInvalidInterpolation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInterpolateWithDefaults(t *testing.T) {
|
func TestInterpolateWithDefaults(t *testing.T) {
|
||||||
defer env.Patch(t, "FOO", "BARZ")()
|
t.Setenv("FOO", "BARZ")
|
||||||
|
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
"networks": map[string]interface{}{
|
"networks": map[string]interface{}{
|
||||||
|
|
|
@ -97,7 +97,7 @@ func TestOldJSONFallbackDeprecationWarning(t *testing.T) {
|
||||||
js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}`
|
js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}`
|
||||||
tmpHome := fs.NewDir(t, t.Name(), fs.WithFile(oldConfigfile, js))
|
tmpHome := fs.NewDir(t, t.Name(), fs.WithFile(oldConfigfile, js))
|
||||||
defer tmpHome.Remove()
|
defer tmpHome.Remove()
|
||||||
defer env.PatchAll(t, map[string]string{homeKey: tmpHome.Path(), "DOCKER_CONFIG": ""})()
|
env.PatchAll(t, map[string]string{homeKey: tmpHome.Path(), "DOCKER_CONFIG": ""})
|
||||||
|
|
||||||
// reset the homeDir, configDir, and its sync.Once, to force them being resolved again
|
// reset the homeDir, configDir, and its sync.Once, to force them being resolved again
|
||||||
resetHomeDir()
|
resetHomeDir()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/cli/internal/test/output"
|
"github.com/docker/cli/internal/test/output"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/fs"
|
"gotest.tools/v3/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildkitDisabled(t *testing.T) {
|
func TestBuildkitDisabled(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
dir := fs.NewDir(t, t.Name(),
|
dir := fs.NewDir(t, t.Name(),
|
||||||
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),
|
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),
|
||||||
|
@ -102,7 +101,7 @@ func TestBuilderBroken(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderBrokenEnforced(t *testing.T) {
|
func TestBuilderBrokenEnforced(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "1")()
|
t.Setenv("DOCKER_BUILDKIT", "1")
|
||||||
|
|
||||||
dir := fs.NewDir(t, t.Name(),
|
dir := fs.NewDir(t, t.Name(),
|
||||||
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),
|
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),
|
||||||
|
|
|
@ -12,14 +12,13 @@ import (
|
||||||
"github.com/docker/cli/internal/test/output"
|
"github.com/docker/cli/internal/test/output"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
is "gotest.tools/v3/assert/cmp"
|
is "gotest.tools/v3/assert/cmp"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/fs"
|
"gotest.tools/v3/fs"
|
||||||
"gotest.tools/v3/icmd"
|
"gotest.tools/v3/icmd"
|
||||||
"gotest.tools/v3/skip"
|
"gotest.tools/v3/skip"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildFromContextDirectoryWithTag(t *testing.T) {
|
func TestBuildFromContextDirectoryWithTag(t *testing.T) {
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
dir := fs.NewDir(t, "test-build-context-dir",
|
dir := fs.NewDir(t, "test-build-context-dir",
|
||||||
fs.WithFile("run", "echo running", fs.WithMode(0755)),
|
fs.WithFile("run", "echo running", fs.WithMode(0755)),
|
||||||
|
@ -58,7 +57,7 @@ func TestBuildFromContextDirectoryWithTag(t *testing.T) {
|
||||||
|
|
||||||
func TestTrustedBuild(t *testing.T) {
|
func TestTrustedBuild(t *testing.T) {
|
||||||
skip.If(t, environment.RemoteDaemon())
|
skip.If(t, environment.RemoteDaemon())
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
dir := fixtures.SetupConfigFile(t)
|
dir := fixtures.SetupConfigFile(t)
|
||||||
defer dir.Remove()
|
defer dir.Remove()
|
||||||
|
@ -93,7 +92,7 @@ func TestTrustedBuild(t *testing.T) {
|
||||||
|
|
||||||
func TestTrustedBuildUntrustedImage(t *testing.T) {
|
func TestTrustedBuildUntrustedImage(t *testing.T) {
|
||||||
skip.If(t, environment.RemoteDaemon())
|
skip.If(t, environment.RemoteDaemon())
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
dir := fixtures.SetupConfigFile(t)
|
dir := fixtures.SetupConfigFile(t)
|
||||||
defer dir.Remove()
|
defer dir.Remove()
|
||||||
|
@ -120,7 +119,7 @@ func TestTrustedBuildUntrustedImage(t *testing.T) {
|
||||||
|
|
||||||
func TestBuildIidFileSquash(t *testing.T) {
|
func TestBuildIidFileSquash(t *testing.T) {
|
||||||
environment.SkipIfNotExperimentalDaemon(t)
|
environment.SkipIfNotExperimentalDaemon(t)
|
||||||
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
|
t.Setenv("DOCKER_BUILDKIT", "0")
|
||||||
|
|
||||||
dir := fs.NewDir(t, "test-iidfile-squash")
|
dir := fs.NewDir(t, "test-iidfile-squash")
|
||||||
defer dir.Remove()
|
defer dir.Remove()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/env"
|
|
||||||
"gotest.tools/v3/fs"
|
"gotest.tools/v3/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ NO_SUCH_ENV
|
||||||
defer envFile1.Remove()
|
defer envFile1.Remove()
|
||||||
envFile2 := fs.NewFile(t, t.Name(), fs.WithContent("Z2=z\nA2=a"))
|
envFile2 := fs.NewFile(t, t.Name(), fs.WithContent("Z2=z\nA2=a"))
|
||||||
defer envFile2.Remove()
|
defer envFile2.Remove()
|
||||||
defer env.Patch(t, "FROM_ENV", "from-env")()
|
t.Setenv("FROM_ENV", "from-env")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
Loading…
Reference in New Issue