github.com/tompao/docker@v1.9.1/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 file, err := New(filepath.Join(dir, "testfile")) 17 if err != nil { 18 t.Fatal("Could not create test file", err) 19 } 20 21 if err := file.Remove(); err != nil { 22 t.Fatal("Could not delete created test file") 23 } 24 } 25 26 func TestRemoveInvalidPath(t *testing.T) { 27 file := PIDFile{path: filepath.Join("foo", "bar")} 28 29 if err := file.Remove(); err == nil { 30 t.Fatal("Non-existing file doesn't give an error on delete") 31 } 32 }