Skip to content

Commit c038078

Browse files
authored
release: v0.4.0
2 parents d7e8118 + cf94204 commit c038078

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## [0.4.0] - 2023-10-02
88
### Added
99
- 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)
1010

tooling/helpers/range.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func IncludeRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []strin
181181
// Note: HTTP Multi Range requests can be validly responded with one of the full data, the partial data from the first
182182
// range, or the partial data from all the requested ranges
183183
func IncludeRandomRangeTests(t *testing.T, baseTest test.SugarTest, fullData []byte, contentType string) test.SugarTests {
184-
return includeRangeTests(t, baseTest, nil, fullData, contentType)
184+
return includeRangeTests(t, baseTest, makeRandomByteRanges(fullData), fullData, contentType)
185185
}
186186

187187
func includeRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string, fullData []byte, contentType string) test.SugarTests {
@@ -238,22 +238,10 @@ func OnlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string,
238238
// Note: HTTP Multi Range requests can be validly responded with one of the full data, the partial data from the first
239239
// range, or the partial data from all the requested ranges
240240
func OnlyRandomRangeTests(t *testing.T, baseTest test.SugarTest, fullData []byte, contentType string) test.SugarTests {
241-
return onlyRangeTests(t, baseTest, nil, fullData, contentType)
241+
return onlyRangeTests(t, baseTest, makeRandomByteRanges(fullData), fullData, contentType)
242242
}
243243

244244
func onlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string, fullData []byte, contentType string) test.SugarTests {
245-
if len(byteRanges) == 0 {
246-
dataLen := len(fullData)
247-
if dataLen < 10 {
248-
panic("transformation not defined for data smaller than 10 bytes")
249-
}
250-
251-
byteRanges = []string{
252-
"bytes=7-9",
253-
"bytes=1-3",
254-
}
255-
}
256-
257245
singleBaseRequest := baseTest.Request.Clone()
258246
if contentType != "" {
259247
singleBaseRequest = singleBaseRequest.Header("Content-Type", contentType)
@@ -280,3 +268,15 @@ func onlyRangeTests(t *testing.T, baseTest test.SugarTest, byteRanges []string,
280268
multiRange := MultiRangeTestTransform(t, multiBase, byteRanges, fullData, contentType)
281269
return test.SugarTests{singleRange, multiRange}
282270
}
271+
272+
func makeRandomByteRanges(fullData []byte) []string {
273+
dataLen := len(fullData)
274+
if dataLen < 10 {
275+
panic("transformation not defined for data smaller than 10 bytes")
276+
}
277+
278+
return []string{
279+
"bytes=7-9",
280+
"bytes=1-3",
281+
}
282+
}

0 commit comments

Comments
 (0)