Skip to content

Commit

Permalink
feat(tests): move dumper binary to bin & add support to run tests und…
Browse files Browse the repository at this point in the history
…er arm64 arch
  • Loading branch information
ArtemTrofimushkin committed Oct 22, 2021
1 parent a2b1d6d commit 915d118
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ test-unit:

.PHONY: test-integration
test-integration:
./hacks/run-integration-tests.sh
./hacks/run-integration-tests.sh amd64

.PHONY: test-integration-arm64
test-integration-arm64:
./hacks/run-integration-tests.sh arm64

.PHONY: tidy
tidy:
Expand All @@ -47,12 +51,13 @@ help:
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@echo " ${YELLOW}cover ${RESET} Open html coverage report in browser"
@echo " ${YELLOW}doc ${RESET} Run doc generation"
@echo " ${YELLOW}lint ${RESET} Run linters via golangci-lint"
@echo " ${YELLOW}prepare ${RESET} Run all available checks and generators"
@echo " ${YELLOW}setup ${RESET} Setup local environment. Create kind cluster"
@echo " ${YELLOW}test ${RESET} Run all available tests"
@echo " ${YELLOW}test-integration ${RESET} Run all integration tests"
@echo " ${YELLOW}test-unit ${RESET} Run all unit tests"
@echo " ${YELLOW}tidy ${RESET} Run tidy for go module to remove unused dependencies"
@echo " ${YELLOW}cover ${RESET} Open html coverage report in browser"
@echo " ${YELLOW}doc ${RESET} Run doc generation"
@echo " ${YELLOW}lint ${RESET} Run linters via golangci-lint"
@echo " ${YELLOW}prepare ${RESET} Run all available checks and generators"
@echo " ${YELLOW}setup ${RESET} Setup local environment. Create kind cluster"
@echo " ${YELLOW}test ${RESET} Run all available tests"
@echo " ${YELLOW}test-integration ${RESET} Run all integration tests (for amd64 arch)"
@echo " ${YELLOW}test-integration-arm64 ${RESET} Run all integration tests (for arm64 arch)"
@echo " ${YELLOW}test-unit ${RESET} Run all unit tests"
@echo " ${YELLOW}tidy ${RESET} Run tidy for go module to remove unused dependencies"
8 changes: 5 additions & 3 deletions dumper/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic as tools-install
ARG ARCH=

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic${ARCH} as tools-install

RUN dotnet tool install -g dotnet-gcdump && \
dotnet tool install -g dotnet-trace

FROM mcr.microsoft.com/dotnet/core/runtime:3.1
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-bionic${ARCH}

ARG DOTNET_TOOLS_PATH="/root/.dotnet/tools"
ENV PATH="${PATH}:${DOTNET_TOOLS_PATH}"
WORKDIR /app

COPY --from=tools-install ${DOTNET_TOOLS_PATH} ${DOTNET_TOOLS_PATH}

COPY ./dumper ./
COPY ./bin/dumper ./

ENTRYPOINT [ "/app/dumper" ]
26 changes: 18 additions & 8 deletions hacks/run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
#!/bin/bash
set -o errexit

script_dir="$( dirname "${BASH_SOURCE[0]}" )"
script_dir="$(dirname "${BASH_SOURCE[0]}")"
project_dir="${script_dir}/.."

kind_context="kind-kind"
current_context=$(kubectl config current-context)

if [ "${current_context}" != "${kind_context}" ]
then
if [ "${current_context}" != "${kind_context}" ]; then
echo "Your context is wrong. Use ${kind_context}"
exit 1
fi

arch=${1:-amd64}
if [ "$arch" == "amd64" ]; then
docker_build_args=""
elif [ "$arch" == "arm64" ]; then
docker_build_args="--build-arg ARCH=-arm64v8"
else
echo "Unsupported arch, choose from: amd64 or arm64"
exit 1
fi

echo "Building dumper..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
GOOS=linux GOARCH=$arch CGO_ENABLED=0 \
go build -v \
-o ${project_dir}/dumper/dumper \
-o ${project_dir}/dumper/bin/dumper \
${project_dir}/dumper

image_tag="latest"
Expand All @@ -26,8 +35,9 @@ echo "Building dumper's image..."
docker build \
-t ${image_repository}:${image_tag} \
-f "${project_dir}/dumper/Dockerfile" \
$docker_build_args \
"${project_dir}/dumper"
rm "${project_dir}/dumper/dumper"
rm "${project_dir}/dumper/bin/dumper"

echo "Loading dumper's image to kind cluster..."
kind load docker-image ${image_repository}:${image_tag}
Expand All @@ -36,8 +46,8 @@ echo "Running tests..."
go test -v \
--tags=integration \
-timeout 300s \
./test/integration/... | \
sed "/PASS/s//$(printf "\033[32mPASS\033[0m")/" | \
./test/integration/... |
sed "/PASS/s//$(printf "\033[32mPASS\033[0m")/" |
sed "/FAIL/s//$(printf "\033[31mFAIL\033[0m")/"

exit ${PIPESTATUS[0]}

0 comments on commit 915d118

Please sign in to comment.