@@ -22,57 +22,65 @@ test_expect_success "Add the test directory" '
22
22
echo "$FILE_CID / $FILE_SIZE"
23
23
'
24
24
25
- test_codec_unixfs () {
25
+ test_headers () {
26
26
name=$1
27
27
format=$2
28
28
29
- test_expect_success " GET UnixFS $name with format=dag-$format has expected Content-Type" '
29
+ test_expect_success " GET $name with format=dag-$format has expected Content-Type" '
30
30
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 &&
31
31
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output &&
32
32
test_should_not_contain "Content-Type: application/$format" curl_output
33
33
'
34
34
35
- test_expect_success " GET UnixFS $name with 'Accept: application/vnd.ipld.dag-$format ' has expected Content-Type" '
35
+ test_expect_success " GET $name with 'Accept: application/vnd.ipld.dag-$format ' has expected Content-Type" '
36
36
curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 &&
37
37
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output &&
38
38
test_should_not_contain "Content-Type: application/$format" curl_output
39
39
'
40
40
41
- test_expect_success " GET UnixFS $name with format=$format has expected Content-Type" '
41
+ test_expect_success " GET $name with format=$format has expected Content-Type" '
42
42
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 &&
43
43
test_should_contain "Content-Type: application/$format" curl_output &&
44
44
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output
45
45
'
46
46
47
- test_expect_success " GET UnixFS $name with 'Accept: application/$format ' has expected Content-Type" '
47
+ test_expect_success " GET $name with 'Accept: application/$format ' has expected Content-Type" '
48
48
curl -sD - -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 &&
49
49
test_should_contain "Content-Type: application/$format" curl_output &&
50
50
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output
51
51
'
52
+ }
53
+
54
+ test_headers " DAG-JSON" " json"
55
+ test_headers " DAG-CBOR" " cbor"
52
56
53
- test_expect_success " GET UnixFS $name has expected output for file" '
57
+ test_dag_pb () {
58
+ name=$1
59
+ format=$2
60
+
61
+ test_expect_success " GET DAG-PB $name has expected output for file" '
54
62
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 &&
55
63
ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 &&
56
64
test_cmp ipfs_dag_get_output curl_output
57
65
'
58
66
59
- test_expect_success " GET UnixFS $name has expected output for directory" '
67
+ test_expect_success " GET DAG-PB $name has expected output for directory" '
60
68
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 &&
61
69
ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 &&
62
70
test_cmp ipfs_dag_get_output curl_output
63
71
'
64
72
65
- test_expect_success " GET UnixFS $name with format=dag-$format and format=$format produce same output" '
73
+ test_expect_success " GET DAG-PB $name with format=dag-$format and format=$format produce same output" '
66
74
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output_1 2>&1 &&
67
75
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=$format" > curl_output_2 2>&1 &&
68
76
test_cmp curl_output_1 curl_output_2
69
77
'
70
78
}
71
79
72
- test_codec_unixfs " DAG-JSON" " json"
73
- test_codec_unixfs " DAG-CBOR" " cbor"
80
+ test_dag_pb " DAG-JSON" " json"
81
+ test_dag_pb " DAG-CBOR" " cbor"
74
82
75
- test_codec () {
83
+ test_cmp_dag_get () {
76
84
name=$1
77
85
format=$2
78
86
@@ -91,8 +99,8 @@ test_codec () {
91
99
'
92
100
}
93
101
94
- test_codec " JSON" " json"
95
- test_codec " CBOR" " cbor"
102
+ test_cmp_dag_get " JSON" " json"
103
+ test_cmp_dag_get " CBOR" " cbor"
96
104
97
105
test_expect_success " GET JSON as CBOR produces DAG-CBOR output" '
98
106
CID=$(echo "{ \"test\": \"json\" }" | ipfs dag put --input-codec json --store-codec json) &&
@@ -108,6 +116,39 @@ test_expect_success "GET CBOR as JSON produces DAG-JSON output" '
108
116
test_cmp ipfs_dag_get_output curl_output
109
117
'
110
118
119
+ DAG_CBOR_TRAVERSAL_CID=" bafyreiehxu373cu3v5gyxyxfsfjryscs7sq6fh3unqcqgqhdfn3n43vrgu"
120
+ DAG_JSON_TRAVERSAL_CID=" baguqeeraoaeabj5hdfcmpkzfeiwtfwb3qbvfwzbiknqn7itcwsb2fdtu7eta"
121
+ DAG_PB_CID=" bafybeiegxwlgmoh2cny7qlolykdf7aq7g6dlommarldrbm7c4hbckhfcke"
122
+
123
+ test_expect_success " Add CARs for path traversal and DAG-PB representation tests" '
124
+ ipfs dag import ../t0123-gateway-json-cbor/dag-cbor-traversal.car > import_output &&
125
+ test_should_contain $DAG_CBOR_TRAVERSAL_CID import_output &&
126
+ ipfs dag import ../t0123-gateway-json-cbor/dag-json-traversal.car > import_output &&
127
+ test_should_contain $DAG_JSON_TRAVERSAL_CID import_output &&
128
+ ipfs dag import ../t0123-gateway-json-cbor/dag-pb.car > import_output &&
129
+ test_should_contain $DAG_PB_CID import_output
130
+ '
131
+
132
+ test_expect_success " GET DAG-JSON traverses multiple links" '
133
+ curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 &&
134
+ jq --sort-keys . curl_output > actual &&
135
+ echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected &&
136
+ test_cmp expected actual
137
+ '
138
+
139
+ test_expect_success " GET DAG-CBOR traverses multiple links" '
140
+ curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_CBOR_TRAVERSAL_CID/foo/bar?format=dag-json" > curl_output 2>&1 &&
141
+ jq --sort-keys . curl_output > actual &&
142
+ echo "{ \"hello\": \"this is not a link\" }" | jq --sort-keys . > expected &&
143
+ test_cmp expected actual
144
+ '
145
+
146
+ test_expect_success " GET DAG-PB has expected output" '
147
+ curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DAG_PB_CID?format=dag-json" > curl_output 2>&1 &&
148
+ jq --sort-keys . curl_output > actual &&
149
+ test_cmp ../t0123-gateway-json-cbor/dag-pb.json actual
150
+ '
151
+
111
152
test_kill_ipfs_daemon
112
153
113
154
test_done
0 commit comments