From 8a37deabf2176f8978157ac71c32a3593bebf718 Mon Sep 17 00:00:00 2001 From: Kevin Neaton Date: Sat, 25 Jul 2020 23:13:33 -0400 Subject: [PATCH] test: update gateway tests for dir-index-html v1.1.0 --- core/corehttp/gateway_test.go | 16 +++++++++++----- test/sharness/t0111-gateway-writeable.sh | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index a8a07aa48d3a..68991bc76897 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/http" "net/http/httptest" + "regexp" "strings" "testing" "time" @@ -154,6 +155,11 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface return ts, api, n.Context() } +func matchPathOrBreadcrumbs(s string, expected string) bool { + matched, _ := regexp.MatchString("Index of\n[\t ]*"+regexp.QuoteMeta(expected), s) + return matched +} + func TestGatewayGet(t *testing.T) { ns := mockNamesys{} ts, api, ctx := newTestServerAndNode(t, ns) @@ -442,7 +448,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s := string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/") { + if !matchPathOrBreadcrumbs(s, "/ipns/example.net/foo? #<'") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -475,7 +481,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /") { + if !matchPathOrBreadcrumbs(s, "/") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -508,7 +514,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/bar/") { + if !matchPathOrBreadcrumbs(s, "/ipns/example.net/foo? #<'/bar") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -542,7 +548,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /ipns/example.net") { + if !matchPathOrBreadcrumbs(s, "/ipns/example.net") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -584,7 +590,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /") { + if !matchPathOrBreadcrumbs(s, "/") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { diff --git a/test/sharness/t0111-gateway-writeable.sh b/test/sharness/t0111-gateway-writeable.sh index 6708b91a6dba..53d4fc1aa408 100755 --- a/test/sharness/t0111-gateway-writeable.sh +++ b/test/sharness/t0111-gateway-writeable.sh @@ -63,7 +63,7 @@ test_expect_success "HTTP GET empty directory" ' URL="http://127.0.0.1:$port/ipfs/$HASH_EMPTY_DIR/" && echo "GET $URL" && curl -so outfile "$URL" 2>curl_getEmpty.out && - grep "Index of /ipfs/$HASH_EMPTY_DIR/" outfile + cat outfile | tr -s "\n" " " | grep "Index of /ipfs/$HASH_EMPTY_DIR" ' test_expect_success "HTTP PUT file to construct a hierarchy" '