Skip to content

Commit

Permalink
remove data from ByteRange helper
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Sep 19, 2023
1 parent 54b0386 commit 74d7b32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
36 changes: 18 additions & 18 deletions tests/path_gateway_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ func TestPlainCodec(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5, plain.RawData()[0:6]),
helpers.SimpleByteRange(10, 15, plain.RawData()[10:16]),
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
plain.RawData(),
)...).
Expand All @@ -277,8 +277,8 @@ func TestPlainCodec(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5, plain.RawData()[0:6]),
helpers.SimpleByteRange(10, 15, plain.RawData()[10:16]),
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
plain.RawData(),
)...).
Expand All @@ -303,8 +303,8 @@ func TestPlainCodec(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5, plain.RawData()[0:6]),
helpers.SimpleByteRange(10, 15, plain.RawData()[10:16]),
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
plain.RawData(),
)...).
Expand Down Expand Up @@ -360,8 +360,8 @@ func TestPlainCodec(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(0, 5, dagFormattedResponse[0:6]),
helpers.SimpleByteRange(10, 15, dagFormattedResponse[10:16]),
helpers.SimpleByteRange(0, 5),
helpers.SimpleByteRange(10, 15),
},
dagFormattedResponse,
)
Expand Down Expand Up @@ -644,8 +644,8 @@ func TestNativeDag(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16, dagTraversal.RawData()[6:17]),
helpers.SimpleByteRange(20, 25, dagTraversal.RawData()[20:26]),
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
},
dagTraversal.RawData(),
)...).Append(
Expand All @@ -663,8 +663,8 @@ func TestNativeDag(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16, dagTraversal.RawData()[6:17]),
helpers.SimpleByteRange(20, 25, dagTraversal.RawData()[20:26]),
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
}, dagTraversal.RawData(),
)...).Append(
helpers.RangeTestTransform(t,
Expand All @@ -681,8 +681,8 @@ func TestNativeDag(t *testing.T) {
),
},
helpers.ByteRanges{
helpers.SimpleByteRange(6, 16, dagTraversal.RawData()[6:17]),
helpers.SimpleByteRange(20, 25, dagTraversal.RawData()[20:26]),
helpers.SimpleByteRange(6, 16),
helpers.SimpleByteRange(20, 25),
},
dagTraversal.RawData(),
)...)
Expand Down Expand Up @@ -727,8 +727,8 @@ func TestNativeDag(t *testing.T) {
Response: Expect(),
},
helpers.ByteRanges{
helpers.SimpleByteRange(1, 5, dagJsonConvertedData[1:6]),
helpers.SimpleByteRange(93, 104, dagJsonConvertedData[93:105])},
helpers.SimpleByteRange(1, 5),
helpers.SimpleByteRange(93, 104)},
dagJsonConvertedData)

RunWithSpecs(t, rangeTests, specs.PathGatewayDAG)
Expand Down Expand Up @@ -767,8 +767,8 @@ func TestNativeDag(t *testing.T) {
),
Response: Expect(),
}, helpers.ByteRanges{
helpers.SimpleByteRange(1, 5, dagCborHTMLRendering[1:6]),
helpers.SimpleByteRange(93, 104, dagCborHTMLRendering[93:105])},
helpers.SimpleByteRange(1, 5),
helpers.SimpleByteRange(93, 104)},
dagCborHTMLRendering)

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

RunWithSpecs(t, tests, specs.TrustlessGatewayRaw)
}
18 changes: 8 additions & 10 deletions tooling/helpers/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ import (
//
// [HTTP Byte Range]: https://httpwg.org/specs/rfc9110.html#rfc.section.14.1.2
type ByteRange struct {
From uint64
To *int64
RangeBytes []byte
From uint64
To *int64
}

func SimpleByteRange(from, to uint64, data []byte) ByteRange {
func SimpleByteRange(from, to uint64) ByteRange {
toInt := int64(to)
return ByteRange{
From: from,
To: &toInt,
RangeBytes: data,
From: from,
To: &toInt,
}
}

Expand Down Expand Up @@ -112,7 +110,7 @@ func SingleRangeTestTransform(t *testing.T, baseTest test.SugarTest, brange Byte
Response: test.AllOf(
modifiedResponse,
test.AnyOf(
test.Expect().Status(http.StatusPartialContent).Body(brange.RangeBytes).Headers(
test.Expect().Status(http.StatusPartialContent).Body(fullData[start:end+1]).Headers(
test.Header("Content-Range").Equals("bytes {{start}}-{{end}}/{{length}}", start, end, fullSize),
),
test.Expect().Status(http.StatusOK).Body(fullData),
Expand Down Expand Up @@ -147,7 +145,7 @@ func MultiRangeTestTransform(t *testing.T, testWithoutRangeRequestHeader test.Su
ranges = append(ranges, rng{start: start, end: end})
multirangeBodyChecks = append(multirangeBodyChecks,
check.Contains("Content-Range: bytes {{start}}-{{end}}/{{length}}", ranges[0].start, ranges[0].end, fullSize),
check.Contains(string(r.RangeBytes)),
check.Contains(string(fullData[start:end+1])),
)
}

Expand All @@ -160,7 +158,7 @@ func MultiRangeTestTransform(t *testing.T, testWithoutRangeRequestHeader test.Su
modifiedResponse,
test.AnyOf(
test.Expect().Status(http.StatusOK).Body(fullData),
test.Expect().Status(http.StatusPartialContent).Body(branges[0].RangeBytes).Headers(
test.Expect().Status(http.StatusPartialContent).Body(fullData[ranges[0].start:ranges[0].end+1]).Headers(
test.Header("Content-Range").Equals("bytes {{start}}-{{end}}/{{length}}", ranges[0].start, ranges[0].end, fullSize),
),
test.Expect().Status(http.StatusPartialContent).Body(
Expand Down

0 comments on commit 74d7b32

Please sign in to comment.