1
0
mirror of https://github.com/moby/moby.git synced 2025-07-29 07:21:35 +03:00

test: use T.Setenv to set env vars in tests

This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-04-23 17:01:58 +08:00
parent e78f6f9c68
commit 36049a04d2
10 changed files with 39 additions and 153 deletions

View File

@ -1693,12 +1693,7 @@ func (s *DockerDaemonSuite) TestDaemonStartWithDefaultTLSHost(c *testing.T) {
"--tlskey", "fixtures/https/server-key.pem")
// The client with --tlsverify should also use default host localhost:2376
tmpHost := os.Getenv("DOCKER_HOST")
defer func() {
os.Setenv("DOCKER_HOST", tmpHost)
}()
os.Setenv("DOCKER_HOST", "")
c.Setenv("DOCKER_HOST", "")
out, _ := dockerCmd(
c,