mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
c55a4ac779
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>
37 lines
783 B
Go
37 lines
783 B
Go
package pidfile // import "github.com/docker/docker/pkg/pidfile"
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestNewAndRemove(t *testing.T) {
|
|
dir, err := os.MkdirTemp(os.TempDir(), "test-pidfile")
|
|
if err != nil {
|
|
t.Fatal("Could not create test directory")
|
|
}
|
|
|
|
path := filepath.Join(dir, "testfile")
|
|
file, err := New(path)
|
|
if err != nil {
|
|
t.Fatal("Could not create test file", err)
|
|
}
|
|
|
|
_, err = New(path)
|
|
if err == nil {
|
|
t.Fatal("Test file creation not blocked")
|
|
}
|
|
|
|
if err := file.Remove(); err != nil {
|
|
t.Fatal("Could not delete created test file")
|
|
}
|
|
}
|
|
|
|
func TestRemoveInvalidPath(t *testing.T) {
|
|
file := PIDFile{path: filepath.Join("foo", "bar")}
|
|
|
|
if err := file.Remove(); err == nil {
|
|
t.Fatal("Non-existing file doesn't give an error on delete")
|
|
}
|
|
}
|