test: add make verify

This commit is contained in:
Jiaxun Song 2020-11-16 20:36:41 +00:00
parent d852708787
commit c84426fb4e
10 changed files with 159 additions and 27 deletions

78
.gitignore vendored
View File

@ -1,6 +1,72 @@
/bin # OSX leaves these everywhere on SMB shares
._*
# This is where the result of the go build goes
/output*/ # OSX trash
/_output*/ .DS_Store
/_output
# Eclipse files
.classpath
.project
.settings/**
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
.idea/
*.iml
# Vscode files
.vscode
# This is where the result of the go build goes
/output*/
/_output*/
/_output
/bin
# Emacs save files
*~
\#*\#
.\#*
# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
# cscope-related files
cscope.*
# Go test binaries
*.test
# JUnit test output from ginkgo e2e tests
/junit*.xml
# Mercurial files
**/.hg
**/.hg*
# Vagrant
.vagrant
.tags*
# Test artifacts produced by Jenkins jobs
/_artifacts/
# Go dependencies installed on Jenkins
/_gopath/
# direnv .envrc files
.envrc
# This file used by some vendor repos (e.g. github.com/go-openapi/...) to store secret variables and should not be ignored
!\.drone\.sec
# Godeps or dep workspace
/Godeps/_workspace
/bazel-*
*.pyc
profile.cov

View File

@ -39,6 +39,13 @@ LDFLAGS = "-X ${PKG}/pkg/nfs.driverVersion=${IMAGE_VERSION} -s -w -extldflags '-
all: nfs all: nfs
.PHONY: verify
verify: unit-test
hack/verify-all.sh
.PHONY: unit-test
unit-test:
go test -covermode=count -coverprofile=profile.cov ./pkg/... -v
.PHONY: sanity-test .PHONY: sanity-test
sanity-test: nfs sanity-test: nfs

View File

@ -38,7 +38,7 @@ rootdir = os.path.abspath(rootdir)
parser.add_argument( parser.add_argument(
"--rootdir", default=rootdir, help="root directory to examine") "--rootdir", default=rootdir, help="root directory to examine")
default_boilerplate_dir = os.path.join(rootdir, "csi-driver-smb/hack/boilerplate") default_boilerplate_dir = os.path.join(rootdir, "csi-driver-nfs/hack/boilerplate")
parser.add_argument( parser.add_argument(
"--boilerplate-dir", default=default_boilerplate_dir) "--boilerplate-dir", default=default_boilerplate_dir)

View File

@ -23,16 +23,15 @@ fi
export REGISTRY_NAME="$1" export REGISTRY_NAME="$1"
export REGISTRY=$REGISTRY_NAME.azurecr.io export REGISTRY=$REGISTRY_NAME.azurecr.io
export IMAGE_NAME=public/k8s/csi/smb-csi export IMAGE_NAME=gcr.io/k8s-staging-sig-storage/nfsplugin
export CI=1 export CI=1
export PUBLISH=1 export PUBLISH=1
az acr login --name $REGISTRY_NAME az acr login --name $REGISTRY_NAME
make smb-container make container
make push make push
make push-latest
echo "sleep 60s ..." echo "sleep 60s ..."
sleep 60 sleep 60
image="mcr.microsoft.com/k8s/csi/smb-csi:latest" image="gcr.io/k8s-staging-sig-storage/nfsplugin:latest"
docker pull $image docker pull $image
docker inspect $image | grep Created docker inspect $image | grep Created

View File

@ -18,13 +18,19 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
echo "Verifying boilerplate"
if [[ -z "$(command -v python)" ]]; then
echo "Cannot find python. Make link to python3..."
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
fi
REPO_ROOT=$(dirname "${BASH_SOURCE}")/.. REPO_ROOT=$(dirname "${BASH_SOURCE}")/..
boilerDir="${REPO_ROOT}/hack/boilerplate" boilerDir="${REPO_ROOT}/hack/boilerplate"
boiler="${boilerDir}/boilerplate.py" boiler="${boilerDir}/boilerplate.py"
files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT})) files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT} --verbose))
# Run boilerplate.py unit tests # Run boilerplate.py unit tests
unitTestOut="$(mktemp)" unitTestOut="$(mktemp)"
@ -40,4 +46,6 @@ if [[ ${#files_need_boilerplate[@]} -gt 0 ]]; then
done done
exit 1 exit 1
fi fi
echo "Done"

View File

@ -19,8 +19,11 @@ set -euo pipefail
if [[ -z "$(command -v golangci-lint)" ]]; then if [[ -z "$(command -v golangci-lint)" ]]; then
echo "Cannot find golangci-lint. Installing golangci-lint..." echo "Cannot find golangci-lint. Installing golangci-lint..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0
export PATH=$PATH:$(go env GOPATH)/bin
fi fi
echo "Verifying golint"
golangci-lint run --no-config --enable=golint --disable=typecheck --deadline=10m golangci-lint run --no-config --enable=golint --disable=typecheck --deadline=10m
echo "Congratulations! Lint check completed for all Go source files." echo "Congratulations! Lint check completed for all Go source files."

View File

@ -16,6 +16,7 @@
set -euo pipefail set -euo pipefail
echo "Verifying gomod"
export GO111MODULE=on export GO111MODULE=on
echo "go mod tidy" echo "go mod tidy"
go mod tidy go mod tidy

View File

@ -20,8 +20,8 @@ readonly PKG_ROOT="$(git rev-parse --show-toplevel)"
function get_image_from_helm_chart() { function get_image_from_helm_chart() {
local -r image_name="${1}" local -r image_name="${1}"
image_repository="$(cat ${PKG_ROOT}/charts/latest/csi-driver-smb/values.yaml | yq -r .image.${image_name}.repository)" image_repository="$(cat ${PKG_ROOT}/charts/latest/csi-driver-nfs/values.yaml | yq -r .image.${image_name}.repository)"
image_tag="$(cat ${PKG_ROOT}/charts/latest/csi-driver-smb/values.yaml | yq -r .image.${image_name}.tag)" image_tag="$(cat ${PKG_ROOT}/charts/latest/csi-driver-nfs/values.yaml | yq -r .image.${image_name}.tag)"
echo "${image_repository}:${image_tag}" echo "${image_repository}:${image_tag}"
} }
@ -37,13 +37,24 @@ function validate_image() {
echo "Comparing image version between helm chart and manifests in deploy folder" echo "Comparing image version between helm chart and manifests in deploy folder"
if [[ -z "$(command -v pip)" ]]; then
echo "Cannot find pip. Installing pip3..."
apt install python3-pip -y
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
fi
if [[ -z "$(command -v jq)" ]]; then
echo "Cannot find jq. Installing yq..."
apt install jq -y
fi
# jq-equivalent for yaml # jq-equivalent for yaml
pip install yq pip install yq
# Extract images from csi-smb-controller.yaml # Extract images from csi-nfs-controller.yaml
expected_csi_provisioner_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)" expected_csi_provisioner_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)" expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)" expected_nfs_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
csi_provisioner_image="$(get_image_from_helm_chart "csiProvisioner")" csi_provisioner_image="$(get_image_from_helm_chart "csiProvisioner")"
validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}" validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}"
@ -51,19 +62,19 @@ validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}"
liveness_probe_image="$(get_image_from_helm_chart "livenessProbe")" liveness_probe_image="$(get_image_from_helm_chart "livenessProbe")"
validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}" validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}"
smb_image="$(get_image_from_helm_chart "smb")" nfs_image="$(get_image_from_helm_chart "nfs")"
validate_image "${expected_smb_image}" "${smb_image}" validate_image "${expected_nfs_image}" "${nfs_image}"
# Extract images from csi-smb-node.yaml # Extract images from csi-nfs-node.yaml
expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)" expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
expected_node_driver_registrar="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)" expected_node_driver_registrar="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)" expected_nfs_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}" validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}"
node_driver_registrar="$(get_image_from_helm_chart "nodeDriverRegistrar")" node_driver_registrar="$(get_image_from_helm_chart "nodeDriverRegistrar")"
validate_image "${expected_node_driver_registrar}" "${node_driver_registrar}" validate_image "${expected_node_driver_registrar}" "${node_driver_registrar}"
validate_image "${expected_smb_image}" "${smb_image}" validate_image "${expected_nfs_image}" "${nfs_image}"
echo "Images in deploy/ matches those in the latest helm chart." echo "Images in deploy/ matches those in the latest helm chart."

View File

@ -19,8 +19,17 @@ if [[ -z "$(command -v yamllint)" ]]; then
fi fi
LOG=/tmp/yamllint.log LOG=/tmp/yamllint.log
helmPath=charts/latest/csi-driver-nfs/templates
for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/windows/*.yaml" "deploy/example/smb-provisioner/*.yaml" "deploy/example/metrics/*.yaml" echo "checking yaml files num ..."
deployDirNum=`ls deploy/*.yaml | wc -l`
helmDirNum=`ls $helmPath/*.yaml | grep -v serviceaccount | wc -l`
if [[ "${deployDirNum}" != "${helmDirNum}" ]]; then
echo "yaml file num($deployDirNum) under deploy/ not equal to num($helmDirNum) under $helmPath"
exit 1
fi
for path in "deploy/*.yaml"
do do
echo "checking yamllint under path: $path ..." echo "checking yamllint under path: $path ..."
yamllint -f parsable $path | grep -v "line too long" > $LOG yamllint -f parsable $path | grep -v "line too long" > $LOG
@ -33,4 +42,13 @@ do
fi fi
done done
echo "checking yamllint under path: $helmPath ..."
yamllint -f parsable $helmPath/*.yaml | grep -v "line too long" | grep -v "too many spaces inside braces" | grep -v "missing document start" | grep -v "syntax error" > $LOG
linecount=`cat $LOG | wc -l`
if [ $linecount -gt 0 ]; then
echo "yaml files under $helmPath/ are not linted, failed with: "
cat $LOG
exit 1
fi
echo "Congratulations! All Yaml files have been linted." echo "Congratulations! All Yaml files have been linted."

View File

@ -6,6 +6,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"fmt"
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/net/context" "golang.org/x/net/context"
"k8s.io/utils/mount" "k8s.io/utils/mount"
@ -31,6 +32,24 @@ func initTestController(t *testing.T) *ControllerServer {
return NewControllerServer(driver) return NewControllerServer(driver)
} }
func teardown() {
err := os.RemoveAll("/tmp/" + testCSIVolume)
if err != nil {
fmt.Printf(err.Error())
fmt.Printf("\n")
fmt.Printf("\033[1;91m%s\033[0m\n", "> Teardown failed")
} else {
fmt.Printf("\033[1;36m%s\033[0m\n", "> Teardown completed")
}
}
func TestMain(m *testing.M) {
code := m.Run()
teardown()
os.Exit(code)
}
func TestCreateVolume(t *testing.T) { func TestCreateVolume(t *testing.T) {
cases := []struct { cases := []struct {
name string name string