master
sh 76 lines 2.16 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2016 Kevin Atkinson
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="test how the unix files api interacts with the gc"
8
9 . lib/test-lib.sh
10
11 test_init_ipfs
12
13 test_expect_success "object not removed after gc" '
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" '
21 ipfs files read /hello.txt > hello-actual &&
22 test_cmp hello.txt hello-actual
23 '
24
25 ADIR_HASH=QmbCgoMYVuZq8m1vK31JQx9DorwQdLMF1M3sJ7kygLLqnW
26 FILE1_HASH=QmX4eaSJz39mNhdu5ACUwTDpyA6y24HmrQNnAape6u3buS
27
28 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 &&
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
35 test_must_fail ipfs cat $FILE1_HASH &&
36 ipfs files cp /ipfs/$ADIR_HASH /adir &&
37 ipfs pin rm $ADIR_HASH
38 '
39
40 test_expect_success "gc okay after adding incomplete node" '
41 ipfs dag get $ADIR_HASH &&
42 ipfs repo gc &&
43 ipfs dag get $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) &&
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