From 776abdc35bbb7d0d30279063ba3d6d8b8eb4cd4d Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Sat, 29 Jun 2019 11:05:31 +0200 Subject: [PATCH] review tests --- Makefile | 12 +++++------- src/gossa.go | 6 ++---- src/gossa_test.go | 30 +++++++++++++++--------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index a2853a1..a337574 100755 --- a/Makefile +++ b/Makefile @@ -9,19 +9,17 @@ run: make build ./gossa test-fixture -watch: - ls src/** | entr -rc make run - -# ci & ci debug ci: timeout 10 make run & cp src/gossa_test.go . && sleep 5 && go test rm gossa_test.go -ci-watch: - ls src/* | entr -rc make ci +watch: + ls src/* gossa-ui/* | entr -rc make run + +ci-watch: + ls src/* gossa-ui/* | entr -rc make ci -# build / cleanup build-all: cp src/gossa.go gossa.go make -C gossa-ui/ diff --git a/src/gossa.go b/src/gossa.go index 308046a..568dfed 100755 --- a/src/gossa.go +++ b/src/gossa.go @@ -22,7 +22,7 @@ var host = flag.String("h", "127.0.0.1", "host to listen to") var port = flag.String("p", "8001", "port to listen to") var verb = flag.Bool("verb", true, "verbosity") var skipHidden = flag.Bool("k", true, "skip hidden files") -var initPath = "" +var initPath = "." var fs http.Handler var page, _ = template.New("pageTemplate").Parse(`template_will_be_here`) @@ -184,9 +184,7 @@ func checkPath(p string) (string, error) { func main() { flag.Parse() - if len(flag.Args()) == 0 { - initPath = "." - } else { + if len(flag.Args()) > 0 { initPath = flag.Args()[0] } diff --git a/src/gossa_test.go b/src/gossa_test.go index 760e83a..0182fbd 100644 --- a/src/gossa_test.go +++ b/src/gossa_test.go @@ -53,7 +53,7 @@ func postJSON(t *testing.T, url string, what string) string { return trimSpaces(string(body)) } -func testDefaults(t *testing.T, url string) string { +func fetchAndTestDefault(t *testing.T, url string) string { bodyStr := get(t, url) if !strings.Contains(bodyStr, `/`) { @@ -76,7 +76,7 @@ func testDefaults(t *testing.T, url string) string { t.Fatal("error 中文 folder") } - if !strings.Contains(bodyStr, ` 211.0B
custom_mime_type.types `) { + if !strings.Contains(bodyStr, `href="custom_mime_type.types">custom_mime_type.types`) { t.Fatal("error row custom_mime_type") } @@ -90,12 +90,12 @@ func TestGetFolder(t *testing.T) { // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching default path") - testDefaults(t, "http://127.0.0.1:8001/") + fetchAndTestDefault(t, "http://127.0.0.1:8001/") // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching an invalid path - redirected to root") - testDefaults(t, "http://127.0.0.1:8001/../../") - testDefaults(t, "http://127.0.0.1:8001/hols/../../") + fetchAndTestDefault(t, "http://127.0.0.1:8001/../../") + fetchAndTestDefault(t, "http://127.0.0.1:8001/hols/../../") // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching a regular file") @@ -118,8 +118,8 @@ func TestGetFolder(t *testing.T) { t.Fatal("mkdir rpc errored") } - bodyStr = testDefaults(t, "http://127.0.0.1:8001/") - if !strings.Contains(bodyStr, `
AAA/ `) { + bodyStr = fetchAndTestDefault(t, "http://127.0.0.1:8001/") + if !strings.Contains(bodyStr, `href="AAA">AAA/`) { t.Fatal("mkdir rpc folder not created") } @@ -137,9 +137,9 @@ func TestGetFolder(t *testing.T) { // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test post file") - path = "%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1" // "하 하" encoded - payload = "12 하" - bodyStr = postDummyFile(t, "%2F"+path, payload) + path = "%2F%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1" // "하 하" encoded + payload = "123 하" + bodyStr = postDummyFile(t, path, payload) if !strings.Contains(bodyStr, `ok`) { t.Fatal("post file errored") } @@ -149,14 +149,14 @@ func TestGetFolder(t *testing.T) { t.Fatal("post file errored reaching new file") } - bodyStr = testDefaults(t, "http://127.0.0.1:8001/") - if !strings.Contains(bodyStr, ` 9.0B
하 하 `) { + bodyStr = fetchAndTestDefault(t, "http://127.0.0.1:8001/") + if !strings.Contains(bodyStr, `href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">하 하`) { t.Fatal("post file errored checking new file row") } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test post file incorrect path") - bodyStr = postDummyFile(t, "%2E%2E%2F"+path, payload) + bodyStr = postDummyFile(t, "%2E%2E"+path, payload) if !strings.Contains(bodyStr, `err`) { t.Fatal("post file incorrect path didnt errored") } @@ -168,8 +168,8 @@ func TestGetFolder(t *testing.T) { t.Fatal("mv rpc errored") } - bodyStr = testDefaults(t, "http://127.0.0.1:8001/") - if strings.Contains(bodyStr, ` AAA/ `) { + bodyStr = fetchAndTestDefault(t, "http://127.0.0.1:8001/") + if strings.Contains(bodyStr, `href="AAA">AAA/ `) { t.Fatal("mv rpc folder not moved") }