2018-02-05 16:05:59 -05:00
|
|
|
package pidfile // import "github.com/docker/docker/pkg/pidfile"
|
2015-02-25 13:33:01 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewAndRemove(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Could not create test directory")
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:55 -04:00
|
|
|
path := filepath.Join(dir, "testfile")
|
|
|
|
file, err := New(path)
|
2015-02-25 13:33:01 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Could not create test file", err)
|
|
|
|
}
|
|
|
|
|
2016-04-18 18:09:55 -04:00
|
|
|
_, err = New(path)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Test file creation not blocked")
|
|
|
|
}
|
|
|
|
|
2015-02-25 13:33:01 -05:00
|
|
|
if err := file.Remove(); err != nil {
|
|
|
|
t.Fatal("Could not delete created test file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoveInvalidPath(t *testing.T) {
|
2015-07-25 04:35:07 -04:00
|
|
|
file := PIDFile{path: filepath.Join("foo", "bar")}
|
2015-02-25 13:33:01 -05:00
|
|
|
|
|
|
|
if err := file.Remove(); err == nil {
|
|
|
|
t.Fatal("Non-existing file doesn't give an error on delete")
|
|
|
|
}
|
|
|
|
}
|