master
sh 114 lines 2.61 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2017 Jeromy Johnson
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test out the filestore nocopy functionality"
8
9 . lib/test-lib.sh
10
11
12 test_expect_success "create a dataset" '
13 random-files -seed=483 -depth=3 -dirs=4 -files=6 -filesize=1000000 somedir > /dev/null
14 '
15
16 EXPHASH="QmXKtATsEt42CF5JoSsmzJstrvwEB5P89YQtdX4mdf9E3M"
17
18 get_repo_size() {
19 disk_usage "$IPFS_PATH"
20 }
21
22 assert_repo_size_less_than() {
23 expval="$1"
24
25 test_expect_success "check repo size" '
26 test "$(get_repo_size)" -lt "$expval" ||
27 { echo should be below "$expval" && test_fsh get_repo_size; }
28 '
29 }
30
31 assert_repo_size_greater_than() {
32 expval="$1"
33
34 test_expect_success "check repo size" '
35 test "$(get_repo_size)" -gt "$expval" ||
36 { echo should be above "$expval" && test_fsh get_repo_size; }
37 '
38 }
39
40 test_filestore_adds() {
41 test_expect_success "nocopy add succeeds" '
42 HASH=$(ipfs add --raw-leaves --nocopy -r -Q somedir)
43 '
44
45 test_expect_success "nocopy add has right hash" '
46 test "$HASH" = "$EXPHASH"
47 '
48
49 assert_repo_size_less_than 1000000
50
51 test_expect_success "normal add with fscache doesn't duplicate data" '
52 ipfs add --raw-leaves --fscache -r -q somedir > /dev/null
53 '
54
55 assert_repo_size_less_than 1000000
56
57 test_expect_success "normal add without fscache duplicates data" '
58 ipfs add --raw-leaves -r -q somedir > /dev/null
59 '
60
61 assert_repo_size_greater_than 1000000
62 }
63
64 init_ipfs_filestore() {
65 test_expect_success "clean up old node" '
66 rm -rf "$IPFS_PATH" mountdir ipfs ipns mfs
67 '
68
69 test_init_ipfs
70
71 # Check the _early_ error message
72 test_expect_success "nocopy add errors and has right message" '
73 test_must_fail ipfs add --nocopy -r somedir 2> add_out &&
74 grep "either the filestore or the urlstore must be enabled" add_out
75 '
76
77 assert_repo_size_less_than 1000000
78
79 test_expect_success "enable urlstore config setting" '
80 ipfs config --json Experimental.UrlstoreEnabled true
81 '
82
83 # Check the _late_ error message
84 test_expect_success "nocopy add errors and has right message when the urlstore is enabled" '
85 test_must_fail ipfs add --nocopy -r somedir 2> add_out &&
86 grep "filestore is not enabled" add_out
87 '
88
89 assert_repo_size_less_than 1000000
90
91 test_expect_success "enable filestore config setting" '
92 ipfs config --json Experimental.UrlstoreEnabled true &&
93 ipfs config --json Experimental.FilestoreEnabled true
94 '
95 }
96
97 init_ipfs_filestore
98
99 test_filestore_adds
100
101 test_debug '
102 echo "pwd=$(pwd)"; echo "IPFS_PATH=$IPFS_PATH"
103 '
104
105
106 init_ipfs_filestore
107
108 test_launch_ipfs_daemon
109
110 test_filestore_adds
111
112 test_kill_ipfs_daemon
113
114 test_done