Skip to content

Commit 4b51ca6

Browse files
committed
added e2e test for operator resolution, fixed unit-test gh action running e2e tests
Signed-off-by: dtfranz <[email protected]>
1 parent 931493a commit 4b51ca6

File tree

4 files changed

+62
-49
lines changed

4 files changed

+62
-49
lines changed

.github/workflows/unit-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
3030
- name: Run basic unit tests
3131
run: |
32-
make test
32+
make test-unit

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ vet: ## Run go vet against code.
6767
go vet ./...
6868

6969
.PHONY: test test-e2e e2e kind-load kind-cluster kind-cluster-cleanup
70-
test: manifests generate fmt vet envtest test-e2e ## Run all tests.
71-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
70+
test: manifests generate fmt vet test-unit test-e2e ## Run all tests.
7271

7372
FOCUS := $(if $(TEST),-v -focus "$(TEST)")
7473
E2E_FLAGS ?= ""
7574
test-e2e: ginkgo ## Run the e2e tests
7675
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e
7776

77+
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
78+
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
79+
test-unit: envtest ## Run the unit tests
80+
eval $$($(ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out
81+
7882
e2e: KIND_CLUSTER_NAME=operator-controller-e2e
7983
e2e: run test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster
8084

test/e2e/install_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
10+
"k8s.io/apimachinery/pkg/util/rand"
11+
12+
. "github.com/onsi/ginkgo/v2"
13+
. "github.com/onsi/gomega"
14+
operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
15+
)
16+
17+
const (
18+
defaultTimeout = 30 * time.Second
19+
defaultPoll = 1 * time.Second
20+
)
21+
22+
var _ = Describe("Operator Install", func() {
23+
It("resolves the specified package with correct bundle path", func() {
24+
var (
25+
ctx context.Context = context.Background()
26+
pkgName string = "prometheus"
27+
operator *operatorv1alpha1.Operator = &operatorv1alpha1.Operator{
28+
ObjectMeta: metav1.ObjectMeta{
29+
Name: fmt.Sprintf("operator-%s", rand.String(8)),
30+
},
31+
Spec: operatorv1alpha1.OperatorSpec{
32+
PackageName: pkgName,
33+
},
34+
}
35+
)
36+
ctx = context.Background()
37+
By("creating the Operator resource")
38+
err := c.Create(ctx, operator)
39+
Expect(err).ToNot(HaveOccurred())
40+
41+
// TODO dfranz: This test currently relies on the hard-coded CatalogSources found in bundle_cache.go
42+
// and should be re-worked to use a real or test catalog source when the hard-coded stuff is removed
43+
By("eventually reporting a successful resolution and bundle path")
44+
Eventually(func(g Gomega) {
45+
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
46+
g.Expect(err).ToNot(HaveOccurred())
47+
g.Expect(len(operator.Status.Conditions)).To(Equal(1))
48+
g.Expect(operator.Status.Conditions[0].Message).To(Equal("resolution was successful"))
49+
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
50+
51+
By("deleting the Operator resource")
52+
err = c.Delete(ctx, operator)
53+
Expect(err).ToNot(HaveOccurred())
54+
})
55+
})

test/e2e/reconcile_test.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)