shithub: hugo

Download patch

ref: 980d0f14de885122ed47482dde01228f7158015d
parent: bf07dc9293026d31534d5ce5eea7f31badcf95ef
author: Owen Waller <[email protected]>
date: Thu Sep 18 18:58:44 EDT 2014

WriteToDisk and SafeWriteToDisk test cleaned up

Minor cleanup to randomise the names of the temp directories used by the
tests.

--- a/helpers/path_test.go
+++ b/helpers/path_test.go
@@ -4,8 +4,10 @@
 	"fmt"
 	"io/ioutil"
 	"os"
+	"strconv"
 	"strings"
 	"testing"
+	"time"
 )
 
 func TestMakePath(t *testing.T) {
@@ -461,20 +463,22 @@
 	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 @@
 		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)
 		}