Skip to content

Commit

Permalink
refactor: apply @lidel suggestion A
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Sep 25, 2023
1 parent 08f2f1e commit d8c1f49
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 102 deletions.
30 changes: 12 additions & 18 deletions tests/path_gateway_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestPlainCodec(t *testing.T) {

tests := &SugarTests{}
tests.Append(
helpers.IncludeRangeTests(t,
helpers.IncludeRandomRangeTests(t,
SugarTest{
Name: Fmt(`GET {{name}} without Accept or format= has expected "{{format}}" Content-Type and body as-is`, row.Name, row.Format),
Hint: `
Expand All @@ -250,12 +250,11 @@ func TestPlainCodec(t *testing.T) {
Contains(Fmt(`{{disposition}}; filename="{{cid}}.{{format}}"`, row.Disposition, plainCID, row.Format)),
),
},
nil,
plain.RawData(),
Fmt("application/{{format}}", row.Format),
)...).
Append(
helpers.IncludeRangeTests(t,
helpers.IncludeRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} with ?format= has expected {{format}} Content-Type and body as-is", row.Name, row.Format),
Hint: `
Expand All @@ -270,12 +269,11 @@ func TestPlainCodec(t *testing.T) {
Contains(`{{disposition}}; filename="{{cid}}.{{format}}"`, row.Disposition, plainCID, row.Format),
),
},
nil,
plain.RawData(),
Fmt("application/{{format}}", row.Format),
)...).
Append(
helpers.IncludeRangeTests(t,
helpers.IncludeRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} with Accept has expected {{format}} Content-Type and body as-is, with single range request", row.Name, row.Format),
Hint: `
Expand All @@ -292,7 +290,6 @@ func TestPlainCodec(t *testing.T) {
Contains(`{{disposition}}; filename="{{cid}}.{{format}}"`, row.Disposition, plainCID, row.Format),
),
},
nil,
plain.RawData(),
Fmt("application/{{format}}", row.Format),
)...).
Expand Down Expand Up @@ -329,7 +326,7 @@ func TestPlainCodec(t *testing.T) {
RunWithSpecs(t, *tests, specs.PathGatewayDAG)

if dagFormattedResponse != nil {
rangeTests := helpers.RangeTestTransform(t,
rangeTests := helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} with format=dag-{{format}} interprets {{format}} as dag-* variant and produces expected Content-Type and body, with single range request", row.Name, row.Format),
Hint: `
Expand All @@ -345,7 +342,6 @@ func TestPlainCodec(t *testing.T) {
Contains(`{{disposition}}; filename="{{cid}}.{{format}}"`, row.Disposition, plainOrDagCID, row.Format),
),
},
nil,
dagFormattedResponse,
Fmt("application/vnd.ipld.dag-{{format}}", row.Format),
)
Expand Down Expand Up @@ -617,16 +613,16 @@ func TestNativeDag(t *testing.T) {
),
},
}
tests.Append(helpers.RangeTestTransform(t,
tests.Append(helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} on /ipfs with no explicit header", row.Name),
Request: Request().
Path("/ipfs/{{cid}}/", dagTraversalCID),
Response: Expect(),
}, nil,
},
dagTraversal.RawData(), Fmt("application/vnd.ipld.dag-{{format}}", row.Format),
)...).Append(
helpers.RangeTestTransform(t,
helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} on /ipfs with dag content headers", row.Name),
Request: Request().
Expand All @@ -636,10 +632,10 @@ func TestNativeDag(t *testing.T) {
),
Response: Expect(),
},
nil, dagTraversal.RawData(),
dagTraversal.RawData(),
Fmt("application/vnd.ipld.dag-{{format}}", row.Format),
)...).Append(
helpers.RangeTestTransform(t,
helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: Fmt("GET {{name}} on /ipfs with non-dag content headers", row.Name),
Request: Request().
Expand All @@ -649,7 +645,6 @@ func TestNativeDag(t *testing.T) {
),
Response: Expect(),
},
nil,
dagTraversal.RawData(),
Fmt("application/{{format}}", row.Format),
)...)
Expand Down Expand Up @@ -681,7 +676,7 @@ func TestNativeDag(t *testing.T) {
}, specs.PathGatewayDAG)

if dagJsonConvertedData != nil {
rangeTests := helpers.RangeTestTransform(
rangeTests := helpers.OnlyRandomRangeTests(
t,
SugarTest{
Name: "Convert application/vnd.ipld.dag-cbor to application/vnd.ipld.dag-json with range request includes correct bytes",
Expand All @@ -693,7 +688,6 @@ func TestNativeDag(t *testing.T) {
),
Response: Expect(),
},
nil,
dagJsonConvertedData,
"application/vnd.ipld.dag-json")

Expand Down Expand Up @@ -722,7 +716,7 @@ func TestNativeDag(t *testing.T) {
}, specs.PathGatewayDAG)

if dagCborHTMLRendering != nil {
rangeTests := helpers.RangeTestTransform(t,
rangeTests := helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: "Convert application/vnd.ipld.dag-cbor to text/html with range request includes correct bytes",
Hint: "",
Expand All @@ -732,7 +726,7 @@ func TestNativeDag(t *testing.T) {
Header("Accept", "text/html"),
),
Response: Expect(),
}, nil,
},
dagCborHTMLRendering,
"text/html")

Expand Down
6 changes: 3 additions & 3 deletions tests/trustless_gateway_raw_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package tests

import (
"github.com/ipfs/gateway-conformance/tooling/helpers"
"strconv"
"strings"
"testing"

"github.com/ipfs/gateway-conformance/tooling/helpers"

"github.com/ipfs/gateway-conformance/tooling"
"github.com/ipfs/gateway-conformance/tooling/car"
"github.com/ipfs/gateway-conformance/tooling/specs"
Expand Down Expand Up @@ -140,7 +141,7 @@ func TestTrustlessRawRanges(t *testing.T) {
// correctly.
fixture := car.MustOpenUnixfsCar("gateway-raw-block.car")

tests := helpers.RangeTestTransform(t,
tests := helpers.OnlyRandomRangeTests(t,
SugarTest{
Name: "GET with application/vnd.ipld.raw with range request includes correct bytes",
Request: Request().
Expand All @@ -150,7 +151,6 @@ func TestTrustlessRawRanges(t *testing.T) {
),
Response: Expect(),
},
nil,
fixture.MustGetRawData("dir", "ascii.txt"),
"application/vnd.ipld.raw",
)
Expand Down
Loading

0 comments on commit d8c1f49

Please sign in to comment.