Skip to content

Commit

Permalink
wip: show alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Mar 14, 2023
1 parent e5fdb82 commit 66ca0ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
43 changes: 38 additions & 5 deletions tests/t0114_gateway_subdomains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func TestGatewaySubdomains(t *testing.T) {
)...)

tests = append(tests, []CTest{
// TODO: this works only because we use example.com in our tests.
// It should be:
// Contains("%s://%s.ipfs.%s", SubdomainGatewayScheme, CIDv1, SubdomainGatewayHost)
// I am trying to avoid this syntax.
// The other option is to force the tested gateway to use example.com.
// Version 1 (default the test writer & runner to use example.com)
{

Name: "request for {gateway}/ipfs/{CIDv1} returns HTTP 301 Moved Permanently (sugar)",
Expand All @@ -66,15 +72,42 @@ func TestGatewaySubdomains(t *testing.T) {
Status(301).
Headers(
Header("Location").
// TODO: this works only because we use example.com in our tests.
// It should be:
// Contains("%s://%s.ipfs.%s", SubdomainGatewayScheme, CIDv1, SubdomainGatewayHost)
// I am trying to avoid this syntax.
// The other option is to force the tested gateway to use example.com.
Contains("http://%s.ipfs.example.com", CIDv1),
).
Response(),
},
// Version 2 (no default)
{

Name: "request for {gateway}/ipfs/{CIDv1} returns HTTP 301 Moved Permanently (sugar)",
Request: Request().
URL("%s/ipfs/%s", SubdomainGatewayUrl, CIDv1).
DoNotFollowRedirects().
Request(),
Response: Expect().
Status(301).
Headers(
Header("Location").
Contains("%s://%s.ipfs.%s", SubdomainGatewayScheme, CIDv1, SubdomainGatewayHost),
).
Response(),
},
// Version 3 (rewrite example.com and provide transformation functions when needed)
{

Name: "request for {gateway}/ipfs/{CIDv1} returns HTTP 301 Moved Permanently (sugar)",
Request: Request().
URL("http://example.com/ipfs/%s", CIDv1).
DoNotFollowRedirects().
Request(),
Response: Expect().
Status(301).
Headers(
Header("Location").
Contains(ReplaceExampleDomain("http://%s.ipfs.example.com", CIDv1)),
).
Response(),
},
{
Name: "request for {cid}.ipfs.localhost/api returns data if present on the content root (sugar)",
Request: Request().
Expand Down
4 changes: 4 additions & 0 deletions tooling/test/sugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestURLFromSpecURL(testURL string) string {
return u.String()
}

func ReplaceExampleDomain(s string, args ...any) string {
return TestURLFromSpecURL(fmt.Sprintf(s, args...))
}

type RequestBuilder struct {
Method_ string
Path_ string
Expand Down

0 comments on commit 66ca0ba

Please sign in to comment.