Skip to content

Commit

Permalink
release: v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta authored Oct 2, 2023
2 parents d7e8118 + cf94204 commit c038078
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [0.4.0] - 2023-10-02
### Added
- Added tests for HTTP Range requests, as well as some basic helpers for `AnyOf` and `AllOf`. [PR](https://github.com/ipfs/gateway-conformance/pull/162)

Expand Down
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 c038078

Please sign in to comment.