github.com/fibonacci1729/draft@v0.3.0/pkg/osutil/osutil_test.go (about)

     1  package osutil
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  func TestExists(t *testing.T) {
    10  	file, err := ioutil.TempFile("", "osutil")
    11  	if err != nil {
    12  		t.Fatal(err)
    13  	}
    14  
    15  	exists, err := Exists(file.Name())
    16  	if err != nil {
    17  		t.Errorf("expected no error when calling Exists() on a file that exists, got %v", err)
    18  	}
    19  	if !exists {
    20  		t.Error("expected tempfile to exist")
    21  	}
    22  	os.Remove(file.Name())
    23  	exists, err = Exists(file.Name())
    24  	if err != nil {
    25  		t.Errorf("expected no error when calling Exists() on a file that does not exist, got %v", err)
    26  	}
    27  	if exists {
    28  		t.Error("expected tempfile to NOT exist")
    29  	}
    30  }