Skip to content

Commit

Permalink
Makefile,test: Support configuring the e2e testdata directory
Browse files Browse the repository at this point in the history
Signed-off-by: timflannagan <timflannagan@gmail.com>
  • Loading branch information
timflannagan committed Mar 25, 2022
1 parent fbbda25 commit f2a3f26
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ e2e:
# See workflows/e2e-tests.yml See test/e2e/README.md for details.
.PHONY: e2e-local
e2e-local: BUILD_TAGS="json1 experimental_metrics"
e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar
e2e-local: extra_args=-kind.images=../test/e2e-local.image.tar -test-data-dir=../test/e2e/testdata
e2e-local: run=bin/e2e-local.test
e2e-local: bin/e2e-local.test test/e2e-local.image.tar
e2e-local: e2e
Expand Down
14 changes: 12 additions & 2 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ var (
communityOperators = flag.String(
"communityOperators",
"quay.io/operator-framework/upstream-community-operators@sha256:098457dc5e0b6ca9599bd0e7a67809f8eca397907ca4d93597380511db478fec",
"reference to upstream-community-operators image")
"reference to upstream-community-operators image",
)

dummyImage = flag.String(
"dummyImage",
"bitnami/nginx:latest",
"dummy image to treat as an operator in tests")
"dummy image to treat as an operator in tests",
)

testdataPath = flag.String(
"test-data-dir",
"./testdata",
"configures where to find the testdata directory",
)

testdataDir = ""
testNamespace = ""
operatorNamespace = ""
communityOperatorsImage = ""
Expand Down Expand Up @@ -74,6 +83,7 @@ var _ = BeforeSuite(func() {
testNamespace = *namespace
operatorNamespace = *olmNamespace
communityOperatorsImage = *communityOperators
testdataDir = *testdataPath
deprovision = ctx.MustProvision(ctx.Ctx())
ctx.MustInstall(ctx.Ctx())

Expand Down
9 changes: 7 additions & 2 deletions test/e2e/fbc_provider.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package e2e

import (
"io/ioutil"
"errors"
"fmt"
"os"
)

type FileBasedCatalogProvider interface {
Expand All @@ -13,7 +15,10 @@ type fileBasedFileBasedCatalogProvider struct {
}

func NewFileBasedFiledBasedCatalogProvider(path string) (FileBasedCatalogProvider, error) {
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if errors.Is(err, os.ErrNotExist) {
return nil, fmt.Errorf("path %s does not exist: %w", path, err)
}
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/magic_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"path/filepath"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -27,7 +28,7 @@ var _ = Describe("MagicCatalog", func() {
const catalogName = "test"
namespace := generatedNamespace.GetName()
kubeClient := ctx.Ctx().Client()
provider, err := NewFileBasedFiledBasedCatalogProvider("../test/e2e/testdata/fbc_catalog.json")
provider, err := NewFileBasedFiledBasedCatalogProvider(filepath.Join(testdataDir, "fbc_catalog.json"))
Expect(err).To(BeNil())

// create and deploy and undeploy the magic catalog
Expand Down

0 comments on commit f2a3f26

Please sign in to comment.