Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: byte range panic #174

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions tooling/helpers/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func IncludeRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []strin
// 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 IncludeRandomRangeTests(t *testing.T, baseTest test.SugarTest, fullData []byte, contentType string) test.SugarTests {
return includeRangeTests(t, baseTest, nil, fullData, contentType)
return includeRangeTests(t, baseTest, makeRandomByteRanges(fullData), fullData, contentType)
}

func includeRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string, fullData []byte, contentType string) test.SugarTests {
Expand Down Expand Up @@ -238,22 +238,10 @@ func OnlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string,
// 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 OnlyRandomRangeTests(t *testing.T, baseTest test.SugarTest, fullData []byte, contentType string) test.SugarTests {
return onlyRangeTests(t, baseTest, nil, fullData, contentType)
return onlyRangeTests(t, baseTest, makeRandomByteRanges(fullData), fullData, contentType)
}

func onlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string, fullData []byte, contentType string) test.SugarTests {
if len(byteRanges) == 0 {
dataLen := len(fullData)
if dataLen < 10 {
panic("transformation not defined for data smaller than 10 bytes")
}

byteRanges = []string{
"bytes=7-9",
"bytes=1-3",
}
}

singleBaseRequest := baseTest.Request.Clone()
if contentType != "" {
singleBaseRequest = singleBaseRequest.Header("Content-Type", contentType)
Expand All @@ -280,3 +268,15 @@ func onlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string,
multiRange := MultiRangeTestTransform(t, multiBase, byteRanges, fullData, contentType)
return test.SugarTests{singleRange, multiRange}
}

func makeRandomByteRanges(fullData []byte) []string {
dataLen := len(fullData)
if dataLen < 10 {
panic("transformation not defined for data smaller than 10 bytes")
}

return []string{
"bytes=7-9",
"bytes=1-3",
}
}
Loading