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

Add a framework for integration tests #1081

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
31 changes: 27 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,34 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.21.6
go-version: "1.21.6"
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
- name: Run build
run: go build -o haproxy-ingress pkg/main.go
- name: Run tests
run: go test ./...
run: make build
- name: Run unit tests
run: make test
integration:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install -y lua-json
- name: Install HAProxy
uses: timwolla/action-install-haproxy@main
id: install-haproxy
with:
branch: "2.2"
use_openssl: yes
use_lua: yes
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.21.6"
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
username: jcmoraisjr
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Run integration tests
run: make test-integration
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ KUBECONFIG?=$(HOME)/.kube/config
CONTROLLER_CONFIGMAP?=
CONTROLLER_ARGS?=

LOCALBIN?=$(shell pwd)/bin
LOCAL_GOTESTSUM=$(LOCALBIN)/gotestsum
LOCAL_SETUP_ENVTEST=$(LOCALBIN)/setup-envtest

.PHONY: build
build:
CGO_ENABLED=0 go build \
Expand All @@ -32,14 +36,28 @@ run: build
--configmap=$(CONTROLLER_CONFIGMAP)\
$(CONTROLLER_ARGS)

.PHONY: gotestsum
gotestsum:
test -x $(LOCAL_GOTESTSUM) || GOBIN=$(LOCALBIN) go install gotest.tools/gotestsum@latest

.PHONY: lint
lint:
golangci-lint run

.PHONY: test
test: lint
test: lint gotestsum
## fix race and add -race param
go test -tags cgo ./...
$(LOCAL_GOTESTSUM) --format=testname -- -tags=cgo ./pkg/...

.PHONY: setup-envtest
setup-envtest:
test -x $(LOCAL_SETUP_ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
$(LOCAL_SETUP_ENVTEST) use 1.29.1 --bin-dir $(LOCALBIN)

.PHONY: test-integration
test-integration: gotestsum setup-envtest
KUBEBUILDER_ASSETS="$(shell $(LOCAL_SETUP_ENVTEST) use 1.29.1 --bin-dir $(LOCALBIN) -i -p path)"\
$(LOCAL_GOTESTSUM) --format=testname -- -count=1 -tags=cgo ./tests/integration/...

.PHONY: linux-build
linux-build:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ The following `make` targets are supported:

* `build` (default): Compiles HAProxy Ingress using the default OS and arch, and generates an executable at `bin/controller`.
* `run`: Runs HAProxy Ingress locally.
* `lint`: Runs [`golangci-lint`](https://golangci-lint.run/).
* `lint`: Runs [`golangci-lint`](https://golangci-lint.run/), needs golangci-lint in the path.
* `test`: Runs unit tests.
* `test-integration`: Runs integration tests, needs haproxy 2.2+ in the path.
* `linux-build`: Compiles HAProxy Ingress and generates an ELF (Linux) executable despite the source platform at `rootfs/haproxy-ingress-controller`. Used by `image` step.
* `image`: Compiles HAProxy Ingress locally and generates a Docker image.
* `docker-build`: Compiles HAProxy Ingress and generates a Docker image using a multi-stage Dockerfile.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.18.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.21.0
gopkg.in/go-playground/pool.v3 v3.1.1
Expand Down Expand Up @@ -58,6 +59,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
Expand Down
Loading
Loading