From 5fae9a4aa90a37ca6918306b2d470b2501eae895 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Magiera?= <magik6k@gmail.com>
Date: Tue, 26 Sep 2017 00:56:25 +0200
Subject: [PATCH] plugin: add sharness tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

License: MIT
Signed-off-by: Ɓukasz Magiera <magik6k@gmail.com>
---
 Makefile                          |  1 +
 cmd/ipfs/Rules.mk                 |  8 ++++----
 config.mk                         |  2 ++
 test/sharness/Rules.mk            |  7 +++++--
 test/sharness/t0280-plugin-git.sh | 32 ++++++++++++++++++++++++++-----
 5 files changed, 39 insertions(+), 11 deletions(-)
 create mode 100644 config.mk

diff --git a/Makefile b/Makefile
index 9f5e509d6..629ed12e1 100644
--- a/Makefile
+++ b/Makefile
@@ -7,4 +7,5 @@ PROTOC = protoc --gogo_out=. --proto_path=.:/usr/local/opt/protobuf/include:$(di
 # enable second expansion
 .SECONDEXPANSION:
 
+include config.mk
 include Rules.mk
diff --git a/cmd/ipfs/Rules.mk b/cmd/ipfs/Rules.mk
index 8c9a15a86..40cee7a87 100644
--- a/cmd/ipfs/Rules.mk
+++ b/cmd/ipfs/Rules.mk
@@ -13,10 +13,10 @@ PATH := $(realpath $(d)):$(PATH)
 # DEPS_OO_$(d) += merkledag/pb/merkledag.pb.go namesys/pb/namesys.pb.go
 # DEPS_OO_$(d) += pin/internal/pb/header.pb.go unixfs/pb/unixfs.pb.go
 
-CONFIG_COMMIT ?= github.com/ipfs/go-ipfs/repo/config.CurrentCommit=$(shell git rev-parse --short HEAD)
-CONFIG_PLUGIN_PATH ?= github.com/ipfs/go-ipfs/repo/config.SystemPluginPath=${PLUGIN_PATH}
-
-$(d)_flags =-ldflags="-X ${CONFIG_COMMIT} -X ${CONFIG_PLUGIN_PATH}"
+$(d)_flags  =-ldflags="
+$(d)_flags += -X github.com/ipfs/go-ipfs/repo/config.CurrentCommit=${CONFIG_COMMIT}
+$(d)_flags += -X github.com/ipfs/go-ipfs/repo/config.SystemPluginPath=${CONFIG_PLUGIN_PATH}
+$(d)_flags += "
 
 $(d)-try-build $(IPFS_BIN_$(d)): GOFLAGS += $(cmd/ipfs_flags)
 
diff --git a/config.mk b/config.mk
new file mode 100644
index 000000000..de8ebfb76
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,2 @@
+CONFIG_COMMIT := $(shell git rev-parse --short HEAD)
+CONFIG_PLUGIN_PATH = ${PLUGIN_PATH}
diff --git a/test/sharness/Rules.mk b/test/sharness/Rules.mk
index 188cb50cb..ba69f6433 100644
--- a/test/sharness/Rules.mk
+++ b/test/sharness/Rules.mk
@@ -7,9 +7,9 @@ T_$(d) = $(sort $(wildcard $(d)/t[0-9][0-9][0-9][0-9]-*.sh))
 DEPS_$(d) := test/bin/random test/bin/multihash test/bin/pollEndpoint \
 	   test/bin/iptb test/bin/go-sleep test/bin/random-files \
 	   test/bin/go-timeout test/bin/hang-fds test/bin/ma-pipe-unidir
-DEPS_$(d) += cmd/ipfs/ipfs
 DEPS_$(d) += $(d)/clean-test-results
 DEPS_$(d) += $(SHARNESS_$(d))
+DEPS_$(d) += $(d)/sharness-ipfs
 
 ifeq ($(OS),Linux)
 PLUGINS_DIR_$(d) := $(d)/plugins/
@@ -49,13 +49,16 @@ $(SHARNESS_$(d)): $(d) ALWAYS
 $(d)/deps: $(SHARNESS_$(d)) $$(DEPS_$(d)) # use second expansion so coverage can inject dependency
 .PHONY: $(d)/deps
 
+$(d)/sharness-ipfs: PLUGIN_PATH=./system_plugins
+$(d)/sharness-ipfs: cmd/ipfs/ipfs
+.PHONY: $(d)/sharness-ipfs
+
 test_sharness_deps: $(d)/deps
 .PHONY: test_sharness_deps
 
 test_sharness_short: $(d)/aggregate
 .PHONY: test_sharness_short
 
-
 test_sharness_expensive: export TEST_EXPENSIVE=1
 test_sharness_expensive: test_sharness_short
 .PHONY: test_sharness_expensive
diff --git a/test/sharness/t0280-plugin-git.sh b/test/sharness/t0280-plugin-git.sh
index a93dfdeba..f3378b106 100755
--- a/test/sharness/t0280-plugin-git.sh
+++ b/test/sharness/t0280-plugin-git.sh
@@ -17,11 +17,6 @@ fi
 
 test_init_ipfs
 
-test_expect_success "copy plugin" '
-  mkdir -p "$IPFS_PATH/plugins" &&
-  cp ../plugins/git.so "$IPFS_PATH/plugins/"
-'
-
 # from https://github.com/ipfs/go-ipld-git/blob/master/make-test-repo.sh
 test_expect_success "prepare test data" '
   tar xzf ../t0280-plugin-git-data/git.tar.gz
@@ -46,6 +41,33 @@ test_dag_git() {
   '
 }
 
+test_expect_success "copy plugin to local plugin directory" '
+  mkdir -p "$IPFS_PATH/plugins" &&
+  chmod +x ../plugins/git.so &&
+  cp ../plugins/git.so "$IPFS_PATH/plugins/"
+'
+
+# should work offline
+#test_dag_git
+
+# should work online
+test_launch_ipfs_daemon
+test_dag_git
+test_kill_ipfs_daemon
+
+test_expect_success "copy plugin to global plugin directory" '
+  mkdir -p "./system_plugins" &&
+  cp ../plugins/git.so "./system_plugins/"
+'
+
+test_expect_success "fail with duplicate plugin" '
+  echo 123 | test_must_fail ipfs dag put
+'
+
+test_expect_success "remove local plugin" '
+  rm -r "$IPFS_PATH/plugins/"
+'
+
 # should work offline
 #test_dag_git
 
-- 
GitLab