Commit 4022d8b8 authored by Juan Benet's avatar Juan Benet

Merge pull request #1885 from ipfs/fix/ndjson

put newlines between streaming json output objects
parents 49684ea4 f130869b
...@@ -47,6 +47,7 @@ func marshalJson(value interface{}) (io.Reader, error) { ...@@ -47,6 +47,7 @@ func marshalJson(value interface{}) (io.Reader, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
b = append(b, '\n')
return bytes.NewReader(b), nil return bytes.NewReader(b), nil
} }
......
{ {
"Links": [], "Links": [],
"Data": "\u0008\u0002\u0012\nHello Mars\u0018\n" "Data": "\u0008\u0002\u0012\nHello Mars\u0018\n"
} }
\ No newline at end of file
...@@ -122,7 +122,7 @@ test_ls_cmd() { ...@@ -122,7 +122,7 @@ test_ls_cmd() {
} }
} }
EOF EOF
printf %s "$(cat expected_json_ls_file_trailing_newline)" >expected_json_ls_file && printf "%s\n" "$(cat expected_json_ls_file_trailing_newline)" >expected_json_ls_file &&
test_cmp expected_json_ls_file actual_json_ls_file test_cmp expected_json_ls_file actual_json_ls_file
' '
...@@ -168,7 +168,7 @@ test_ls_cmd() { ...@@ -168,7 +168,7 @@ test_ls_cmd() {
} }
} }
EOF EOF
printf %s "$(cat expected_json_ls_duplicates_file_trailing_newline)" >expected_json_ls_duplicates_file && printf "%s\n" "$(cat expected_json_ls_duplicates_file_trailing_newline)" >expected_json_ls_duplicates_file &&
test_cmp expected_json_ls_duplicates_file actual_json_ls_duplicates_file test_cmp expected_json_ls_duplicates_file actual_json_ls_duplicates_file
' '
} }
......
#!/bin/sh
#
# Copyright (c) 2015 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="Test output of streaming json commands"
. lib/test-lib.sh
test_init_ipfs
get_api_port() {
cat "$IPFS_PATH/api" | awk -F/ '{ print $5 }'
}
test_ls_cmd() {
test_expect_success "make a file with multiple refs" '
HASH=$(random 1000000 | ipfs add -q)
'
test_expect_success "can get refs through curl" '
PORT=$(get_api_port) &&
curl http://localhost:$PORT/api/v0/refs/$HASH > output
'
# make sure newlines are printed between each object
test_expect_success "output looks good" '
test_expect_code 1 grep "}{" output > /dev/null
'
}
# should work online (only)
test_launch_ipfs_daemon
test_ls_cmd
test_kill_ipfs_daemon
test_done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment