github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/pidfile/pidfile_test.go (about) 1 package pidfile 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 ) 9 10 func TestNewAndRemove(t *testing.T) { 11 dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile") 12 if err != nil { 13 t.Fatal("Could not create test directory") 14 } 15 16 path := filepath.Join(dir, "testfile") 17 file, err := New(path) 18 if err != nil { 19 t.Fatal("Could not create test file", err) 20 } 21 22 _, err = New(path) 23 if err == nil { 24 t.Fatal("Test file creation not blocked") 25 } 26 27 if err := file.Remove(); err != nil { 28 t.Fatal("Could not delete created test file") 29 } 30 } 31 32 func TestRemoveInvalidPath(t *testing.T) { 33 file := PIDFile{path: filepath.Join("foo", "bar")} 34 35 if err := file.Remove(); err == nil { 36 t.Fatal("Non-existing file doesn't give an error on delete") 37 } 38 }