Skip to content

Commit 0b899f4

Browse files
committed
Add test target
This adds the test target to run the required tests. The test target can be invoked via: `make -f Next.mk test`. This target runs test via bazel. The bazel command is provided via bazelisk so we can pick up the right bazel version (hint: .bazelversion). Before running the test, we generate the required *.go files via tests_harness_cases_go (which is a dependency of test target). This patch adds test target invocation in the workflow, also sets up the corresponding caching mechanism for bazel. Signed-off-by: Dhi Aurrahman <[email protected]>
1 parent 0eae5da commit 0b899f4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

.github/workflows/commit.yaml

+11-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ jobs:
3030
go-version: "1.19.3"
3131
cache: true
3232

33+
- name: Download cache for bazel
34+
uses: actions/cache@v3
35+
with:
36+
path: "~/.cache/bazel"
37+
key: test-${{ runner.os }}-bazel-cache
38+
3339
- name: "Generate *.pb.go and build the plugin binary"
34-
run: make -f Next.mk clean build # we do "clean build" here, hence *.pb.go is regenerated.
40+
run: make -f Next.mk clean build # we do "clean build" here, hence validate.pb.go is regenerated.
3541

3642
- name: "Verify clean check-in"
37-
run: make -f Next.mk check
43+
run: make -f Next.mk check # we do verification after validate.pb.go is regenerated.
44+
45+
- name: "Run tests"
46+
run: make -f Next.mk test

Next.mk

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export PATH := $(root_dir)$(current_binary_path):$(go_tools_dir)/bin:$(prepackag
3131
# The main generated file.
3232
validate_pb_go := validate/validate.pb.go
3333

34+
# List of harness test cases.
35+
tests_harness_cases := \
36+
/harness \
37+
/harness/cases \
38+
/harness/cases/other_package \
39+
/harness/cases/yet_another_package
40+
3441
# Include versions of tools we build on-demand
3542
include Tools.mk
3643
# This provides the "help" target.
@@ -42,8 +49,12 @@ include tools/build/Env.mk
4249
protoc := $(prepackaged_tools_dir)/bin/protoc
4350

4451
# Go based tools.
52+
bazel := $(go_tools_dir)/bin/bazelisk
4553
protoc-gen-go := $(go_tools_dir)/bin/protoc-gen-go
4654

55+
test: $(bazel) $(tests_harness_cases) ## Run tests
56+
@$(bazel) test //tests/... --test_output=errors
57+
4758
build: $(current_binary) ## Build the plugin
4859

4960
clean: ## Clean all build and test artifacts
@@ -65,4 +76,22 @@ $(validate_pb_go): $(protoc) $(protoc-gen-go) validate/validate.proto
6576
build/$(name)_%/$(name)$(goexe): $(validate_pb_go)
6677
@GOBIN=$(root_dir)$(current_binary_path) $(go) install .
6778

79+
# Generate all required files for harness tests in Go.
80+
$(tests_harness_cases): $(current_binary)
81+
$(call generate-test-cases-go,tests$@)
82+
83+
# Generates a test-case for Go.
84+
define generate-test-cases-go
85+
@cd $1 && \
86+
mkdir -p go && \
87+
$(protoc) \
88+
-I . \
89+
-I $(root_dir) \
90+
--go_opt=paths=source_relative \
91+
--go_out=go \
92+
--validate_opt=paths=source_relative \
93+
--validate_out=lang=go:go \
94+
*.proto
95+
endef
96+
6897
include tools/build/Installer.mk

Tools.mk

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Licensed under the Apache License, Version 2.0 (the "License")
22

3+
bazelisk@v := github.com/bazelbuild/[email protected]
34
protoc@v := github.com/protocolbuffers/[email protected]
45
protoc-gen-go@v := google.golang.org/protobuf/cmd/[email protected]

0 commit comments

Comments
 (0)