Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Mar 14, 2017
1 parent 5ae9d79 commit 83e2291
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 0 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ func TestCreateAndRemovePidFile(t *testing.T) {
t.Errorf("pid file should be created but, %s", err)
}

if runtime.GOOS != "windows" {
if err := pidfile.Create(fpath); err == nil || !strings.HasPrefix(err.Error(), "pidfile found, try stopping another running mackerel-agent or delete") {
t.Errorf("creating pid file should be failed when the running process exists, %s", err)
}
}

pidfile.Remove(fpath)
if err := pidfile.Create(fpath); err != nil {
t.Errorf("pid file should be created but, %s", err)
Expand Down
10 changes: 10 additions & 0 deletions pidfile/pidfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package pidfile

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -31,7 +32,16 @@ func TestCreate(t *testing.T) {
if pid != os.Getpid() {
t.Errorf("contents of pidfile does not match pid. content: %d, pid: %d", pid, os.Getpid())
}
}

func TestCreate_mutex(t *testing.T) {
dir, err := ioutil.TempDir("", "")
if err != nil {
t.Fatalf("failed to create tempdir")
}
defer os.RemoveAll(dir)
pidfile := filepath.Join(dir, "pidfile")
ioutil.WriteFile(pidfile, []byte(fmt.Sprintf("%d", os.Getppid())), 0644)
err = Create(pidfile)
if err == nil {
t.Errorf("Successfully overwriting the pidfile unintentionally")
Expand Down

0 comments on commit 83e2291

Please sign in to comment.