32 lines
928 B
Go
32 lines
928 B
Go
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
|
|
|
package tempdir
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func TestTempDir(t *testing.T) {
|
|
var TempDir Path = "testtempdir"
|
|
assert.Nil(t, TempDir.Create())
|
|
assert.Contains(t, string(TempDir), "/tmp")
|
|
assert.Nil(t, TempDir.CreateFile("foo.txt", "testdata"))
|
|
stat, err := os.Stat(filepath.Join(string(TempDir), "foo.txt"))
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, int64(8), stat.Size())
|
|
assert.Nil(t, TempDir.Mkdir("bar", 0700))
|
|
dirStat, err := os.Stat(filepath.Join(string(TempDir), "bar"))
|
|
assert.Nil(t, err)
|
|
assert.True(t, dirStat.IsDir())
|
|
TempDir.Remove()
|
|
var InvalidTempDir Path = ""
|
|
assert.False(t, InvalidTempDir.ValidPath())
|
|
assert.Nil(t, InvalidTempDir.Create())
|
|
assert.Contains(t, string(InvalidTempDir), "/tmp")
|
|
assert.Greater(t, len(InvalidTempDir), 10)
|
|
InvalidTempDir.Remove()
|
|
}
|