Add test with expected failure for #3503
Write a `sharness` test that expects failure documenting the issue raised in #3503. The issue may get resolved in the refactoring of `ipfs dag get` command to support go-ipld-prime (e.g. #8171). For now add a `sharness` test that expects failure. We will then flip the expectation in the success in the rewriting PR to check if #3503 gets resolved. Relates to: - https://github.com/ipfs/go-ipfs/issues/3503
Masih H. Derkani committed
Jul 20, 2021 at 12:14 UTC
1aa9c1a18ff53ecbdc320ae68ee0d65507b943d5
1 file changed
+40
test/sharness/t0055-dag-put-json-new-line.sh
new
+40
@@ -0,0 +1,40 @@
1
+#!/usr/bin/env bash
2
+
3
+test_description='Test retrieval of JSON put as CBOR does not end with new-line'
4
+
5
+. lib/test-lib.sh
6
+
7
+test_init_ipfs
8
+
9
+test_expect_success 'create test JSON files' '
10
+ WANT_JSON="{\"data\":1234}"
11
+ WANT_HASH="bafyreidcqah6v3py3ujdc3ris22rjlfntaw7ajrus2f2477kpnizulaoea"
12
+ printf "${WANT_JSON}\n" > with_newline.json &&
13
+ printf "${WANT_JSON}" > without_newline.json
14
+'
15
+
16
+test_expect_success 'puts as CBOR work' '
17
+ GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put -f cbor)"
18
+ GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put -f cbor)"
19
+'
20
+
21
+test_expect_success 'put hashes with or without newline are equal' '
22
+ test "${GOT_HASH_WITH_NEWLINE}" = "${GOT_HASH_WITHOUT_NEWLINE}"
23
+'
24
+
25
+test_expect_success 'hashes are of expected value' '
26
+ test "${WANT_HASH}" = "${GOT_HASH_WITH_NEWLINE}"
27
+ test "${WANT_HASH}" = "${GOT_HASH_WITHOUT_NEWLINE}"
28
+'
29
+
30
+# Retrieval must not contain a new-line regardless of input JSON, because
31
+# objects are put using the stable CBOR format.
32
+# despite this, dag retrieval returns JSON with new-line.
33
+# Expect failure until fixed, as per:
34
+# - https://github.com/ipfs/go-ipfs/issues/3503#issuecomment-877295280
35
+test_expect_failure "retrieval by hash does not have new line" '
36
+ ipfs dag get "${WANT_HASH}" > got.json
37
+ test_cmp without_newline.json got.json
38
+'
39
+
40
+test_done