github.com/rumpl/bof@v23.0.0-rc.2+incompatible/pkg/pidfile/pidfile_test.go (about)

     1  package pidfile // import "github.com/docker/docker/pkg/pidfile"
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  )
     8  
     9  func TestNewAndRemove(t *testing.T) {
    10  	dir, err := os.MkdirTemp(os.TempDir(), "test-pidfile")
    11  	if err != nil {
    12  		t.Fatal("Could not create test directory")
    13  	}
    14  
    15  	path := filepath.Join(dir, "testfile")
    16  	file, err := New(path)
    17  	if err != nil {
    18  		t.Fatal("Could not create test file", err)
    19  	}
    20  
    21  	_, err = New(path)
    22  	if err == nil {
    23  		t.Fatal("Test file creation not blocked")
    24  	}
    25  
    26  	if err := file.Remove(); err != nil {
    27  		t.Fatal("Could not delete created test file")
    28  	}
    29  }
    30  
    31  func TestRemoveInvalidPath(t *testing.T) {
    32  	file := PIDFile{path: filepath.Join("foo", "bar")}
    33  
    34  	if err := file.Remove(); err == nil {
    35  		t.Fatal("Non-existing file doesn't give an error on delete")
    36  	}
    37  }