Skip to content

Commit

Permalink
Controller tests setup (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
live-wire authored Oct 19, 2022
1 parent d60e6a0 commit 818b5f9
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 172 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ RESOURCE_PREFIX ?= flink-operator-
# The Kubernetes namespace to limit watching.
WATCH_NAMESPACE ?=

# Env test configuration
ENVTEST_K8S_VERSION=1.25.0
SETUP_ENVTEST_VERSION=v0.0.0-20221007015352-8ad090e0663e
LOCALBIN=$(shell pwd)/bin

all: build

##@ General
Expand Down Expand Up @@ -56,8 +61,7 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet tidy kustomize envtest ## Run tests.
rm -rf config/test && mkdir -p config/test/crd
$(KUSTOMIZE) build config/crd > config/test/crd/flinkoperator.k8s.io_flinkclusters.yaml
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path) go test ./... -coverprofile cover.out
##@ Build

build: generate fmt vet tidy ## Build manager binary.
Expand Down Expand Up @@ -125,7 +129,8 @@ kustomize: ## Download kustomize locally if necessary.
ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION))


CRD_REF_DOCS = $(shell pwd)/bin/crd-ref-docs
crd-ref-docs:
Expand Down
40 changes: 40 additions & 0 deletions controllers/flinkcluster/flinkcluster_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package flinkcluster

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/types"
"time"
)

var _ = Describe("FlinkCluster Controller", func() {
// Utility constants and functions here
const (
timeout = time.Second * 10
duration = time.Second * 10
interval = time.Millisecond * 250
)

Context("When creating a new FlinkCluster", func() {
It("Should create the JobManager Statefulset", func() {
// Test code here
By("By creating a new FlinkCluster")
dummyFlinkCluster := getDummyFlinkCluster()
Expect(k8sClient.Create(ctx, dummyFlinkCluster)).Should(Succeed())

expectedJobManagerName := dummyFlinkCluster.ObjectMeta.Name + "-jobmanager"
jobManagerLookupKey := types.NamespacedName{Name: expectedJobManagerName, Namespace: dummyFlinkCluster.ObjectMeta.Namespace}
createdJobManagerStatefulSet := &appsv1.StatefulSet{}

Eventually(func() bool {
err := k8sClient.Get(ctx, jobManagerLookupKey, createdJobManagerStatefulSet)
if err != nil {
return false
}
return true
}, timeout, interval).Should(BeTrue())

})
})
})
Loading

0 comments on commit 818b5f9

Please sign in to comment.