Skip to content

Commit

Permalink
fix: byte range panic
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Oct 2, 2023
1 parent d7e8118 commit cf30140
Showing 1 changed file with 14 additions and 14 deletions.
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",
}
}

0 comments on commit cf30140

Please sign in to comment.