Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin authored on 2017/08/24 06:25:00... | ... |
@@ -3,14 +3,14 @@ package dockerfile |
3 | 3 |
import ( |
4 | 4 |
"testing" |
5 | 5 |
|
6 |
- "github.com/docker/docker/pkg/testutil/tempfile" |
|
6 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
7 | 7 |
"github.com/stretchr/testify/assert" |
8 | 8 |
) |
9 | 9 |
|
10 | 10 |
func TestIsExistingDirectory(t *testing.T) { |
11 |
- tmpfile := tempfile.NewTempFile(t, "file-exists-test", "something") |
|
11 |
+ tmpfile := fs.NewFile(t, "file-exists-test", fs.WithContent("something")) |
|
12 | 12 |
defer tmpfile.Remove() |
13 |
- tmpdir := tempfile.NewTempDir(t, "dir-exists-test") |
|
13 |
+ tmpdir := fs.NewDir(t, "dir-exists-test") |
|
14 | 14 |
defer tmpdir.Remove() |
15 | 15 |
|
16 | 16 |
var testcases = []struct { |
... | ... |
@@ -20,7 +20,7 @@ func TestIsExistingDirectory(t *testing.T) { |
20 | 20 |
}{ |
21 | 21 |
{ |
22 | 22 |
doc: "directory exists", |
23 |
- path: tmpdir.Path, |
|
23 |
+ path: tmpdir.Path(), |
|
24 | 24 |
expected: true, |
25 | 25 |
}, |
26 | 26 |
{ |
... | ... |
@@ -30,7 +30,7 @@ func TestIsExistingDirectory(t *testing.T) { |
30 | 30 |
}, |
31 | 31 |
{ |
32 | 32 |
doc: "file exists", |
33 |
- path: tmpfile.Name(), |
|
33 |
+ path: tmpfile.Path(), |
|
34 | 34 |
expected: false, |
35 | 35 |
}, |
36 | 36 |
} |
... | ... |
@@ -5,7 +5,7 @@ import ( |
5 | 5 |
|
6 | 6 |
"github.com/docker/docker/daemon/config" |
7 | 7 |
"github.com/docker/docker/pkg/testutil" |
8 |
- "github.com/docker/docker/pkg/testutil/tempfile" |
|
8 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
9 | 9 |
"github.com/sirupsen/logrus" |
10 | 10 |
"github.com/spf13/pflag" |
11 | 11 |
"github.com/stretchr/testify/assert" |
... | ... |
@@ -46,9 +46,9 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) { |
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { |
49 |
- tempFile := tempfile.NewTempFile(t, "config", `{"labels": ["l3=foo"]}`) |
|
49 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{"labels": ["l3=foo"]}`)) |
|
50 | 50 |
defer tempFile.Remove() |
51 |
- configFile := tempFile.Name() |
|
51 |
+ configFile := tempFile.Path() |
|
52 | 52 |
|
53 | 53 |
opts := defaultOptions(configFile) |
54 | 54 |
flags := opts.flags |
... | ... |
@@ -62,10 +62,10 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { |
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) { |
65 |
- tempFile := tempfile.NewTempFile(t, "config", `{"tlsverify": true}`) |
|
65 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{"tlsverify": true}`)) |
|
66 | 66 |
defer tempFile.Remove() |
67 | 67 |
|
68 |
- opts := defaultOptions(tempFile.Name()) |
|
68 |
+ opts := defaultOptions(tempFile.Path()) |
|
69 | 69 |
opts.TLSOptions.CAFile = "/tmp/ca.pem" |
70 | 70 |
|
71 | 71 |
loadedConfig, err := loadDaemonCliConfig(opts) |
... | ... |
@@ -75,10 +75,10 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) { |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) { |
78 |
- tempFile := tempfile.NewTempFile(t, "config", `{"tlsverify": false}`) |
|
78 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{"tlsverify": false}`)) |
|
79 | 79 |
defer tempFile.Remove() |
80 | 80 |
|
81 |
- opts := defaultOptions(tempFile.Name()) |
|
81 |
+ opts := defaultOptions(tempFile.Path()) |
|
82 | 82 |
opts.TLSOptions.CAFile = "/tmp/ca.pem" |
83 | 83 |
|
84 | 84 |
loadedConfig, err := loadDaemonCliConfig(opts) |
... | ... |
@@ -88,10 +88,10 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) { |
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) { |
91 |
- tempFile := tempfile.NewTempFile(t, "config", `{}`) |
|
91 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{}`)) |
|
92 | 92 |
defer tempFile.Remove() |
93 | 93 |
|
94 |
- opts := defaultOptions(tempFile.Name()) |
|
94 |
+ opts := defaultOptions(tempFile.Path()) |
|
95 | 95 |
opts.TLSOptions.CAFile = "/tmp/ca.pem" |
96 | 96 |
|
97 | 97 |
loadedConfig, err := loadDaemonCliConfig(opts) |
... | ... |
@@ -101,10 +101,10 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) { |
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) { |
104 |
- tempFile := tempfile.NewTempFile(t, "config", `{"log-level": "warn"}`) |
|
104 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{"log-level": "warn"}`)) |
|
105 | 105 |
defer tempFile.Remove() |
106 | 106 |
|
107 |
- opts := defaultOptions(tempFile.Name()) |
|
107 |
+ opts := defaultOptions(tempFile.Path()) |
|
108 | 108 |
loadedConfig, err := loadDaemonCliConfig(opts) |
109 | 109 |
require.NoError(t, err) |
110 | 110 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -114,10 +114,10 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) { |
114 | 114 |
|
115 | 115 |
func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) { |
116 | 116 |
content := `{"tlscacert": "/etc/certs/ca.pem", "log-driver": "syslog"}` |
117 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
117 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
118 | 118 |
defer tempFile.Remove() |
119 | 119 |
|
120 |
- opts := defaultOptions(tempFile.Name()) |
|
120 |
+ opts := defaultOptions(tempFile.Path()) |
|
121 | 121 |
loadedConfig, err := loadDaemonCliConfig(opts) |
122 | 122 |
require.NoError(t, err) |
123 | 123 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -131,10 +131,10 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { |
131 | 131 |
"registry-mirrors": ["https://mirrors.docker.com"], |
132 | 132 |
"insecure-registries": ["https://insecure.docker.com"] |
133 | 133 |
}` |
134 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
134 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
135 | 135 |
defer tempFile.Remove() |
136 | 136 |
|
137 |
- opts := defaultOptions(tempFile.Name()) |
|
137 |
+ opts := defaultOptions(tempFile.Path()) |
|
138 | 138 |
loadedConfig, err := loadDaemonCliConfig(opts) |
139 | 139 |
require.NoError(t, err) |
140 | 140 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -9,17 +9,17 @@ import ( |
9 | 9 |
"testing" |
10 | 10 |
|
11 | 11 |
"github.com/docker/docker/daemon/config" |
12 |
- "github.com/docker/docker/pkg/testutil/tempfile" |
|
12 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
13 | 13 |
"github.com/stretchr/testify/assert" |
14 | 14 |
"github.com/stretchr/testify/require" |
15 | 15 |
) |
16 | 16 |
|
17 | 17 |
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { |
18 | 18 |
content := `{"log-opts": {"max-size": "1k"}}` |
19 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
19 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
20 | 20 |
defer tempFile.Remove() |
21 | 21 |
|
22 |
- opts := defaultOptions(tempFile.Name()) |
|
22 |
+ opts := defaultOptions(tempFile.Path()) |
|
23 | 23 |
opts.Debug = true |
24 | 24 |
opts.LogLevel = "info" |
25 | 25 |
assert.NoError(t, opts.flags.Set("selinux-enabled", "true")) |
... | ... |
@@ -37,10 +37,10 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { |
37 | 37 |
|
38 | 38 |
func TestLoadDaemonConfigWithNetwork(t *testing.T) { |
39 | 39 |
content := `{"bip": "127.0.0.2", "ip": "127.0.0.1"}` |
40 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
40 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
41 | 41 |
defer tempFile.Remove() |
42 | 42 |
|
43 |
- opts := defaultOptions(tempFile.Name()) |
|
43 |
+ opts := defaultOptions(tempFile.Path()) |
|
44 | 44 |
loadedConfig, err := loadDaemonCliConfig(opts) |
45 | 45 |
require.NoError(t, err) |
46 | 46 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -54,10 +54,10 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) { |
54 | 54 |
"cluster-store-opts": {"kv.cacertfile": "/var/lib/docker/discovery_certs/ca.pem"}, |
55 | 55 |
"log-opts": {"tag": "test"} |
56 | 56 |
}` |
57 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
57 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
58 | 58 |
defer tempFile.Remove() |
59 | 59 |
|
60 |
- opts := defaultOptions(tempFile.Name()) |
|
60 |
+ opts := defaultOptions(tempFile.Path()) |
|
61 | 61 |
loadedConfig, err := loadDaemonCliConfig(opts) |
62 | 62 |
require.NoError(t, err) |
63 | 63 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -71,10 +71,10 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) { |
71 | 71 |
|
72 | 72 |
func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { |
73 | 73 |
content := `{ "userland-proxy": false }` |
74 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
74 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
75 | 75 |
defer tempFile.Remove() |
76 | 76 |
|
77 |
- opts := defaultOptions(tempFile.Name()) |
|
77 |
+ opts := defaultOptions(tempFile.Path()) |
|
78 | 78 |
loadedConfig, err := loadDaemonCliConfig(opts) |
79 | 79 |
require.NoError(t, err) |
80 | 80 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -90,10 +90,10 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { |
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { |
93 |
- tempFile := tempfile.NewTempFile(t, "config", `{}`) |
|
93 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(`{}`)) |
|
94 | 94 |
defer tempFile.Remove() |
95 | 95 |
|
96 |
- opts := defaultOptions(tempFile.Name()) |
|
96 |
+ opts := defaultOptions(tempFile.Path()) |
|
97 | 97 |
loadedConfig, err := loadDaemonCliConfig(opts) |
98 | 98 |
require.NoError(t, err) |
99 | 99 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -103,10 +103,10 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { |
103 | 103 |
|
104 | 104 |
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) { |
105 | 105 |
content := `{"disable-legacy-registry": false}` |
106 |
- tempFile := tempfile.NewTempFile(t, "config", content) |
|
106 |
+ tempFile := fs.NewFile(t, "config", fs.WithContent(content)) |
|
107 | 107 |
defer tempFile.Remove() |
108 | 108 |
|
109 |
- opts := defaultOptions(tempFile.Name()) |
|
109 |
+ opts := defaultOptions(tempFile.Path()) |
|
110 | 110 |
loadedConfig, err := loadDaemonCliConfig(opts) |
111 | 111 |
require.NoError(t, err) |
112 | 112 |
require.NotNil(t, loadedConfig) |
... | ... |
@@ -6,8 +6,8 @@ import ( |
6 | 6 |
"testing" |
7 | 7 |
|
8 | 8 |
"github.com/docker/docker/opts" |
9 |
- "github.com/docker/docker/pkg/testutil/tempfile" |
|
10 | 9 |
"github.com/docker/go-units" |
10 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
11 | 11 |
"github.com/spf13/pflag" |
12 | 12 |
"github.com/stretchr/testify/assert" |
13 | 13 |
"github.com/stretchr/testify/require" |
... | ... |
@@ -29,7 +29,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) { |
29 | 29 |
} |
30 | 30 |
}`)) |
31 | 31 |
|
32 |
- file := tempfile.NewTempFile(t, "docker-config", configFileData) |
|
32 |
+ file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData)) |
|
33 | 33 |
defer file.Remove() |
34 | 34 |
|
35 | 35 |
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) |
... | ... |
@@ -38,7 +38,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) { |
38 | 38 |
flags.Var(opts.NewNamedUlimitOpt("default-ulimits", nil), "default-ulimit", "") |
39 | 39 |
flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "") |
40 | 40 |
|
41 |
- cc, err := getConflictFreeConfiguration(file.Name(), flags) |
|
41 |
+ cc, err := getConflictFreeConfiguration(file.Path(), flags) |
|
42 | 42 |
require.NoError(t, err) |
43 | 43 |
|
44 | 44 |
assert.True(t, cc.Debug) |
... | ... |
@@ -70,7 +70,7 @@ func TestDaemonConfigurationMerge(t *testing.T) { |
70 | 70 |
} |
71 | 71 |
}`)) |
72 | 72 |
|
73 |
- file := tempfile.NewTempFile(t, "docker-config", configFileData) |
|
73 |
+ file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData)) |
|
74 | 74 |
defer file.Remove() |
75 | 75 |
|
76 | 76 |
c := &Config{ |
... | ... |
@@ -90,7 +90,7 @@ func TestDaemonConfigurationMerge(t *testing.T) { |
90 | 90 |
flags.Var(opts.NewNamedUlimitOpt("default-ulimits", nil), "default-ulimit", "") |
91 | 91 |
flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "") |
92 | 92 |
|
93 |
- cc, err := MergeDaemonConfigurations(c, flags, file.Name()) |
|
93 |
+ cc, err := MergeDaemonConfigurations(c, flags, file.Path()) |
|
94 | 94 |
require.NoError(t, err) |
95 | 95 |
|
96 | 96 |
assert.True(t, cc.Debug) |
... | ... |
@@ -120,7 +120,7 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) { |
120 | 120 |
"default-shm-size": "1g" |
121 | 121 |
}`)) |
122 | 122 |
|
123 |
- file := tempfile.NewTempFile(t, "docker-config", data) |
|
123 |
+ file := fs.NewFile(t, "docker-config", fs.WithContent(data)) |
|
124 | 124 |
defer file.Remove() |
125 | 125 |
|
126 | 126 |
c := &Config{} |
... | ... |
@@ -129,7 +129,7 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) { |
129 | 129 |
shmSize := opts.MemBytes(DefaultShmSize) |
130 | 130 |
flags.Var(&shmSize, "default-shm-size", "") |
131 | 131 |
|
132 |
- cc, err := MergeDaemonConfigurations(c, flags, file.Name()) |
|
132 |
+ cc, err := MergeDaemonConfigurations(c, flags, file.Path()) |
|
133 | 133 |
require.NoError(t, err) |
134 | 134 |
|
135 | 135 |
expectedValue := 1 * 1024 * 1024 * 1024 |
... | ... |
@@ -23,11 +23,11 @@ import ( |
23 | 23 |
"github.com/docker/docker/integration-cli/cli" |
24 | 24 |
"github.com/docker/docker/integration-cli/daemon" |
25 | 25 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
26 |
- "github.com/docker/docker/pkg/testutil/tempfile" |
|
27 | 26 |
"github.com/docker/libnetwork/driverapi" |
28 | 27 |
"github.com/docker/libnetwork/ipamapi" |
29 | 28 |
remoteipam "github.com/docker/libnetwork/ipams/remote/api" |
30 | 29 |
"github.com/go-check/check" |
30 |
+ "github.com/gotestyourself/gotestyourself/fs" |
|
31 | 31 |
"github.com/vishvananda/netlink" |
32 | 32 |
) |
33 | 33 |
|
... | ... |
@@ -67,11 +67,11 @@ func (s *DockerSwarmSuite) TestSwarmUpdate(c *check.C) { |
67 | 67 |
c.Assert(spec.CAConfig.ExternalCAs[1].CACert, checker.Equals, string(expected)) |
68 | 68 |
|
69 | 69 |
// passing an invalid external CA fails |
70 |
- tempFile := tempfile.NewTempFile(c, "testfile", "fakecert") |
|
70 |
+ tempFile := fs.NewFile(c, "testfile", fs.WithContent("fakecert")) |
|
71 | 71 |
defer tempFile.Remove() |
72 | 72 |
|
73 | 73 |
result := cli.Docker(cli.Args("swarm", "update", |
74 |
- "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://something.org,cacert=%s", tempFile.Name())), |
|
74 |
+ "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://something.org,cacert=%s", tempFile.Path())), |
|
75 | 75 |
cli.Daemon(d.Daemon)) |
76 | 76 |
result.Assert(c, icmd.Expected{ |
77 | 77 |
ExitCode: 125, |
... | ... |
@@ -88,11 +88,11 @@ func (s *DockerSwarmSuite) TestSwarmInit(c *check.C) { |
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
// passing an invalid external CA fails |
91 |
- tempFile := tempfile.NewTempFile(c, "testfile", "fakecert") |
|
91 |
+ tempFile := fs.NewFile(c, "testfile", fs.WithContent("fakecert")) |
|
92 | 92 |
defer tempFile.Remove() |
93 | 93 |
|
94 | 94 |
result := cli.Docker(cli.Args("swarm", "init", "--cert-expiry", "30h", "--dispatcher-heartbeat", "11s", |
95 |
- "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://somethingelse.org,cacert=%s", tempFile.Name())), |
|
95 |
+ "--external-ca", fmt.Sprintf("protocol=cfssl,url=https://somethingelse.org,cacert=%s", tempFile.Path())), |
|
96 | 96 |
cli.Daemon(d.Daemon)) |
97 | 97 |
result.Assert(c, icmd.Expected{ |
98 | 98 |
ExitCode: 125, |