Skip to content

Commit

Permalink
tekton: add go-unit-tests and golangci lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips committed Dec 19, 2024
1 parent c23cce7 commit 3bbdcca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
47 changes: 46 additions & 1 deletion .tekton/instaslice-operator-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,50 @@ spec:
workspace: git-auth
- name: netrc
workspace: netrc
- name: lint
runAfter:
- prefetch-dependencies
tasks:
image: golangci/golangci-lint:v1.62.2
workingDir: $(workspaces.source.path)
computeResources:
limits:
memory: 3Gi
cpu: 2000m
requests:
memory: 3Gi
cpu: 2000m
script: |
#!/usr/bin/env bash
set -eux
GOLANGCI_LINT=golangci-lint make lint-no-download
when:
- input: $(tasks.init.results.build)
operator: in
values:
- "true"
- name: unit
runAfter:
- prefetch-dependencies
tasks:
image: golang:1.22
workingDir: $(workspaces.source.path)
computeResources:
limits:
memory: 3Gi
cpu: 2000m
requests:
memory: 3Gi
cpu: 2000m
script: |
#!/usr/bin/env bash
set -eux
make test-unit
when:
- input: $(tasks.init.results.build)
operator: in
values:
- "true"
- matrix:
params:
- name: PLATFORM
Expand Down Expand Up @@ -231,7 +275,8 @@ spec:
- name: IMAGE_APPEND_PLATFORM
value: "true"
runAfter:
- prefetch-dependencies
- lint
- unit
taskRef:
params:
- name: name
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out

.PHONY: test-unit
test-unit: envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v $$(go list ./... | grep -v /e2e)

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
Expand Down Expand Up @@ -196,7 +200,7 @@ deploy-instaslice-emulated-on-ocp:
export KUBECTL=oc IMG=$(IMG) IMG_DMST=$(IMG_DMST) && \
hack/deploy-instaslice-emulated-on-ocp.sh

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT ?= $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.61.0
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
Expand All @@ -206,7 +210,11 @@ golangci-lint:

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
$(GOLANGCI_LINT) run
$(GOLANGCI_LINT) run --timeout 7m

.PHONY: lint-no-download
lint-no-download:
$(GOLANGCI_LINT) run --timeout 7m

.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
Expand Down

0 comments on commit 3bbdcca

Please sign in to comment.