-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mike Ng <[email protected]>
- Loading branch information
Showing
4 changed files
with
79 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Temporary Build Files | ||
test | ||
build/_output | ||
build/_test | ||
build-harness-extensions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,31 @@ | ||
#!/bin/bash | ||
#!/bin/bash -e | ||
############################################################################### | ||
# (c) Copyright IBM Corporation 2019, 2020. All Rights Reserved. | ||
# Note to U.S. Government Users Restricted Rights: | ||
# U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule | ||
# Contract with IBM Corp. | ||
# Copyright (c) Red Hat, Inc. | ||
# Copyright Contributors to the Open Cluster Management project | ||
############################################################################### | ||
|
||
# | ||
# Copyright 2019 The Kubernetes 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. | ||
_script_dir=$(dirname "$0") | ||
if ! which patter > /dev/null; then echo "Installing patter ..."; pushd $(mktemp -d) && GOSUMDB=off go get -u github.com/apg/patter && popd; fi | ||
if ! which gocovmerge > /dev/null; then echo "Installing gocovmerge..."; pushd $(mktemp -d) && GOSUMDB=off go get -u github.com/wadey/gocovmerge && popd; fi | ||
|
||
echo "UNIT TESTS GO HERE!" | ||
export GOFLAGS="" | ||
mkdir -p test/unit/coverage | ||
echo 'mode: atomic' > test/unit/coverage/cover.out | ||
echo '' > test/unit/coverage/cover.tmp | ||
echo -e "${GOPACKAGES// /\\n}" | xargs -n1 -I{} $_script_dir/test-package.sh {} ${GOPACKAGES// /,} | ||
|
||
echo "Install Kubebuilder components for test framework usage!" | ||
if [ ! -f test/unit/coverage/cover.out ]; then | ||
echo "Coverage file test/unit/coverage/cover.out does not exist" | ||
exit 0 | ||
fi | ||
|
||
_OS=$(go env GOOS) | ||
_ARCH=$(go env GOARCH) | ||
KubeBuilderVersion="2.3.1" | ||
COVERAGE=$(go tool cover -func=test/unit/coverage/cover.out | grep "total:" | awk '{ print $3 }' | sed 's/[][()><%]/ /g') | ||
echo "-------------------------------------------------------------------------" | ||
echo "TOTAL COVERAGE IS ${COVERAGE}%" | ||
echo "-------------------------------------------------------------------------" | ||
|
||
# download kubebuilder and extract it to tmp | ||
curl -L https://go.kubebuilder.io/dl/"$KubeBuilderVersion"/"${_OS}"/"${_ARCH}" | tar -xz -C /tmp/ | ||
|
||
# move to a long-term location and put it on your path | ||
# (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else) | ||
sudo mv /tmp/kubebuilder_"$KubeBuilderVersion"_"${_OS}"_"${_ARCH}" /usr/local/kubebuilder | ||
export PATH=$PATH:/usr/local/kubebuilder/bin | ||
|
||
# Run unit test | ||
export IMAGE_NAME_AND_VERSION=${1} | ||
make test | ||
go tool cover -html=test/unit/coverage/cover.out -o=test/unit/coverage/cover.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash -e | ||
############################################################################### | ||
# (c) Copyright IBM Corporation 2019, 2020. All Rights Reserved. | ||
# Note to U.S. Government Users Restricted Rights: | ||
# U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule | ||
# Contract with IBM Corp. | ||
# Copyright (c) Red Hat, Inc. | ||
# Copyright Contributors to the Open Cluster Management project | ||
############################################################################### | ||
|
||
# NOTE: This script should not be called directly. Please run `make test`. | ||
|
||
set -o pipefail | ||
|
||
_package=$1 | ||
_cover_pkgs=$2 | ||
echo -e "\nTesting package $_package" | ||
|
||
# Make sure temporary files do not exist | ||
rm -f test/unit/coverage/cover.tmp | ||
|
||
# Support for TAP output | ||
_package_base=${PROJECT_DIR/$GOPATH\/src\/} # TODO need a better solution since $(go list) doesn't work any more (won't work with go 1.11) | ||
_tap_out_dir=$GOPATH/src/$_package_base/test/out | ||
_tap_name="${_package/$_package_base/}" | ||
_tap_name=${_tap_name//\//_} | ||
|
||
mkdir -p $_tap_out_dir | ||
|
||
# Run tests | ||
# DO NOT USE -coverpkg=./... | ||
go test -v -cover -coverpkg=$_cover_pkgs -covermode=atomic -coverprofile=test/unit/coverage/cover.tmp $_package 2> >( grep -v "warning: no packages being tested depend on" >&2 ) | $GOPATH/bin/patter | tee $_tap_out_dir/$_tap_name.tap | grep -v "TAP version 13" | grep -v ": PASS:" | grep -v -i "# /us" | ||
|
||
# Merge coverage files | ||
if [ -f test/unit/coverage/cover.tmp ]; then | ||
$GOPATH/bin/gocovmerge test/unit/coverage/cover.tmp test/unit/coverage/cover.out > test/unit/coverage/cover.all | ||
mv test/unit/coverage/cover.all test/unit/coverage/cover.out | ||
fi | ||
|
||
# Clean up temporary files | ||
rm -f test/unit/coverage/cover.tmp |