From 5541671b3f1b2826180627e887a315ebebe97308 Mon Sep 17 00:00:00 2001 From: Daniel Franz Date: Fri, 27 Jan 2023 13:40:16 -0800 Subject: [PATCH] added e2e test for operator resolution, fixed unit-test gh action running e2e tests (#103) Signed-off-by: dtfranz --- .github/workflows/unit-test.yaml | 2 +- Makefile | 8 +++-- test/e2e/install_test.go | 55 ++++++++++++++++++++++++++++++++ test/e2e/reconcile_test.go | 46 -------------------------- 4 files changed, 62 insertions(+), 49 deletions(-) create mode 100644 test/e2e/install_test.go delete mode 100644 test/e2e/reconcile_test.go diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index c32bb5c34..6c3f99fbf 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -29,4 +29,4 @@ jobs: - name: Run basic unit tests run: | - make test + make test-unit diff --git a/Makefile b/Makefile index 15215f9ee..398ff957e 100644 --- a/Makefile +++ b/Makefile @@ -67,14 +67,18 @@ vet: ## Run go vet against code. go vet ./... .PHONY: test test-e2e e2e kind-load kind-cluster kind-cluster-cleanup -test: manifests generate fmt vet envtest test-e2e ## Run all tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out +test: manifests generate fmt vet test-unit test-e2e ## Run all tests. FOCUS := $(if $(TEST),-v -focus "$(TEST)") E2E_FLAGS ?= "" test-e2e: ginkgo ## Run the e2e tests $(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e +ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/') +UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/) +test-unit: envtest ## Run the unit tests + eval $$($(ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out + e2e: KIND_CLUSTER_NAME=operator-controller-e2e e2e: run test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster diff --git a/test/e2e/install_test.go b/test/e2e/install_test.go new file mode 100644 index 000000000..260a4f454 --- /dev/null +++ b/test/e2e/install_test.go @@ -0,0 +1,55 @@ +package e2e + +import ( + "context" + "fmt" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/rand" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" +) + +const ( + defaultTimeout = 30 * time.Second + defaultPoll = 1 * time.Second +) + +var _ = Describe("Operator Install", func() { + It("resolves the specified package with correct bundle path", func() { + var ( + ctx context.Context = context.Background() + pkgName string = "prometheus" + operator *operatorv1alpha1.Operator = &operatorv1alpha1.Operator{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("operator-%s", rand.String(8)), + }, + Spec: operatorv1alpha1.OperatorSpec{ + PackageName: pkgName, + }, + } + ) + ctx = context.Background() + By("creating the Operator resource") + err := c.Create(ctx, operator) + Expect(err).ToNot(HaveOccurred()) + + // TODO dfranz: This test currently relies on the hard-coded CatalogSources found in bundle_cache.go + // and should be re-worked to use a real or test catalog source when the hard-coded stuff is removed + By("eventually reporting a successful resolution and bundle path") + Eventually(func(g Gomega) { + err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(len(operator.Status.Conditions)).To(Equal(1)) + g.Expect(operator.Status.Conditions[0].Message).To(Equal("resolution was successful")) + }).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed()) + + By("deleting the Operator resource") + err = c.Delete(ctx, operator) + Expect(err).ToNot(HaveOccurred()) + }) +}) diff --git a/test/e2e/reconcile_test.go b/test/e2e/reconcile_test.go deleted file mode 100644 index d2b993d55..000000000 --- a/test/e2e/reconcile_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package e2e - -import ( - "context" - "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/rand" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" -) - -var _ = Describe("Operator Install", func() { - When("a valid Operator CR specifying a package", func() { - var ( - operator *operatorv1alpha1.Operator - ctx context.Context - err error - ) - BeforeEach(func() { - ctx = context.Background() - - operator = &operatorv1alpha1.Operator{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("operator-%s", rand.String(8)), - }, - Spec: operatorv1alpha1.OperatorSpec{ - PackageName: "my-cool-package", - }, - } - err = c.Create(ctx, operator) - Expect(err).To(Not(HaveOccurred())) - }) - AfterEach(func() { - By("deleting the testing Operator resource") - err = c.Delete(ctx, operator) - Expect(err).To(Not(HaveOccurred())) - }) - PIt("installs the specified package", func() { - // Pending until we actually have some code to test - // Expect that a CRD and Deployment were successfully installed by rukpak - }) - }) -})