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:
Sebastiaan van Stijn 2022-09-22 16:31:28 +02:00
parent 320337f17a
commit 28b0aa9f1a
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
9 changed files with 21 additions and 29 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/docker/docker/client"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
)
@ -89,8 +88,8 @@ func TestNewAPIClientFromFlagsWithCustomHeaders(t *testing.T) {
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
customVersion := "v3.3.3"
defer env.Patch(t, "DOCKER_API_VERSION", customVersion)()
defer env.Patch(t, "DOCKER_HOST", ":2375")()
t.Setenv("DOCKER_API_VERSION", customVersion)
t.Setenv("DOCKER_HOST", ":2375")
opts := &flags.CommonOptions{}
configFile := &configfile.ConfigFile{}

View File

@ -10,7 +10,6 @@ import (
cliflags "github.com/docker/cli/cli/flags"
"github.com/docker/go-connections/tlsconfig"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"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) {
cli, err := NewDockerCli()
assert.NilError(t, err)
defer env.Patch(t, "DOCKER_HOST", "ssh://someswarmserver")()
t.Setenv("DOCKER_HOST", "ssh://someswarmserver")
cli.configFile = &configfile.ConfigFile{}
ctx, err := ResolveDefaultContext(&cliflags.CommonOptions{
TLS: true,

View File

@ -17,13 +17,12 @@ import (
"github.com/docker/docker/pkg/archive"
"github.com/google/go-cmp/cmp"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
"gotest.tools/v3/skip"
)
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
buffer := new(bytes.Buffer)
fakeBuild := newFakeBuild()
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) {
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
skip.If(t, os.Getuid() != 0, "root is required to chown files")
t.Setenv("DOCKER_BUILDKIT", "0")
fakeBuild := newFakeBuild()
cli := test.NewFakeCli(&fakeClient{imageBuildFunc: fakeBuild.build})
@ -90,7 +89,7 @@ func TestRunBuildResetsUidAndGidInContext(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(),
fs.WithFile("data", "data file"))
defer dir.Remove()
@ -123,7 +122,7 @@ COPY data /data
// TODO: test "context selection" logic directly when runBuild is refactored
// to support testing (ex: docker/cli#294)
func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
cmd := NewBuildCommand(test.NewFakeCli(&fakeClient{}))
// Clone a small repo that exists so git doesn't prompt for credentials
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
// case.
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")
err := os.MkdirAll(buildDir, 0777)
@ -154,7 +153,7 @@ func TestRunBuildFromLocalGitHubDir(t *testing.T) {
}
func TestRunBuildWithSymlinkedContext(t *testing.T) {
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
dockerfile := `
FROM alpine:3.6
RUN echo hello world

View File

@ -13,7 +13,7 @@ import (
)
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 := &registrytypes.IndexInfo{Name: "testserver"}
output, err := trust.Server(indexInfo)
expectedStr := "https://notary-test.example.com:5000"
@ -23,7 +23,7 @@ func TestENVTrustServer(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 := &registrytypes.IndexInfo{Name: "testserver"}
_, err := trust.Server(indexInfo)
if err == nil {

View File

@ -1,13 +1,11 @@
package interpolation
import (
"testing"
"strconv"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/env"
)
var defaults = map[string]string{
@ -62,7 +60,7 @@ func TestInvalidInterpolation(t *testing.T) {
}
func TestInterpolateWithDefaults(t *testing.T) {
defer env.Patch(t, "FOO", "BARZ")()
t.Setenv("FOO", "BARZ")
config := map[string]interface{}{
"networks": map[string]interface{}{

View File

@ -97,7 +97,7 @@ func TestOldJSONFallbackDeprecationWarning(t *testing.T) {
js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"user@example.com"}}`
tmpHome := fs.NewDir(t, t.Name(), fs.WithFile(oldConfigfile, js))
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
resetHomeDir()

View File

@ -9,7 +9,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/internal/test/output"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"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) {
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
dir := fs.NewDir(t, t.Name(),
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),
@ -102,7 +101,7 @@ func TestBuilderBroken(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(),
fs.WithFile(pluginFilename, `#!/bin/sh exit 1`, fs.WithMode(0777)),

View File

@ -12,14 +12,13 @@ import (
"github.com/docker/cli/internal/test/output"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
"gotest.tools/v3/icmd"
"gotest.tools/v3/skip"
)
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",
fs.WithFile("run", "echo running", fs.WithMode(0755)),
@ -58,7 +57,7 @@ func TestBuildFromContextDirectoryWithTag(t *testing.T) {
func TestTrustedBuild(t *testing.T) {
skip.If(t, environment.RemoteDaemon())
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
dir := fixtures.SetupConfigFile(t)
defer dir.Remove()
@ -93,7 +92,7 @@ func TestTrustedBuild(t *testing.T) {
func TestTrustedBuildUntrustedImage(t *testing.T) {
skip.If(t, environment.RemoteDaemon())
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
dir := fixtures.SetupConfigFile(t)
defer dir.Remove()
@ -120,7 +119,7 @@ func TestTrustedBuildUntrustedImage(t *testing.T) {
func TestBuildIidFileSquash(t *testing.T) {
environment.SkipIfNotExperimentalDaemon(t)
defer env.Patch(t, "DOCKER_BUILDKIT", "0")()
t.Setenv("DOCKER_BUILDKIT", "0")
dir := fs.NewDir(t, "test-iidfile-squash")
defer dir.Remove()

View File

@ -4,7 +4,6 @@ import (
"testing"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
)
@ -23,7 +22,7 @@ NO_SUCH_ENV
defer envFile1.Remove()
envFile2 := fs.NewFile(t, t.Name(), fs.WithContent("Z2=z\nA2=a"))
defer envFile2.Remove()
defer env.Patch(t, "FROM_ENV", "from-env")()
t.Setenv("FROM_ENV", "from-env")
tests := []struct {
name string