summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhangjie <iamkadisi@163.com>2020-02-05 15:34:01 +0800
committerzhangjie <iamkadisi@163.com>2020-02-18 16:12:24 +0800
commit2d341dee7b21b9e75c7c45fe258052b6b068c152 (patch)
tree68bf6de8ad663e5719a9470c279fcf0e8c798aee
parentsupport make test (diff)
downloadkubeedge-2d341dee7b21b9e75c7c45fe258052b6b068c152.tar.gz
support make lint
Signed-off-by: zhangjie <iamkadisi@163.com>
-rw-r--r--Makefile54
-rw-r--r--cloud/Makefile21
-rwxr-xr-xcloud/hack/test.sh96
-rw-r--r--edge/Makefile17
-rw-r--r--hack/lib/golang.sh3
-rw-r--r--hack/lib/init.sh1
-rw-r--r--hack/lib/lint.sh108
-rwxr-xr-xhack/make-rules/lint.sh26
-rw-r--r--keadm/Makefile4
-rw-r--r--mappers/bluetooth_mapper/Makefile3
10 files changed, 161 insertions, 172 deletions
diff --git a/Makefile b/Makefile
index ff4678c34..473a7d85b 100644
--- a/Makefile
+++ b/Makefile
@@ -86,40 +86,36 @@ test:
hack/make-rules/test.sh $(WHAT)
endif
+LINTS=cloud\
+ edge\
+ keadm\
+ bluetoothdevice
-####################################
-
-# unit tests
-.PHONY: edge_test
-edge_test:
- cd edge && $(MAKE) test
-
-.PHONY: cloud_test
-cloud_test:
- $(MAKE) -C cloud test
-
-
-
-# lint
-.PHONY: lint
-lint:edge_lint cloud_lint bluetoothdevice_lint keadm_lint
-
-.PHONY: edge_lint
-edge_lint:
- cd edge && $(MAKE) lint
+define LINT_HELP_INFO
+# run golang lint check.
+#
+# Args:
+# WHAT: Component names to be lint check. support: $(LINTS)
+# If not specified, "everything" will be lint check.
+#
+# Example:
+# make lint
+# make lint HELP=y
+# make lint WHAT=cloud
+endef
-.PHONY: cloud_lint
-cloud_lint:
- cd cloud && $(MAKE) lint
+.PHONY: lint
+ifeq ($(HELP),y)
+lint:
+ @echo "$$LINT_HELP_INFO"
+else
+lint:
+ hack/make-rules/lint.sh $(WHAT)
+endif
-.PHONY: bluetoothdevice_lint
-bluetoothdevice_lint:
- make -C mappers/bluetooth_mapper lint
-.PHONY: keadm_lint
-keadm_lint:
- make -C keadm lint
+####################################
.PHONY: edge_integration_test
edge_integration_test:
diff --git a/cloud/Makefile b/cloud/Makefile
index d8aef0ab3..e1b107a0a 100644
--- a/cloud/Makefile
+++ b/cloud/Makefile
@@ -6,27 +6,6 @@
default:
-.PHONY: lint
-lint:
- golangci-lint run --skip-dirs 'pkg/client' --disable-all -E gofmt -E golint --deadline '10m' ./...
- go vet ./...
-
-# Build and run tests.
-#
-# Args:
-# WHAT: Directory names to test. All *_test.go files under these
-# directories will be run. If not specified, "everything" will be tested.
-# KUBE_TEST_ARGS: Test case name to test.
-# GOFLAGS: go flags to be passed like verbose mode etc.
-# Example:
-# make test
-# make test GOFLAGS=-v
-# make test WHAT=pkg/controller/manager/ GOFLAGS=-v
-# make test GOFLAGS="-v" KUBE_TEST_ARGS="-run ^TestEventToMessage"
-.PHONY: test
-test:
- hack/test.sh $(WHAT)
-
# Build and run integration tests.
#
# Args:
diff --git a/cloud/hack/test.sh b/cloud/hack/test.sh
deleted file mode 100755
index 39a9f8acb..000000000
--- a/cloud/hack/test.sh
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/env bash
-
-# Copyright 2019 The KubeEdge Authors.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-set -o errexit
-set -o nounset
-set -o pipefail
-
-KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
-
-kubeedge::golang::get_cloud_test_dirs() {
- (
- local findDirs
- local -a dirArray
- cd ${KUBEEDGE_ROOT}
- findDirs=$(find -L ./cloud -not \( \
- \( \
- -path './cloud/test/integration/*' \
- \) -prune \
- \) -name '*_test.go' -print0 | xargs -0n1 dirname | LC_ALL=C sort -u)
- dirArray=(${findDirs// /})
- echo "${dirArray[@]}"
- )
-}
-
-kubeedge::golang::get_edge_test_dirs() {
- (
- local findDirs
- local -a dirArray=()
- cd ${KUBEEDGE_ROOT}
- findDirs=$(find "./edge/pkg" -name "*_test.go"| xargs -I{} dirname {} | uniq)
- dirArray=(${findDirs// /})
- echo "${dirArray[@]}"
- )
-}
-
-read -ra KUBEEDGE_CLOUD_TESTCASES <<< "$(kubeedge::golang::get_cloud_test_dirs)"
-read -ra KUBEEDGE_EDGE_TESTCASES <<< "$(kubeedge::golang::get_edge_test_dirs)"
-
-readonly KUBEEDGE_ALL_TESTCASES=(
- ${KUBEEDGE_CLOUD_TESTCASES[@]}
- ${KUBEEDGE_EDGE_TESTCASES[@]}
-)
-
-ALL_COMPONENTS_AND_GETTESTDIRS_FUNCTIONS=(
- cloud::::kubeedge::golang::get_cloud_test_dirs
- edge::::kubeedge::golang::get_edge_test_dirs
-)
-
-kubeedge::golang::get_testdirs_by_component() {
- local key=$1
- for ct in "${ALL_COMPONENTS_AND_GETTESTDIRS_FUNCTIONS[@]}" ; do
- local component="${ct%%::::*}"
- if [ "${component}" == "${key}" ]; then
- local testcases="${ct##*::::}"
- echo $(eval $testcases)
- return
- fi
- done
- echo "can not find component: $key"
- exit 1
-}
-
-
-
-runTests() {
- echo "running tests cases $@"
-
- cd ${KUBEEDGE_ROOT}
-
- local -a testdirs=()
- local binArg
- for binArg in "$@"; do
- testdirs+=("$(kubeedge::golang::get_testdirs_by_component $binArg)")
- done
-
- if [[ ${#testdirs[@]} -eq 0 ]]; then
- testdirs+=("${KUBEEDGE_ALL_TESTCASES[@]}")
- fi
-
- go test ${testdirs[@]}
-
-}
-runTests $@
-
diff --git a/edge/Makefile b/edge/Makefile
index 5d487f73c..3fbfafa32 100644
--- a/edge/Makefile
+++ b/edge/Makefile
@@ -1,21 +1,4 @@
-# unit tests
-.PHONY: test
-ifeq ($(WHAT),)
- TEST_DIR="./pkg/"
-else
- TEST_DIR=${WHAT}
-endif
-
-export GOARCHAIUS_CONFIG_PATH=$(CURDIR)
-test:
- find ${TEST_DIR} -name "*_test.go"| xargs -I{} dirname {} | uniq | xargs -I{} go test ${T} {}
-
-# lint
-.PHONY: lint
-lint:
- golangci-lint run --disable-all -E gofmt -E golint -E misspell --deadline '10m' ./...
- go vet ./...
.PHONY: integration_test
integration_test: edgecore
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index 26d2505b3..c90a00b33 100644
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -161,8 +161,7 @@ kubeedge::golang::get_target_by_binary() {
for bt in "${ALL_BINARIES_AND_TARGETS[@]}" ; do
local binary="${bt%%:*}"
if [ "${binary}" == "${key}" ]; then
- local target="${bt##*:}"
- echo "$target"
+ echo "${bt##*:}"
return
fi
done
diff --git a/hack/lib/init.sh b/hack/lib/init.sh
index 776cf4384..b9fb53f3e 100644
--- a/hack/lib/init.sh
+++ b/hack/lib/init.sh
@@ -28,3 +28,4 @@ KUBEEDGE_OUTPUT="${KUBEEDGE_ROOT}/${KUBEEDGE_OUTPUT_SUBPATH}"
KUBEEDGE_OUTPUT_BINPATH="${KUBEEDGE_OUTPUT}/bin"
source "${KUBEEDGE_ROOT}/hack/lib/golang.sh"
+source "${KUBEEDGE_ROOT}/hack/lib/lint.sh"
diff --git a/hack/lib/lint.sh b/hack/lib/lint.sh
new file mode 100644
index 000000000..5ef5374af
--- /dev/null
+++ b/hack/lib/lint.sh
@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+###
+#Copyright 2020 The KubeEdge Authors.
+#
+#Licensed under the Apache License, Version 2.0 (the "License");
+#you may not use this file except in compliance with the License.
+#You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing, software
+#distributed under the License is distributed on an "AS IS" BASIS,
+#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#See the License for the specific language governing permissions and
+#limitations under the License.
+###
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+kubeedge::lint::cloud_lint() {
+ (
+ echo "lint cloud"
+ cd ${KUBEEDGE_ROOT}/cloud
+ golangci-lint run --skip-dirs 'pkg/client' --disable-all -E gofmt -E golint --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::edge_lint() {
+ (
+ echo "lint edge"
+ cd ${KUBEEDGE_ROOT}/edge
+ golangci-lint run --disable-all -E gofmt -E golint -E misspell --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::keadm_lint() {
+ (
+ echo "lint keadm"
+ cd ${KUBEEDGE_ROOT}/keadm
+ golangci-lint run --deadline '10m' --disable-all -E golint ./...
+ go vet ./...
+ )
+}
+
+kubeedge::lint::bluetoothdevice_lint() {
+ (
+ echo "lint bluetoothdevice"
+ cd ${KUBEEDGE_ROOT}/mappers/bluetooth_mapper
+ golangci-lint run --disable-all -E golint --deadline '10m' ./...
+ go vet ./...
+ )
+}
+
+ALL_COMPONENTS_AND_LINT_FUNCTIONS=(
+ cloud::::kubeedge::lint::cloud_lint
+ edge::::kubeedge::lint::edge_lint
+ keadm::::kubeedge::lint::keadm_lint
+ bluetoothdevice::::kubeedge::lint::bluetoothdevice_lint
+)
+
+kubeedge::lint::get_lintfuntion_by_component() {
+ local key=$1
+ for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
+ local component="${cl%%::::*}"
+ if [ "${component}" == "${key}" ]; then
+ local func="${cl##*::::}"
+ echo "${func}"
+ return
+ fi
+ done
+ echo "can not find component: $key"
+ exit 1
+}
+
+kubeedge::lint::get_all_lintfuntion() {
+ local -a funcs
+ for cl in "${ALL_COMPONENTS_AND_LINT_FUNCTIONS[@]}" ; do
+ funcs+=("${cl##*::::}")
+ done
+ echo ${funcs[@]}
+}
+
+IFS=" " read -ra ALL_LINT_FUNCTIONS <<< "$(kubeedge::lint::get_all_lintfuntion)"
+
+kubeedge::lint::check() {
+ echo "checking golang lint $@"
+
+ cd ${KUBEEDGE_ROOT}
+
+ local -a funcs=()
+ local arg
+ for arg in "$@"; do
+ funcs+=("$(kubeedge::lint::get_lintfuntion_by_component $arg)")
+ done
+
+ if [[ ${#funcs[@]} -eq 0 ]]; then
+ funcs+=("${ALL_LINT_FUNCTIONS[@]}")
+ fi
+
+ for f in ${funcs[@]}; do
+ $f
+ done
+}
diff --git a/hack/make-rules/lint.sh b/hack/make-rules/lint.sh
new file mode 100755
index 000000000..e575a6a46
--- /dev/null
+++ b/hack/make-rules/lint.sh
@@ -0,0 +1,26 @@
+#!/usr/bin/env bash
+
+###
+#Copyright 2020 The KubeEdge Authors.
+#
+#Licensed under the Apache License, Version 2.0 (the "License");
+#you may not use this file except in compliance with the License.
+#You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing, software
+#distributed under the License is distributed on an "AS IS" BASIS,
+#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#See the License for the specific language governing permissions and
+#limitations under the License.
+###
+
+set -o errexit
+set -o nounset
+set -o pipefail
+
+KUBEEDGE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
+source "${KUBEEDGE_ROOT}/hack/lib/init.sh"
+
+kubeedge::lint::check "$@"
diff --git a/keadm/Makefile b/keadm/Makefile
index 49a6b9148..222aa9619 100644
--- a/keadm/Makefile
+++ b/keadm/Makefile
@@ -1,7 +1,3 @@
-lint:
- golangci-lint run --deadline '10m' --disable-all -E golint ./...
- go vet ./...
-
.PHONY: clean
clean:
$(RM) keadm
diff --git a/mappers/bluetooth_mapper/Makefile b/mappers/bluetooth_mapper/Makefile
index 34f527ff8..9a3ebbcf7 100644
--- a/mappers/bluetooth_mapper/Makefile
+++ b/mappers/bluetooth_mapper/Makefile
@@ -4,9 +4,6 @@
bluetooth_mapper:
go build main.go
-lint:
- golangci-lint run --disable-all -E golint --deadline '10m' ./...
- go vet ./...
bluetooth_mapper_image: bluetooth_mapper
docker build -t bluetooth_mapper:v1.0 .