Skip to content

Commit

Permalink
Add test check
Browse files Browse the repository at this point in the history
  • Loading branch information
sergicastro committed Mar 27, 2024
1 parent 3f79c6a commit 873891d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build

on:
push:
branches:
- main
- release-**
pull_request:
branches:
- main
- release-**

env:
GOPROXY: https://proxy.golang.org

jobs:
test:
runs-on: ubuntu-latest
env:
IMG: local/kubegres:test
PLATFORMS: linux/amd64
steps:
- uses: docker/setup-qemu-action@v3
with:
platforms: amd64
- uses: docker/setup-buildx-action@v3
- uses: actions/checkout@v4
- run: make kind test
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: build envtest ## Run tests.
go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s
KIND_EXEC_PATH=$(KIND) go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -test.timeout 10000s
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell pwd)/test -run $(shell pwd)/test/suite_test.go -v -coverprofile cover.out -test.timeout 10000s
#KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test test/suite_test.go -coverprofile cover.out -v -test.timeout 10000s

Expand Down Expand Up @@ -145,10 +145,12 @@ $(LOCALBIN):
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
KIND ?= $(LOCALBIN)/kind

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.9.2
KIND_VERSION ?= v0.22.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -165,3 +167,8 @@ $(CONTROLLER_GEN): $(LOCALBIN)
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary.
$(KIND): $(LOCALBIN)
test -s $(LOCALBIN)/kind || GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind@$(KIND_VERSION)
23 changes: 15 additions & 8 deletions test/util/kindcluster/KindTestClusterUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (

const clusterName = "kubegres"

var kindExecPath = os.Getenv("KIND_EXEC_PATH")

type KindTestClusterUtil struct {
kindExecPath string
}
Expand All @@ -39,15 +41,20 @@ func (r *KindTestClusterUtil) StartCluster() {

log.Println("STARTING KIND CLUSTER '" + clusterName + "'")

// start kind cluster
var err error
r.kindExecPath, err = exec.LookPath("kind")
if err != nil {
log.Fatal("We cannot find the executable 'kind'. " +
"Make sure 'kind' is installed and the executable 'kind' " +
"is in the classpath before running the tests.")
// define kind executable path or find it
if kindExecPath != "" {
r.kindExecPath = kindExecPath
} else {
var err error
r.kindExecPath, err = exec.LookPath("kind")
if err != nil {
log.Fatal("We cannot find the executable 'kind'. " +
"Make sure 'kind' is installed and the executable 'kind' " +
"is in the classpath before running the tests.")
}
}

// start kind cluster
if r.isClusterRunning() {
log.Println("Cluster is already running. No need to restart it.")
r.installOperator()
Expand All @@ -66,7 +73,7 @@ func (r *KindTestClusterUtil) StartCluster() {
Stderr: os.Stdout,
}

err = cmdStartCluster.Run()
err := cmdStartCluster.Run()
if err != nil {
log.Fatal("Unable to execute the command 'kind create cluster --name "+clusterName+" --config "+clusterConfigFilePath+"'", err)
} else {
Expand Down

0 comments on commit 873891d

Please sign in to comment.