Skip to content

Commit

Permalink
allow tests to delegate choosing which ranges to query to the helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Sep 19, 2023
1 parent 74d7b32 commit 245795b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
44 changes: 9 additions & 35 deletions tests/path_gateway_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ func TestPlainCodec(t *testing.T) {
Contains(Fmt("application/{{format}}", row.Format)),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
nil,
plain.RawData(),
)...).
Append(
Expand All @@ -276,10 +273,7 @@ func TestPlainCodec(t *testing.T) {
Contains("application/{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
nil,
plain.RawData(),
)...).
Append(
Expand All @@ -302,10 +296,7 @@ func TestPlainCodec(t *testing.T) {
Contains("application/{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
nil,
plain.RawData(),
)...).
Append(
Expand Down Expand Up @@ -359,10 +350,7 @@ func TestPlainCodec(t *testing.T) {
Contains("application/vnd.ipld.dag-{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
nil,
dagFormattedResponse,
)
RunWithSpecs(t, rangeTests, specs.PathGatewayDAG)
Expand Down Expand Up @@ -642,11 +630,7 @@ func TestNativeDag(t *testing.T) {
Headers(
Header("Content-Type", "application/vnd.ipld.dag-{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
},
}, nil,
dagTraversal.RawData(),
)...).Append(
helpers.RangeTestTransform(t,
Expand All @@ -662,10 +646,7 @@ func TestNativeDag(t *testing.T) {
Header("Content-Type", "application/vnd.ipld.dag-{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
}, dagTraversal.RawData(),
nil, dagTraversal.RawData(),
)...).Append(
helpers.RangeTestTransform(t,
SugarTest{
Expand All @@ -680,10 +661,7 @@ func TestNativeDag(t *testing.T) {
Header("Content-Type", "application/{{format}}", row.Format),
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
},
nil,
dagTraversal.RawData(),
)...)

Expand Down Expand Up @@ -726,9 +704,7 @@ func TestNativeDag(t *testing.T) {
),
Response: Expect(),
},
helpers.ByteRanges{
helpers.SimpleByteRange(1, 5),
helpers.SimpleByteRange(93, 104)},
nil,
dagJsonConvertedData)

RunWithSpecs(t, rangeTests, specs.PathGatewayDAG)
Expand Down Expand Up @@ -766,9 +742,7 @@ func TestNativeDag(t *testing.T) {
Header("Accept", "text/html"),
),
Response: Expect(),
}, helpers.ByteRanges{
helpers.SimpleByteRange(1, 5),
helpers.SimpleByteRange(93, 104)},
}, nil,
dagCborHTMLRendering)

RunWithSpecs(t, rangeTests, specs.PathGatewayDAG)
Expand Down
5 changes: 1 addition & 4 deletions tests/trustless_gateway_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ func TestTrustlessRawRanges(t *testing.T) {
),
Response: Expect(),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(0, 4),
},
nil,
fixture.MustGetRawData("dir", "ascii.txt"))

RunWithSpecs(t, tests, specs.TrustlessGatewayRaw)
Expand Down
18 changes: 18 additions & 0 deletions tooling/helpers/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func MultiRangeTestTransform(t *testing.T, testWithoutRangeRequestHeader test.Su
// Will test the full request, a single range request for the first passed range as well as a multi-range request for
// all the requested ranges.
//
// If no ranges are passed then some non-overlapping ranges are automatically generated for data >= 10 bytes. Smaller
// data will result in undefined behavior.
//
// Note: HTTP Range requests can be validly responded with either the full data, or the requested partial data
// Note: HTTP Multi Range requests can be validly responded with one of the full data, the partial data from the first
// range, or the partial data from all the requested ranges
Expand All @@ -202,10 +205,25 @@ func BaseWithRangeTestTransform(t *testing.T, baseTest test.SugarTest, branges B
// Will test both a single range request for the first passed range as well as a multi-range request for all the
// requested ranges.
//
// If no ranges are passed then some non-overlapping ranges are automatically generated for data >= 10 bytes. Smaller
// data will result in undefined behavior.
//
// Note: HTTP Range requests can be validly responded with either the full data, or the requested partial data
// Note: HTTP Multi Range requests can be validly responded with one of the full data, the partial data from the first
// range, or the partial data from all the requested ranges
func RangeTestTransform(t *testing.T, baseTest test.SugarTest, branges ByteRanges, fullData []byte) test.SugarTests {
if len(branges) == 0 {
dataLen := len(fullData)
if dataLen < 10 {
panic("transformation not defined for data smaller than 10 bytes")
}

branges = ByteRanges{
SimpleByteRange(7, 9),
SimpleByteRange(1, 3),
}
}

singleBase := test.SugarTest{
Name: fmt.Sprintf("%s - single range", baseTest.Name),
Hint: baseTest.Hint,
Expand Down

0 comments on commit 245795b

Please sign in to comment.