put newlines between streaming json output objects
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Oct 22, 2015 at 11:01 UTC
f130869b452b18bfc4b31c6d99b1706e22219039
4 files changed
+42
-3
commands/response.go
+1
@@ -47,6 +47,7 @@ func marshalJson(value interface{}) (io.Reader, error) {
47
if err != nil {
48
return nil, err
49
}
50
+ b = append(b, '\n')
51
return bytes.NewReader(b), nil
52
}
53
test/sharness/t0051-object-data/expected_getOut
+1
-1
@@ -1,4 +1,4 @@
1
{
2
"Links": [],
3
"Data": "\u0008\u0002\u0012\nHello Mars\u0018\n"
4
-}
\ No newline at end of file
4
+}
test/sharness/t0200-unixfs-ls.sh
+2
-2
@@ -122,7 +122,7 @@ test_ls_cmd() {
122
}
123
}
124
EOF
125
- printf %s "$(cat expected_json_ls_file_trailing_newline)" >expected_json_ls_file &&
125
+ printf "%s\n" "$(cat expected_json_ls_file_trailing_newline)" >expected_json_ls_file &&
126
test_cmp expected_json_ls_file actual_json_ls_file
127
'
128
@@ -168,7 +168,7 @@ test_ls_cmd() {
168
}
169
}
170
EOF
171
- printf %s "$(cat expected_json_ls_duplicates_file_trailing_newline)" >expected_json_ls_duplicates_file &&
171
+ printf "%s\n" "$(cat expected_json_ls_duplicates_file_trailing_newline)" >expected_json_ls_duplicates_file &&
172
test_cmp expected_json_ls_duplicates_file actual_json_ls_duplicates_file
173
'
174
}
test/sharness/t0231-channel-streaming.sh
new
+38
@@ -0,0 +1,38 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2015 Jeromy Johnson
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test output of streaming json commands"
8
+
9
+. lib/test-lib.sh
10
+
11
+test_init_ipfs
12
+
13
+get_api_port() {
14
+ cat "$IPFS_PATH/api" | awk -F/ '{ print $5 }'
15
+}
16
+
17
+test_ls_cmd() {
18
+ test_expect_success "make a file with multiple refs" '
19
+ HASH=$(random 1000000 | ipfs add -q)
20
+ '
21
+
22
+ test_expect_success "can get refs through curl" '
23
+ PORT=$(get_api_port) &&
24
+ curl http://localhost:$PORT/api/v0/refs/$HASH > output
25
+ '
26
+
27
+ # make sure newlines are printed between each object
28
+ test_expect_success "output looks good" '
29
+ test_expect_code 1 grep "}{" output > /dev/null
30
+ '
31
+}
32
+
33
+# should work online (only)
34
+test_launch_ipfs_daemon
35
+test_ls_cmd
36
+test_kill_ipfs_daemon
37
+
38
+test_done