Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller tests setup #495

Merged
merged 3 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
live-wire marked this conversation as resolved.
Show resolved Hide resolved
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