Skip to content

Commit 29372c1

Browse files
committed
* rename car-scope to dag-scope
* add test for missing dag-scope parameter
1 parent a3437dd commit 29372c1

File tree

1 file changed

+42
-40
lines changed

1 file changed

+42
-40
lines changed

tests/t0118_gateway_car_test.go

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ func TestGatewayCar(t *testing.T) {
1212
fixture := car.MustOpenUnixfsCar("t0118-test-dag.car")
1313
hamtFixture := car.MustOpenUnixfsCar("t0118-ipip-402-scope.car")
1414

15+
dagScopeAllBuilder := Expect().
16+
Status(200).
17+
Body(
18+
IsCar().
19+
HasRoot(hamtFixture.MustGetCid()).
20+
HasBlocks(hamtFixture.MustGetCid()).
21+
HasBlocks(
22+
hamtFixture.MustGetCid("sub2"),
23+
hamtFixture.MustGetCid("sub2", "hello.txt"),
24+
).
25+
HasBlocks(hamtFixture.MustGetChildrenCids("sub2", "hello.txt")...).
26+
HasBlocks(
27+
hamtFixture.MustGetCid("sub1"),
28+
hamtFixture.MustGetCid("sub1", "hello.txt"),
29+
).
30+
HasBlocks(hamtFixture.MustGetChildrenCids("sub1", "hello.txt")...).
31+
Exactly().
32+
InThatOrder(),
33+
)
34+
1535
tests := SugarTests{
1636
{
1737
Name: "GET response for application/vnd.ipld.car",
@@ -57,15 +77,15 @@ func TestGatewayCar(t *testing.T) {
5777
),
5878
},
5979
{
60-
Name: "GET with ?format=car&car-scope=block params returns expected blocks",
80+
Name: "GET with ?format=car&dag-scope=block params returns expected blocks",
6181
Hint: `
62-
car-scope=block should return a CAR file with only the root block and a
82+
dag-scope=block should return a CAR file with only the root block and a
6383
block for each optional path component.
6484
`,
6585
Request: Request().
6686
Path("ipfs/{{cid}}/sub1/hello.txt", hamtFixture.MustGetCid()).
6787
Query("format", "car").
68-
Query("car-scope", "block"),
88+
Query("dag-scope", "block"),
6989
Response: Expect().
7090
Status(200).
7191
Body(
@@ -81,68 +101,50 @@ func TestGatewayCar(t *testing.T) {
81101
),
82102
},
83103
{
84-
Name: "GET with ?format=car&car-scope=file params returns expected blocks",
104+
Name: "GET with ?format=car&dag-scope=entity params returns expected blocks",
85105
Hint: `
86-
car-scope=file should return a CAR file with all the blocks needed to 'cat'
106+
dag-scope=entity should return a CAR file with all the blocks needed to 'cat'
87107
a UnixFS file at the end of the specified path, or to 'ls' a UnixFS directory
88108
at the end of the specified path.
89109
`,
90110
Request: Request().
91111
Path("ipfs/{{cid}}/sub1/hello.txt", hamtFixture.MustGetCid()).
92112
Query("format", "car").
93-
Query("car-scope", "file"),
113+
Query("dag-scope", "entity"),
94114
Response: Expect().
95115
Status(200).
96116
Body(
97117
IsCar().
98118
HasRoot(hamtFixture.MustGetCid()).
99119
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-
)...,
120+
hamtFixture.MustGetCid(),
121+
hamtFixture.MustGetCid("sub1"),
122+
hamtFixture.MustGetCid("sub1", "hello.txt"),
108123
).
124+
HasBlocks(hamtFixture.MustGetChildrenCids("sub1", "hello.txt")...).
109125
Exactly().
110126
InThatOrder(),
111127
),
112128
},
113129
{
114-
Name: "GET with ?format=car&car-scope=all params returns expected blocks",
130+
Name: "GET with ?format=car&dag-scope=all params returns expected blocks",
115131
Hint: `
116-
car-scope=all should return a CAR file with the entire contiguous DAG
132+
dag-scope=all should return a CAR file with the entire contiguous DAG
117133
that begins at the end of the path query, after blocks required to verify path segments.
118134
`,
119135
Request: Request().
120136
Path("ipfs/{{cid}}", hamtFixture.MustGetCid()).
121137
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-
),
138+
Query("dag-scope", "all"),
139+
Response: dagScopeAllBuilder,
140+
},
141+
{
142+
Name: "GET with ?format=car returns same response as dag-scope=all",
143+
Hint: `If the CAR request does not have a dag-scope parameter, it should be treated as dag-scope=all`,
144+
Request: Request().
145+
Path("ipfs/{{cid}}", hamtFixture.MustGetCid()).
146+
Query("format", "car"),
147+
Response: dagScopeAllBuilder,
146148
},
147149
}
148150

0 commit comments

Comments
 (0)