From 74d7b32c2528751350c99fc6d93777168aa8e4af Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Tue, 19 Sep 2023 14:39:18 -0400 Subject: [PATCH] remove data from ByteRange helper --- tests/path_gateway_dag_test.go | 36 ++++++++++++++--------------- tests/trustless_gateway_raw_test.go | 6 ++--- tooling/helpers/range.go | 18 +++++++-------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/tests/path_gateway_dag_test.go b/tests/path_gateway_dag_test.go index efe408237..3edcb4d56 100644 --- a/tests/path_gateway_dag_test.go +++ b/tests/path_gateway_dag_test.go @@ -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(), )...). @@ -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(), )...). @@ -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(), )...). @@ -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, ) @@ -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( @@ -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, @@ -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(), )...) @@ -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) @@ -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) diff --git a/tests/trustless_gateway_raw_test.go b/tests/trustless_gateway_raw_test.go index c9fcfbd82..8580214bb 100644 --- a/tests/trustless_gateway_raw_test.go +++ b/tests/trustless_gateway_raw_test.go @@ -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) } diff --git a/tooling/helpers/range.go b/tooling/helpers/range.go index 610cd1e7c..165b8ec9e 100644 --- a/tooling/helpers/range.go +++ b/tooling/helpers/range.go @@ -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, } } @@ -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), @@ -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])), ) } @@ -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(