moby/daemon/logger/loggerutils/file_windows_test.go
Eng Zer Jun c55a4ac779
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-08-27 14:56:57 +08:00

33 lines
731 B
Go

package loggerutils
import (
"os"
"path/filepath"
"testing"
"gotest.tools/v3/assert"
)
func TestOpenFileDelete(t *testing.T) {
tmpDir, err := os.MkdirTemp("", t.Name())
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
f, err := openFile(filepath.Join(tmpDir, "test.txt"), os.O_CREATE|os.O_RDWR, 644)
assert.NilError(t, err)
defer f.Close()
assert.NilError(t, os.RemoveAll(f.Name()))
}
func TestOpenFileRename(t *testing.T) {
tmpDir, err := os.MkdirTemp("", t.Name())
assert.NilError(t, err)
defer os.RemoveAll(tmpDir)
f, err := openFile(filepath.Join(tmpDir, "test.txt"), os.O_CREATE|os.O_RDWR, 0644)
assert.NilError(t, err)
defer f.Close()
assert.NilError(t, os.Rename(f.Name(), f.Name()+"renamed"))
}