Skip to content

Commit

Permalink
refactor: explain what we test and why
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jan 24, 2024
1 parent 4bd19e7 commit 6a97c94
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/trustless_gateway_car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,10 @@ func TestTrustlessCarEntityBytes(t *testing.T) {
),
},
{
Name: "GET CAR with entity-bytes requesting a range from the end of a file",
Name: "GET CAR with entity-bytes requesting a range from the end of a file that is bigger than a file itself",
Hint: `
The response MUST contain only the minimal set of blocks necessary for fulfilling the range request
The response MUST contain only the minimal set of blocks necessary for fulfilling the range request,
and requests for part beyond the start of a file are silently ignored.
`,
Request: Request().
Path("/ipfs/{{cid}}", subdirWithMixedBlockFiles.MustGetCidWithCodec(0x70, "subdir", "multiblock.txt")).
Expand All @@ -633,15 +634,20 @@ func TestTrustlessCarEntityBytes(t *testing.T) {
IgnoreRoots().
HasBlocks(
flattenStrings(t,
subdirWithMixedBlockFiles.MustGetCid("subdir", "multiblock.txt"),
subdirWithMixedBlockFiles.MustGetDescendantsCids("subdir", "multiblock.txt")[:len(subdirWithMixedBlockFiles.MustGetDescendantsCids("subdir", "multiblock.txt"))-1])...,
).
subdirWithMixedBlockFiles.MustGetCid("subdir", "multiblock.txt"), // dag-pb root of the file DAG
"bafkreie5noke3mb7hqxukzcy73nl23k6lxszxi5w3dtmuwz62wnvkpsscm", // 256 chunk
"bafkreih4ephajybraj6wnxsbwjwa77fukurtpl7oj7t7pfq545duhot7cq", // 256
"bafkreigu7buvm3cfunb35766dn7tmqyh2um62zcio63en2btvxuybgcpue", // 256
"bafkreicll3huefkc3qnrzeony7zcfo7cr3nbx64hnxrqzsixpceg332fhe", // 256
// and we dont expect the last chunk at "bafkreifst3pqztuvj57lycamoi7z34b4emf7gawxs74nwrc2c7jncmpaqm"
// because it has size of 2 and we did -3 from the end, so this one should be skipped
)...).
Exactly().
InThatOrder(),
),
},
{
Name: "GET CAR with entity-bytes requesting the first byte of a file",
Name: "GET CAR with entity-bytes requesting only the blocks for the first byte of a file",
Hint: `
The response MUST contain only the first block of the file.
`,
Expand Down Expand Up @@ -835,6 +841,7 @@ func TestTrustlessCarOrderAndDuplicates(t *testing.T) {
RunWithSpecs(t, tests, specs.TrustlessGatewayCAROptional)
}

// TODO: this feels like it could be an internal detail of HasBlocks
func flattenStrings(t *testing.T, values ...interface{}) []string {
var res []string
for _, v := range values {
Expand Down

0 comments on commit 6a97c94

Please sign in to comment.