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

Added e2e test for operator resolution #103

Merged
merged 1 commit into from
Jan 27, 2023
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package e2e_test

??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think package e2e is fine - there's only tests and test tooling here...no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's right, I feel like I usually just see that convention when we have actualpkg and then when we test it actualpkg_test


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.