-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5043 from rhatdan/tmpdir
GetTmpDir is not using ImageCopyTmpdir correctly
- Loading branch information
Showing
2 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tmpdir | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/containers/common/pkg/config" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetTempDir(t *testing.T) { | ||
// test default | ||
err := os.Unsetenv("TMPDIR") | ||
require.NoError(t, err) | ||
err = os.Setenv("CONTAINERS_CONF", "/dev/null") | ||
require.NoError(t, err) | ||
tmpdir := GetTempDir() | ||
assert.Equal(t, "/var/tmp", tmpdir) | ||
|
||
// test TMPDIR Environment | ||
err = os.Setenv("TMPDIR", "/tmp/bogus") | ||
require.NoError(t, err) | ||
tmpdir = GetTempDir() | ||
assert.Equal(t, tmpdir, "/tmp/bogus") | ||
err = os.Unsetenv("TMPDIR") | ||
require.NoError(t, err) | ||
|
||
f, err := os.CreateTemp("", "containers.conf-") | ||
require.NoError(t, err) | ||
// close and remove the temporary file at the end of the program | ||
defer f.Close() | ||
defer os.Remove(f.Name()) | ||
data := []byte("[engine]\nimage_copy_tmp_dir=\"/mnt\"\n") | ||
_, err = f.Write(data) | ||
require.NoError(t, err) | ||
|
||
err = os.Setenv("CONTAINERS_CONF", f.Name()) | ||
require.NoError(t, err) | ||
// force config reset of default containers.conf | ||
options := config.Options{ | ||
SetDefault: true, | ||
} | ||
_, err = config.New(&options) | ||
require.NoError(t, err) | ||
tmpdir = GetTempDir() | ||
assert.Equal(t, "/mnt", tmpdir) | ||
|
||
} |