-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: implement car check API #43
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hey, here's the potential API we discussed package tests
import (
"testing"
"github.com/ipfs/gateway-conformance/tooling/car"
. "github.com/ipfs/gateway-conformance/tooling/test"
)
func TestGatewayCar(t *testing.T) {
fixture := car.MustOpenUnixfsCar("t0118-test-dag.car")
tests := SugarTests{
{
Name: "GET response for application/vnd.ipld.car",
Hint: `
CAR stream is not deterministic, as blocks can arrive in random order,
but if we have a small file that fits into a single block, and export its CID
we will get a CAR that is a deterministic array of bytes.
`,
Request: Request().
Path("ipfs/%s/subdir/ascii.txt", fixture.MustGetCid()).
Headers(
Header("Accept", "application/vnd.ipld.car"),
),
Response: Expect().
Status(200).
Headers(
Header("Content-Type").
Hint("Expected content type to be application/vnd.ipld.car").
Contains("application/vnd.ipld.car"),
Header("Content-Length").
Hint("CAR is streamed, gateway may not have the entire thing, unable to calculate total size").
IsEmpty(),
Header("Content-Disposition").
Hint("Expected content disposition to be attachment; filename=\"<cid>.car\"").
Contains("attachment; filename=\"%s.car\"", fixture.MustGetCid("subdir", "ascii.txt")),
Header("X-Content-Type-Options").
Hint("CAR is streamed, gateway may not have the entire thing, unable to calculate total size").
Equals("nosniff"),
Header("Accept-Ranges").
Hint("CAR is streamed, gateway may not have the entire thing, unable to support range-requests. Partial downloads and resumes should be handled using IPLD selectors: https://github.com/ipfs/go-ipfs/issues/8769").
Equals("none"),
),
},
{
Name: "GET with ?format=car&car-scope=block params returns expected blocks",
Hint: `
car-scope=block should return a CAR file with only the root block and a
block for each optional path component.
`,
Request: Request().
Path("ipfs/%s/subdir/ascii.txt", fixture.MustGetCid()).
Query("format", "car").
Query("car-scope", "block"),
Response: Expect().
Status(200).
// TODO: Check if CAR response contains blocks for: root cid, subdir, ascii.txt
Body(
IsCar().
HasOnlyRoots(fixture.MustGetCid()).
HasOnlyBlocks([
fixture.MustGetCid(),
fixture.GetCidForPath("subdir"),
fixture.GetCidForPath("ascii.txt")
])
),
},
{
Name: "GET with ?format=car&car-scope=block params returns expected blocks",
Hint: `
car-scope=block should return a CAR file with only the root block and a
block for each optional path component.
`,
Request: Request().
Path("ipfs/%s/subdir/ascii.txt", fixture.MustGetCid()).
Query("format", "car").
Query("car-scope", "file"),
Response: Expect().
Status(200).
// TODO: Check if CAR response contains blocks for: root cid, subdir, ascii.txt
Body(
IsCar().
HasOnlyRoots(fixture.MustGetCid()).
HasOnlyBlocks([
fixture.MustGetCid(),
fixture.GetCidForPath("subdir"),
...fixture.GetAllCidsForNode("ascii.txt")
])),
},
{
Name: "GET with ?format=car&car-scope=block params returns expected blocks",
Hint: `
car-scope=block should return a CAR file with only the root block and a
block for each optional path component.
`,
Request: Request().
Path("ipfs/%s/subdir/ascii.txt", fixture.MustGetCid()).
Query("format", "car").
Query("car-scope", "all"),
Response: Expect().
Status(200).
// TODO: Check if CAR response contains blocks for: root cid, subdir, ascii.txt
Body(
IsCar().
HasOnlyRoots(fixture.MustGetCid()).
HasOnlyBlocks([
fixture.MustGetCid(),
fixture.GetCidForPath("subdir"),
...fixture.GetAllCidsForNode("ascii.txt")
])),
},
}
Run(t, tests)
} |
laurentsenta
force-pushed
the
feat/car-check
branch
from
May 4, 2023 15:01
d538597
to
6c11770
Compare
Thanks for sharing the code @guanzo, could you try the API in this branch? See the PR description for the full API, small differences with what we discussed:
|
galargh
approved these changes
May 8, 2023
galargh
approved these changes
May 8, 2023
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tooling to test trustless gateway - ipfs/specs#402
fixture.GetCidForPath
=>fixture.MustGetCID("subdir", "ascii,txt")
fixture.GetAllCidsForNode
=>fixture.MustGetChildrenCids("subdir")
In order to traverse a fixture:
Which means that the check for "my car should have the blocks for dir, subdir, and all the children of subdir" would look like: