master
sh 35 lines 1.05 KB
Raw
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="bafyreidbm2zncsc3j25zn7lofgd4woeh6eygdy73thfosuni2rwr3bhcvu"
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 --store-codec dag-cbor)"
18 GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put --store-codec dag-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 test_expect_success "retrieval by hash does not have new line" '
31 ipfs dag get "${WANT_HASH}" > got.json
32 test_cmp without_newline.json got.json
33 '
34
35 test_done