Skip to content

Commit

Permalink
Add unit testing makefile target
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <omachace@redhat.com>
  • Loading branch information
machacekondra committed Oct 15, 2024
1 parent f7e87ad commit 12331a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
29 changes: 5 additions & 24 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,16 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5

- name: Test
- name: Prepare
run: |
touch rhcos-live.x86_64.iso
make generate
make build
DOWNLOAD_RHCOS=false make build
- name: Test
run: |
make test
- name: Checking generated files are up to date
run: |
if [[ $(git ls-files --others --exclude-standard) ]]; then git ls-files --others --exclude-standard; echo "These files are not tracked by git"; exit 1; fi
if [ -n "$(git status --porcelain)" ]; then echo "There are uncommitted changes:"; git status --short; exit 1; fi
Lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6.1.1
with:
args: --timeout=2m

YamlLint:
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4
- name: 🚀 Run yamllint
run: |
yamllint -f github -c .yamllint .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ examples/config.ign
examples/config.yaml
*.local.*
/tmp/
cover.out
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ MIGRATION_PLANNER_AGENT_IMAGE ?= quay.io/kubev2v/migration-planner-agent
MIGRATION_PLANNER_COLLECTOR_IMAGE ?= quay.io/kubev2v/migration-planner-collector
MIGRATION_PLANNER_API_IMAGE ?= quay.io/kubev2v/migration-planner-api
MIGRATION_PLANNER_UI_IMAGE ?= quay.io/kubev2v/migration-planner-ui
DOWNLOAD_RHCOS ?= true

SOURCE_GIT_TAG ?=$(shell git describe --always --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT)')
SOURCE_GIT_TREE_STATE ?=$(shell ( ( [ ! -d ".git/" ] || git diff --quiet ) && echo 'clean' ) || echo 'dirty')
Expand Down Expand Up @@ -42,6 +43,18 @@ help:
@echo " build: run all builds"
@echo " clean: clean up all containers and volumes"

GOBIN = $(shell pwd)/bin
GINKGO = $(GOBIN)/ginkgo
ginkgo: ## Download ginkgo locally if necessary.
ifeq (, $(shell which ginkgo 2> /dev/null))
go install -v github.com/onsi/ginkgo/v2/ginkgo@v2.15.0
endif

TEST_PACKAGES := ./...
GINKGO_OPTIONS ?= --skip e2e
test: ginkgo
$(GINKGO) --cover -output-dir=. -coverprofile=cover.out -v --show-node-events $(GINKGO_OPTIONS) $(TEST_PACKAGES)

generate:
go generate -v $(shell go list ./...)
hack/mockgen.sh
Expand All @@ -50,10 +63,12 @@ tidy:
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && go mod tidy'

lint: tools
$(GOBIN)/golangci-lint run -v
$(GOBIN)/golangci-lint run -v --timeout 2m

image:
ifeq ($(DOWNLOAD_RHCOS), true)
curl --silent -C - -O https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso
endif

build: bin image
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/...
Expand Down

0 comments on commit 12331a5

Please sign in to comment.