Skip to content

Commit

Permalink
added e2e test for operator resolution, fixed unit-test gh action run…
Browse files Browse the repository at this point in the history
…ning e2e tests (#103)

Signed-off-by: dtfranz <[email protected]>
  • Loading branch information
dtfranz authored Jan 27, 2023
1 parent 931493a commit 5541671
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- name: Run basic unit tests
run: |
make test
make test-unit
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
55 changes: 55 additions & 0 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
46 changes: 0 additions & 46 deletions test/e2e/reconcile_test.go

This file was deleted.

0 comments on commit 5541671

Please sign in to comment.