jx/internal/tempdir/tempdir_test.go
Matthew Rich c4afd77777
Some checks are pending
Lint / golangci-lint (push) Waiting to run
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
pkg to manage resouce tmp files
2024-09-19 08:04:03 +00:00

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()
}