pidfile_test.go 650 B

1234567891011121314151617181920212223242526272829303132
  1. package pidfile
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. )
  8. func TestNewAndRemove(t *testing.T) {
  9. dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile")
  10. if err != nil {
  11. t.Fatal("Could not create test directory")
  12. }
  13. file, err := New(filepath.Join(dir, "testfile"))
  14. if err != nil {
  15. t.Fatal("Could not create test file", err)
  16. }
  17. if err := file.Remove(); err != nil {
  18. t.Fatal("Could not delete created test file")
  19. }
  20. }
  21. func TestRemoveInvalidPath(t *testing.T) {
  22. file := PIDFile{path: filepath.Join("foo", "bar")}
  23. if err := file.Remove(); err == nil {
  24. t.Fatal("Non-existing file doesn't give an error on delete")
  25. }
  26. }