github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/ethutil/path_test.go (about)

     1  package ethutil
     2  
     3  import (
     4  	// "os"
     5  	"testing"
     6  )
     7  
     8  func TestGoodFile(t *testing.T) {
     9  	goodpath := "~/goethereumtest.pass"
    10  	path := ExpandHomePath(goodpath)
    11  	contentstring := "3.14159265358979323846"
    12  
    13  	err := WriteFile(path, []byte(contentstring))
    14  	if err != nil {
    15  		t.Error("Could not write file")
    16  	}
    17  
    18  	if !FileExist(path) {
    19  		t.Error("File not found at", path)
    20  	}
    21  
    22  	v, err := ReadAllFile(path)
    23  	if err != nil {
    24  		t.Error("Could not read file", path)
    25  	}
    26  	if v != contentstring {
    27  		t.Error("Expected", contentstring, "Got", v)
    28  	}
    29  
    30  }
    31  
    32  func TestBadFile(t *testing.T) {
    33  	badpath := "/this/path/should/not/exist/goethereumtest.fail"
    34  	path := ExpandHomePath(badpath)
    35  	contentstring := "3.14159265358979323846"
    36  
    37  	err := WriteFile(path, []byte(contentstring))
    38  	if err == nil {
    39  		t.Error("Wrote file, but should not be able to", path)
    40  	}
    41  
    42  	if FileExist(path) {
    43  		t.Error("Found file, but should not be able to", path)
    44  	}
    45  
    46  	v, err := ReadAllFile(path)
    47  	if err == nil {
    48  		t.Error("Read file, but should not be able to", v)
    49  	}
    50  
    51  }