path_test.go 1016 B

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