@cryptotaxi247 / kubo / commits / 6e4f3acb4

Enhance tests for files API root best-effort pin.

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Aug 31, 2016 at 18:16 UTC 6e4f3acb4aa2781e2153742b4954ee88dfe57437
1 file changed +34 -3
test/sharness/t0252-files-gc.sh
+34 -3
@@ -11,13 +11,15 @@ test_description="test how the unix files api interacts with the gc"
11 test_init_ipfs
12
13 test_expect_success "object not removed after gc" '
14 - echo "hello world" | ipfs files write --create /hello.txt &&
14 + echo "hello world" > hello.txt &&
15 + cat hello.txt | ipfs files write --create /hello.txt &&
16 ipfs repo gc &&
17 ipfs cat QmVib14uvPnCP73XaCDpwugRuwfTsVbGyWbatHAmLSdZUS
18 '
19
20 test_expect_success "/hello.txt still accessible after gc" '
20 - ipfs files read /hello.txt
21 + ipfs files read /hello.txt > hello-actual &&
22 + test_cmp hello.txt hello-actual
23 '
24
25 ADIR_HASH=QmbCgoMYVuZq8m1vK31JQx9DorwQdLMF1M3sJ7kygLLqnW
@@ -27,7 +29,6 @@ test_expect_success "gc okay after adding incomplete node -- prep" '
29 ipfs files mkdir /adir &&
30 echo "file1" | ipfs files write --create /adir/file1 &&
31 echo "file2" | ipfs files write --create /adir/file2 &&
30 - ipfs cat $FILE1_HASH &&
32 ipfs pin add --recursive=false $ADIR_HASH &&
33 ipfs files rm -r /adir &&
34 ipfs repo gc && # will remove /adir/file1 and /adir/file2 but not /adir
@@ -42,4 +43,34 @@ test_expect_success "gc okay after adding incomplete node" '
43 ipfs refs $ADIR_HASH
44 '
45
46 +test_expect_success "add directory with direct pin" '
47 + mkdir mydir/ &&
48 + echo "hello world!" > mydir/hello.txt &&
49 + FILE_UNPINNED=$(ipfs add --pin=false -q -r mydir/hello.txt) &&
50 + DIR_PINNED=$(ipfs add --pin=false -q -r mydir | tail -n1) &&
51 + ipfs add --pin=false -r mydir &&
52 + ipfs pin add --recursive=false $DIR_PINNED &&
53 + ipfs cat $FILE_UNPINNED
54 +'
55 +
56 +test_expect_success "run gc and make sure directory contents are removed" '
57 + ipfs repo gc &&
58 + test_must_fail ipfs cat $FILE_UNPINNED
59 +'
60 +
61 +test_expect_success "add incomplete directory and make sure gc is okay" '
62 + ipfs files cp /ipfs/$DIR_PINNED /mydir &&
63 + ipfs repo gc &&
64 + test_must_fail ipfs cat $FILE_UNPINNED
65 +'
66 +
67 +test_expect_success "add back directory contents and run gc" '
68 + ipfs add --pin=false mydir/hello.txt &&
69 + ipfs repo gc
70 +'
71 +
72 +test_expect_success "make sure directory contents are not removed" '
73 + ipfs cat $FILE_UNPINNED
74 +'
75 +
76 test_done