Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make bats tests run faster #502

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ teardown-integration-test: undeploy ## Teardown the integration test setup
rm -rf $(TF_VAULT_STATE_DIR)

.PHONY: unit-test
unit-test: bats-parallel ## Run unit tests for the helm chart
PATH="$(CURDIR)/scripts:$(PATH)" bats $(BATS_PARALLEL_ARGS) -f $(BATS_TESTS_FILTER) test/unit/
unit-test: bats-parallel yq ## Run unit tests for the helm chart
PATH="$(CURDIR)/bin:$(CURDIR)/scripts:$(PATH)" bats $(BATS_PARALLEL_ARGS) -f $(BATS_TESTS_FILTER) test/unit/

.PHONY: port-forward
port-forward:
Expand Down Expand Up @@ -579,6 +579,10 @@ copywrite: ## Download copywrite locally if necessary.
@./hack/install_copywrite.sh
$(eval COPYWRITE=./bin/copywrite)

.PHONY: yq
yq: ## Download yq locally if necessary.
@./hack/install_yq.sh

.PHONY: crd-ref-docs
CRD_REF_DOCS = ./bin/crd-ref-docs
crd-ref-docs: ## Install crd-ref-docs locally if necessary.
Expand Down Expand Up @@ -641,5 +645,5 @@ ifneq (,$(shell which parallel 2>/dev/null))
endif

.PHONY: check-versions
check-versions:
check-versions: yq
VERSION=$(VERSION) KUBE_RBAC_PROXY_VERSION=$(KUBE_RBAC_PROXY_VERSION) ./scripts/check-versions.sh
44 changes: 44 additions & 0 deletions hack/install_yq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

# Script to install the mikefarah/yq tool to the bin directory.
# It ensures that only one copy of yq exists, and its version
# matches YQ_VERSION.
. ${0%/*}/.functions

set -e -o pipefail

YQ_VERSION="${YQ_VERSION-v4.40.4}"

pushd "$(git rev-parse --show-toplevel || echo .)" > /dev/null
dest_filename="yq-${YQ_VERSION}"
dest_file="bin/${dest_filename}"
if [ -f "${dest_file}" ]; then
ln -sf "${dest_filename}" "${dest_file%/*}/yq"
exit 0
fi

eval $(go env | egrep '^(GOOS|GOARCH)')
binary="yq_${GOOS}_${GOARCH}"
base_url="https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}"

tempdir=$(mktemp -d)
function cleanup {
rm -rf "${tempdir}"
}
trap cleanup EXIT SIGINT

# unfortunately the project has bizarre way of presenting checksums of their binaries, in this case
# we are implicitly trusting their released artifacts, as we would do for go install ...
pushd $tempdir > /dev/null
getGH "${base_url}/${binary}" yq
chmod +x yq
popd > /dev/null

rm -f "${dest_file%/*}"/yq*
mkdir -p bin/
mv "${tempdir}/yq" "${dest_file}"
ln -sf "${dest_filename}" "${dest_file%/*}/yq"

popd > /dev/null
7 changes: 5 additions & 2 deletions hack/set_containerImage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash -e
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
#
set -e -o pipefail

# Set the annotation `containerImage` in
# bundle/manifests/vault-secrets-operator.clusterserviceversion.yaml to the
Expand All @@ -9,7 +11,8 @@
BUILD_DIR="${BUILD_DIR:-build}"
HACK_DIR=$(dirname "$0")
CSV_FILE=${HACK_DIR}/../${BUILD_DIR}/bundle/manifests/vault-secrets-operator.clusterserviceversion.yaml
YQ=${HACK_DIR}/../scripts/yq
# bin/yq is installed by running 'make yq'
YQ=${HACK_DIR}/../bin/yq

IMAGE=$(cat ${CSV_FILE} | ${YQ} '.spec.install.spec.deployments.[] | select(.name == "vault-secrets-operator-controller-manager") | .spec.template.spec.containers.[] | select(.name == "manager") | .image')

Expand Down
2 changes: 1 addition & 1 deletion scripts/check-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ esac

ROOT_DIR="${0%/*}"
# update PATH to prefer scripts relative to this one e.g. yq
export PATH="${ROOT_DIR}:${PATH}"
export PATH="${ROOT_DIR}:${ROOT_DIR}/../bin:${PATH}"

CHART_ROOT="${CHART_ROOT-$(readlink -f ${ROOT_DIR}/../chart)}"
KUSTOMIZE_ROOT="${KUSTOMIZE_ROOT-$(readlink -f ${ROOT_DIR}/../config)}"
Expand Down
11 changes: 0 additions & 11 deletions scripts/yq

This file was deleted.