master
sh 102 lines 2.43 KB
Raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2019 Protocol Labs
4 # MIT Licensed; see the LICENSE file in this repository.
5 #
6
7 test_description="Test plugin loading"
8
9 . lib/test-lib.sh
10
11 if ! test_have_prereq PLUGIN; then
12 skip_all='skipping plugin tests, plugins not available'
13
14 test_done
15 fi
16
17 test_init_ipfs
18
19 test_expect_success "ipfs id succeeds" '
20 ipfs id
21 '
22
23 test_expect_success "make a bad plugin" '
24 mkdir -p "$IPFS_PATH/plugins" &&
25 echo foobar > "$IPFS_PATH/plugins/foo.so" &&
26 chmod +x "$IPFS_PATH/plugins/foo.so"
27 '
28
29 test_expect_success "ipfs id fails due to a bad plugin" '
30 test_expect_code 1 ipfs id
31 '
32
33 test_expect_success "cleanup bad plugin" '
34 rm "$IPFS_PATH/plugins/foo.so"
35 '
36
37 test_expect_success "install test plugin" '
38 go build \
39 -asmflags=all="-trimpath=${GOPATH}" -gcflags=all="-trimpath=${GOPATH}" \
40 -buildmode=plugin -o "$IPFS_PATH/plugins/example.so" ../t0280-plugin-data/example.go &&
41 chmod +x "$IPFS_PATH/plugins/example.so"
42 '
43
44 test_plugin() {
45 local loads="$1"
46 local repo="$2"
47 local config="$3"
48
49 rm -f id_raw_output id_output id_output_expected
50
51 test_expect_success "id runs" '
52 ipfs id 2>id_raw_output >/dev/null
53 '
54
55 test_expect_success "filter test plugin output" '
56 sed -ne "s/^testplugin //p" id_raw_output >id_output
57 '
58
59 if [ "$loads" != "true" ]; then
60 test_expect_success "plugin doesn't load" '
61 test_must_be_empty id_output
62 '
63 else
64 test_expect_success "plugin produces the correct output" '
65 echo "$repo" >id_output_expected &&
66 echo "$config" >>id_output_expected &&
67 test_cmp id_output id_output_expected
68 '
69 fi
70 }
71
72 test_plugin true "$IPFS_PATH" "<nil>"
73
74 test_expect_success "disable the plugin" '
75 ipfs config --json Plugins.Plugins.test-plugin.Disabled true
76 '
77
78 test_plugin false
79
80 test_expect_success "re-enable the plugin" '
81 ipfs config --json Plugins.Plugins.test-plugin.Disabled false
82 '
83
84 test_plugin true "$IPFS_PATH" "<nil>"
85
86 test_expect_success "configure the plugin" '
87 ipfs config Plugins.Plugins.test-plugin.Config foobar
88 '
89
90 test_plugin true "$IPFS_PATH" "foobar"
91
92 test_expect_success "noplugin flag works" '
93 test_must_fail go run -tags=noplugin github.com/ipfs/go-ipfs/cmd/ipfs id > output 2>&1
94 test_should_contain "not built with plugin support" output
95 '
96
97 test_expect_success "noplugin flag works" '
98 CGO_ENABLED=0 test_must_fail go run github.com/ipfs/go-ipfs/cmd/ipfs id > output 2>&1
99 test_should_contain "not built with cgo support" output
100 '
101
102 test_done