Skip to content

Commit 309535c

Browse files
Merge pull request #3151 from ipfs/kevina/more3138tests
Enhance tests for files API root best-effort pin.
2 parents 0e5e6cf + 6e4f3ac commit 309535c

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

test/sharness/t0252-files-gc.sh

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ test_description="test how the unix files api interacts with the gc"
1111
test_init_ipfs
1212

1313
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 &&
1516
ipfs repo gc &&
1617
ipfs cat QmVib14uvPnCP73XaCDpwugRuwfTsVbGyWbatHAmLSdZUS
1718
'
1819

1920
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
2123
'
2224

2325
ADIR_HASH=QmbCgoMYVuZq8m1vK31JQx9DorwQdLMF1M3sJ7kygLLqnW
@@ -27,7 +29,6 @@ test_expect_success "gc okay after adding incomplete node -- prep" '
2729
ipfs files mkdir /adir &&
2830
echo "file1" | ipfs files write --create /adir/file1 &&
2931
echo "file2" | ipfs files write --create /adir/file2 &&
30-
ipfs cat $FILE1_HASH &&
3132
ipfs pin add --recursive=false $ADIR_HASH &&
3233
ipfs files rm -r /adir &&
3334
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" '
4243
ipfs refs $ADIR_HASH
4344
'
4445

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+
4576
test_done

0 commit comments

Comments
 (0)