Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
cli: tests: remove the tmpdir to the config.json
Browse files Browse the repository at this point in the history
We were defer removing the temporary config.json files
but not the tmpdir path we had created to store them in.
Expose that path out so we can defer removeall it.

Fixes: #480

Signed-off-by: Graham Whaley <[email protected]>
  • Loading branch information
Graham Whaley authored and Eric Ernst committed Aug 23, 2018
1 parent b0e5614 commit 9fac082
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
24 changes: 15 additions & 9 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestDeleteInvalidConfig(t *testing.T) {
assert.False(vcmock.IsMockError(err))
}

func testConfigSetup(t *testing.T) string {
func testConfigSetup(t *testing.T) (rootPath string, configPath string) {
assert := assert.New(t)

tmpdir, err := ioutil.TempDir("", "")
Expand All @@ -135,8 +135,8 @@ func testConfigSetup(t *testing.T) string {
assert.NoError(err)

// config json path
configPath := filepath.Join(bundlePath, "config.json")
return configPath
configPath = filepath.Join(bundlePath, "config.json")
return tmpdir, configPath
}

func TestDeleteSandbox(t *testing.T) {
Expand All @@ -146,7 +146,8 @@ func TestDeleteSandbox(t *testing.T) {
MockID: testSandboxID,
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -223,7 +224,8 @@ func TestDeleteInvalidContainerType(t *testing.T) {
MockID: testSandboxID,
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -261,7 +263,8 @@ func TestDeleteSandboxRunning(t *testing.T) {
MockID: testSandboxID,
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -340,7 +343,8 @@ func TestDeleteRunningContainer(t *testing.T) {
},
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -422,7 +426,8 @@ func TestDeleteContainer(t *testing.T) {
},
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -523,7 +528,8 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
},
}

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down
24 changes: 16 additions & 8 deletions cli/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func TestExecuteErrors(t *testing.T) {
assert.False(vcmock.IsMockError(err))

// Container state undefined
configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -147,7 +148,8 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
flagSet.Parse([]string{testContainerID})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -195,7 +197,8 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
flagSet.Parse([]string{testContainerID})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -261,7 +264,8 @@ func TestExecuteWithFlags(t *testing.T) {
flagSet.Parse([]string{testContainerID, "/tmp/foo"})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -349,7 +353,8 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
flagSet.Parse([]string{testContainerID, "/tmp/foo"})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -427,7 +432,8 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
flagSet.Parse([]string{testContainerID})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -478,7 +484,8 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
flagSet.Parse([]string{testContainerID, "/tmp/foo"})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down Expand Up @@ -578,7 +585,8 @@ func TestExecuteWithEmptyEnvironmentValue(t *testing.T) {
flagSet.Parse([]string{testContainerID})
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
rootPath, configPath := testConfigSetup(t)
defer os.RemoveAll(rootPath)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

Expand Down

0 comments on commit 9fac082

Please sign in to comment.