Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Waller <o.waller@kulawe.com>2014-09-19 01:58:44 +0400
committerspf13 <steve.francia@gmail.com>2014-11-05 03:18:54 +0300
commit980d0f14de885122ed47482dde01228f7158015d (patch)
tree9c2c87850222688d02c61e06cc8d57fcfecfc11d /helpers
parentbf07dc9293026d31534d5ce5eea7f31badcf95ef (diff)
WriteToDisk and SafeWriteToDisk test cleaned up
Minor cleanup to randomise the names of the temp directories used by the tests.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/path_test.go30
1 files changed, 9 insertions, 21 deletions
diff --git a/helpers/path_test.go b/helpers/path_test.go
index 3a31c27fb..6683d9eb5 100644
--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -4,8 +4,10 @@ import (
"fmt"
"io/ioutil"
"os"
+ "strconv"
"strings"
"testing"
+ "time"
)
func TestMakePath(t *testing.T) {
@@ -461,20 +463,22 @@ func TestSafeWriteToDisk(t *testing.T) {
defer deleteFileInTempDir(emptyFile)
tmpDir, _ := createEmptyTempDir()
defer deleteTempDir(tmpDir)
- os.MkdirAll(tmpDir+"/this/dir/does/not/exist/", 0644)
randomString := "This is a random string!"
reader := strings.NewReader(randomString)
fileExists := fmt.Errorf("%v already exists", emptyFile.Name())
+
type test struct {
filename string
expectedErr error
}
+ now := time.Now().Unix()
+ nowStr := strconv.FormatInt(now, 10)
data := []test{
{emptyFile.Name(), fileExists},
- {tmpDir + "/" + emptyFile.Name(), nil},
+ {tmpDir + "/" + nowStr, nil},
}
for i, d := range data {
@@ -510,35 +514,19 @@ func TestWriteToDisk(t *testing.T) {
expectedErr error
}
+ now := time.Now().Unix()
+ nowStr := strconv.FormatInt(now, 10)
data := []test{
{emptyFile.Name(), nil},
- {tmpDir + "/abcd", nil},
+ {tmpDir + "/" + nowStr, nil},
}
for i, d := range data {
- // fmt.Printf("Writing to: %s\n", d.filename)
- // dir, _ := filepath.Split(d.filename)
- // ospath := filepath.FromSlash(dir)
-
- // fmt.Printf("dir: %q, ospath: %q\n", dir, ospath)
e := WriteToDisk(d.filename, reader)
- // fmt.Printf("Error from WriteToDisk: %s\n", e)
- // f, e := os.Open(d.filename)
- // if e != nil {
- // fmt.Errorf("could not open file %s, error %s\n", d.filename, e)
- // }
- // fi, e := f.Stat()
- // if e != nil {
- // fmt.Errorf("Could not stat file %s, error %s\n", d.filename, e)
- // }
- // fmt.Printf("file size of %s is %d bytes\n", d.filename, fi.Size())
if d.expectedErr != e {
t.Errorf("Test %d failed. WriteToDisk Error Expected %q but got %q", i, d.expectedErr, e)
}
- // fmt.Printf("Reading from %s\n", d.filename)
contents, e := ioutil.ReadFile(d.filename)
- // fmt.Printf("Error from ReadFile: %s\n", e)
- // fmt.Printf("Contents: %#v, %s\n", contents, string(contents))
if e != nil {
t.Error("Test %d failed. Could not read file %s. Reason: %s\n", i, d.filename, e)
}