Merge pull request #1750 from monopole/invokePluginUnitTests

Invoke plugin unit tests in presubmit.
This commit is contained in:
Jeff Regan
2019-11-07 17:29:15 -08:00
committed by GitHub
4 changed files with 88 additions and 28 deletions

View File

@@ -47,16 +47,20 @@ lint: install-tools
cd kustomize; $(MYGOBIN)/golangci-lint run ./...
cd pluginator; $(MYGOBIN)/golangci-lint run ./...
.PHONY: unit-tests-api
unit-tests-api:
.PHONY: unit-test-api
unit-test-api:
cd api; go test ./...
.PHONY: unit-tests-kustomize
unit-tests-kustomize:
.PHONY: unit-test-plugins
unit-test-plugins:
./hack/runPluginUnitTests.sh
.PHONY: unit-test-kustomize
unit-test-kustomize:
cd kustomize; go test ./...
.PHONY: unit-tests
unit-tests: unit-tests-api unit-tests-kustomize
.PHONY: unit-test-all
unit-test-all: unit-test-api unit-test-kustomize unit-test-plugins
# linux only.
$(MYGOBIN)/kubeval:

74
hack/runPluginUnitTests.sh Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/env bash
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
# TODO: get rid of this script, make individual targets
# in the makefile.
# Run this script with no arguments from the repo root
# to test all the plugins.
# Want this to keep going even if one test fails,
# to see how many pass, so do not errexit.
set -o nounset
# set -o errexit
set -o pipefail
rcAccumulator=0
function onLinuxAndNotOnTravis {
[[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return
false
}
function runTest {
local file=$1
local code=0
if grep -q "// +build notravis" "$file"; then
if onLinuxAndNotOnTravis; then
go test -v -tags=notravis $file
code=$?
else
# TODO: make work for non-linux
echo "Not on linux or on travis; skipping $file"
fi
else
go test -v $file
code=$?
fi
rcAccumulator=$((rcAccumulator || $code))
if [ $code -ne 0 ]; then
echo "Failure in $d"
fi
}
function scanDir {
pushd $1 >& /dev/null
echo "Testing $1"
for t in $(find . -name '*_test.go'); do
runTest $t
done
popd >& /dev/null
}
if onLinuxAndNotOnTravis; then
# Some of these tests have special deps.
make $(go env GOPATH)/bin/helm
make $(go env GOPATH)/bin/kubeval
fi
for goMod in $(find ./plugin -name 'go.mod'); do
d=$(dirname "${goMod}")
if [[ "$d" == "./plugin/someteam.example.com/v1/gogetter" ]]; then
echo "Skipping broken $d"
else
scanDir $d
fi
done
if [ $rcAccumulator -ne 0 ]; then
echo "FAILURE; exit code $rcAccumulator"
exit 1
fi

View File

@@ -33,6 +33,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 h1:H2pdYOb3KQ1/YsqVWoWNLQO+fusocsw354rqGTZtAgw=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emicklei/go-restful v2.9.6+incompatible h1:tfrHha8zJ01ywiOEC1miGY8st1/igzWB8OmvPgoYX7w=
github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
@@ -117,6 +118,7 @@ github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
@@ -337,6 +339,7 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=

View File

@@ -35,28 +35,7 @@ function runLint {
}
function runUnitTests {
make unit-tests
# TODO: make work for non-linux
if [[ (-z ${TRAVIS+x}) && ("linux" == "$(go env GOOS)") ]]; then
echo " "
echo "On linux, and not on travis, so running the notravis Go tests."
echo " "
# Requires helm.
make $(go env GOPATH)/bin/helm
(cd api; go test -v sigs.k8s.io/kustomize/api/internal/target \
-run TestChartInflatorPlugin -tags=notravis)
(cd plugin/someteam.example.com/v1/chartinflator;
go test -v . -run TestChartInflator -tags=notravis)
# Requires kubeval.
make $(go env GOPATH)/bin/kubeval
(cd plugin/someteam.example.com/v1/validator;
go test -v . -run TestValidatorHappy -tags=notravis)
(cd plugin/someteam.example.com/v1/validator;
go test -v . -run TestValidatorUnHappy -tags=notravis)
fi
make unit-test-all
}
function testExamplesAgainstLatestKustomizeRelease {