-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add some dag-json and dag-cbor tests
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
|
||
test_description="Test HTTP Gateway DAG-JSON (application/vnd.ipld.dag-json) and DAG-CBOR (application/vnd.ipld.dag-cbor) Support" | ||
|
||
. lib/test-lib.sh | ||
|
||
test_init_ipfs | ||
test_launch_ipfs_daemon_without_network | ||
|
||
test_expect_success "Add the test directory" ' | ||
mkdir -p rootDir/ipfs && | ||
mkdir -p rootDir/ipns && | ||
mkdir -p rootDir/api && | ||
mkdir -p rootDir/ą/ę && | ||
echo "I am a txt file on path with utf8" > rootDir/ą/ę/file-źł.txt && | ||
echo "I am a txt file in confusing /api dir" > rootDir/api/file.txt && | ||
echo "I am a txt file in confusing /ipfs dir" > rootDir/ipfs/file.txt && | ||
echo "I am a txt file in confusing /ipns dir" > rootDir/ipns/file.txt && | ||
DIR_CID=$(ipfs add -Qr --cid-version 1 rootDir) && | ||
FILE_CID=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Hash) && | ||
FILE_SIZE=$(ipfs files stat --enc=json /ipfs/$DIR_CID/ą/ę/file-źł.txt | jq -r .Size) | ||
echo "$FILE_CID / $FILE_SIZE" | ||
' | ||
|
||
test_codec () { | ||
format=$1 | ||
|
||
test_expect_success "GET $format with format=dag-$format has expected Content-Type" ' | ||
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && | ||
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && | ||
test_should_not_contain "Content-Type: application/$format" curl_output | ||
' | ||
|
||
test_expect_success "GET $format with 'Accept: application/vnd.ipld.dag-$format' has expected Content-Type" ' | ||
curl -sD - -H "Accept: application/vnd.ipld.dag-$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && | ||
test_should_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output && | ||
test_should_not_contain "Content-Type: application/$format" curl_output | ||
' | ||
|
||
test_expect_success "GET $format with format=$format has expected Content-Type" ' | ||
curl -sD - "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=$format" > curl_output 2>&1 && | ||
test_should_contain "Content-Type: application/$format" curl_output && | ||
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output | ||
' | ||
|
||
test_expect_success "GET $format with 'Accept: application/$format' has expected Content-Type" ' | ||
curl -sD - -H "Accept: application/$format" "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID" > curl_output 2>&1 && | ||
test_should_contain "Content-Type: application/$format" curl_output && | ||
test_should_not_contain "Content-Type: application/vnd.ipld.dag-$format" curl_output | ||
' | ||
|
||
test_expect_success "GET $format has expected output for file" ' | ||
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$FILE_CID?format=dag-$format" > curl_output 2>&1 && | ||
ipfs dag get --output-codec dag-$format $FILE_CID > ipfs_dag_get_output 2>&1 && | ||
test_cmp ipfs_dag_get_output curl_output | ||
' | ||
|
||
test_expect_success "GET $format has expected output for directory" ' | ||
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output 2>&1 && | ||
ipfs dag get --output-codec dag-$format $DIR_CID > ipfs_dag_get_output 2>&1 && | ||
test_cmp ipfs_dag_get_output curl_output | ||
' | ||
|
||
test_expect_success "GET $format with format=dag-$format and format=$format produce same output" ' | ||
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=dag-$format" > curl_output_1 2>&1 && | ||
curl -s "http://127.0.0.1:$GWAY_PORT/ipfs/$DIR_CID?format=$format" > curl_output_2 2>&1 && | ||
test_cmp curl_output_1 curl_output_2 | ||
' | ||
} | ||
|
||
test_codec "json" | ||
test_codec "cbor" | ||
|
||
test_kill_ipfs_daemon | ||
|
||
test_done |