Moved pidfile from utils to pkg

Fixes #10958 by moving utils.daemon to pkg.pidfile.
Test cases were also added.
Updated the daemon to use the new pidfile.

Signed-off-by: Rick Wieman <git@rickw.nl>
This commit is contained in:
Rick Wieman 2015-02-25 19:33:01 +01:00
parent 4341a8f231
commit c0c4f68893
2 changed files with 76 additions and 0 deletions

32
pidfile/pidfile_test.go Normal file
View file

@ -0,0 +1,32 @@
package pidfile
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")
}
file, err := New(filepath.Join(dir, "testfile"))
if err != nil {
t.Fatal("Could not create test file", err)
}
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")
}
}