Skip to content

Commit 8a37dea

Browse files
author
Kevin Neaton
committed
test: update gateway tests for dir-index-html v1.1.0
1 parent 5f74e23 commit 8a37dea

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

core/corehttp/gateway_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"net/http"
88
"net/http/httptest"
9+
"regexp"
910
"strings"
1011
"testing"
1112
"time"
@@ -154,6 +155,11 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface
154155
return ts, api, n.Context()
155156
}
156157

158+
func matchPathOrBreadcrumbs(s string, expected string) bool {
159+
matched, _ := regexp.MatchString("Index of\n[\t ]*"+regexp.QuoteMeta(expected), s)
160+
return matched
161+
}
162+
157163
func TestGatewayGet(t *testing.T) {
158164
ns := mockNamesys{}
159165
ts, api, ctx := newTestServerAndNode(t, ns)
@@ -442,7 +448,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
442448
s := string(body)
443449
t.Logf("body: %s\n", string(body))
444450

445-
if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/") {
451+
if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27\">foo? #&lt;&#39;</a>") {
446452
t.Fatalf("expected a path in directory listing")
447453
}
448454
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/./..\">") {
@@ -475,7 +481,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
475481
s = string(body)
476482
t.Logf("body: %s\n", string(body))
477483

478-
if !strings.Contains(s, "Index of /") {
484+
if !matchPathOrBreadcrumbs(s, "/") {
479485
t.Fatalf("expected a path in directory listing")
480486
}
481487
if !strings.Contains(s, "<a href=\"/\">") {
@@ -508,7 +514,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
508514
s = string(body)
509515
t.Logf("body: %s\n", string(body))
510516

511-
if !strings.Contains(s, "Index of /ipns/example.net/foo? #&lt;&#39;/bar/") {
517+
if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27\">foo? #&lt;&#39;</a>/<a href=\"/ipns/example.net/foo%3F%20%23%3C%27/bar\">bar</a>") {
512518
t.Fatalf("expected a path in directory listing")
513519
}
514520
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/./..\">") {
@@ -542,7 +548,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
542548
s = string(body)
543549
t.Logf("body: %s\n", string(body))
544550

545-
if !strings.Contains(s, "Index of /ipns/example.net") {
551+
if !matchPathOrBreadcrumbs(s, "/ipns/<a href=\"/ipns/example.net\">example.net</a>") {
546552
t.Fatalf("expected a path in directory listing")
547553
}
548554
if !strings.Contains(s, "<a href=\"/good-prefix/\">") {
@@ -584,7 +590,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
584590
s = string(body)
585591
t.Logf("body: %s\n", string(body))
586592

587-
if !strings.Contains(s, "Index of /") {
593+
if !matchPathOrBreadcrumbs(s, "/") {
588594
t.Fatalf("expected a path in directory listing")
589595
}
590596
if !strings.Contains(s, "<a href=\"/\">") {

test/sharness/t0111-gateway-writeable.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success "HTTP GET empty directory" '
6363
URL="http://127.0.0.1:$port/ipfs/$HASH_EMPTY_DIR/" &&
6464
echo "GET $URL" &&
6565
curl -so outfile "$URL" 2>curl_getEmpty.out &&
66-
grep "Index of /ipfs/$HASH_EMPTY_DIR/" outfile
66+
cat outfile | tr -s "\n" " " | grep "Index of /ipfs/<a href=\"/ipfs/$HASH_EMPTY_DIR\">$HASH_EMPTY_DIR</a>"
6767
'
6868

6969
test_expect_success "HTTP PUT file to construct a hierarchy" '

0 commit comments

Comments
 (0)