@@ -10,6 +10,7 @@ import (
1010
1111func TestGatewayCar (t * testing.T ) {
1212 fixture := car .MustOpenUnixfsCar ("t0118-test-dag.car" )
13+ hamtFixture := car .MustOpenUnixfsCar ("t0118-ipip-402-scope.car" )
1314
1415 tests := SugarTests {
1516 {
@@ -42,13 +43,106 @@ func TestGatewayCar(t *testing.T) {
4243 Header ("Accept-Ranges" ).
4344 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" ).
4445 Equals ("none" ),
45- ).Body (
46- IsCar ().
47- HasRoot (fixture .MustGetCid ("subdir" , "ascii.txt" )).
48- HasBlock (fixture .MustGetCid ("subdir" , "ascii.txt" )).
46+ ).
47+ Body (
48+ IsCar ().
49+ HasRoot (fixture .MustGetCid ()).
50+ HasBlocks (
51+ fixture .MustGetCid (),
52+ fixture .MustGetCid ("subdir" ),
53+ fixture .MustGetCid ("subdir" , "ascii.txt" ),
54+ ).
4955 Exactly ().
5056 InThatOrder (),
51- ),
57+ ),
58+ },
59+ {
60+ Name : "GET with ?format=car&car-scope=block params returns expected blocks" ,
61+ Hint : `
62+ car-scope=block should return a CAR file with only the root block and a
63+ block for each optional path component.
64+ ` ,
65+ Request : Request ().
66+ Path ("ipfs/{{cid}}/sub1/hello.txt" , hamtFixture .MustGetCid ()).
67+ Query ("format" , "car" ).
68+ Query ("car-scope" , "block" ),
69+ Response : Expect ().
70+ Status (200 ).
71+ Body (
72+ IsCar ().
73+ HasRoot (hamtFixture .MustGetCid ()).
74+ HasBlocks (
75+ hamtFixture .MustGetCid (),
76+ hamtFixture .MustGetCid ("sub1" ),
77+ hamtFixture .MustGetCid ("sub1" , "hello.txt" ),
78+ ).
79+ Exactly ().
80+ InThatOrder (),
81+ ),
82+ },
83+ {
84+ Name : "GET with ?format=car&car-scope=file params returns expected blocks" ,
85+ Hint : `
86+ car-scope=file should return a CAR file with all the blocks needed to 'cat'
87+ a UnixFS file at the end of the specified path, or to 'ls' a UnixFS directory
88+ at the end of the specified path.
89+ ` ,
90+ Request : Request ().
91+ Path ("ipfs/{{cid}}/sub1/hello.txt" , hamtFixture .MustGetCid ()).
92+ Query ("format" , "car" ).
93+ Query ("car-scope" , "file" ),
94+ Response : Expect ().
95+ Status (200 ).
96+ Body (
97+ IsCar ().
98+ HasRoot (hamtFixture .MustGetCid ()).
99+ HasBlocks (
100+ append (
101+ []string {
102+ hamtFixture .MustGetCid (),
103+ hamtFixture .MustGetCid ("sub1" ),
104+ hamtFixture .MustGetCid ("sub1" , "hello.txt" ),
105+ },
106+ hamtFixture .MustGetChildrenCids ("sub1" , "hello.txt" )... ,
107+ )... ,
108+ ).
109+ Exactly ().
110+ InThatOrder (),
111+ ),
112+ },
113+ {
114+ Name : "GET with ?format=car&car-scope=all params returns expected blocks" ,
115+ Hint : `
116+ car-scope=all should return a CAR file with the entire contiguous DAG
117+ that begins at the end of the path query, after blocks required to verify path segments.
118+ ` ,
119+ Request : Request ().
120+ Path ("ipfs/{{cid}}" , hamtFixture .MustGetCid ()).
121+ Query ("format" , "car" ).
122+ Query ("car-scope" , "all" ),
123+ Response : Expect ().
124+ Status (200 ).
125+ Body (
126+ IsCar ().
127+ HasRoot (hamtFixture .MustGetCid ()).
128+ HasBlocks (
129+ append (
130+ []string {
131+ hamtFixture .MustGetCid (),
132+ hamtFixture .MustGetCid ("sub1" ),
133+ hamtFixture .MustGetCid ("sub1" , "hello.txt" ),
134+ hamtFixture .MustGetCid ("sub2" ),
135+ hamtFixture .MustGetCid ("sub2" , "hello.txt" ),
136+ },
137+ append (
138+ hamtFixture .MustGetChildrenCids ("sub1" , "hello.txt" ),
139+ hamtFixture .MustGetChildrenCids ("sub2" , "hello.txt" )...
140+ )...
141+ )... ,
142+ ).
143+ Exactly ().
144+ InThatOrder (),
145+ ),
52146 },
53147 }
54148
0 commit comments