Skip to content
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
3 changes: 2 additions & 1 deletion test/catalogd-e2e/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"k8s.io/apimachinery/pkg/types"

catalogdv1 "github.com/operator-framework/operator-controller/catalogd/api/v1"
testutils "github.com/operator-framework/operator-controller/test/utils"
)

const (
Expand Down Expand Up @@ -76,7 +77,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
Expect(catalog.ObjectMeta.Labels).To(HaveKeyWithValue("olm.operatorframework.io/metadata.name", catalogName))

By("Making sure the catalog content is available via the http server")
actualFBC, err := ReadTestCatalogServerContents(ctx, catalog, c, kubeClient)
actualFBC, err := testutils.ReadTestCatalogServerContents(ctx, catalog, kubeClient)
Expect(err).To(Not(HaveOccurred()))

expectedFBC, err := os.ReadFile("../../catalogd/testdata/catalogs/test-catalog/expected_all.json")
Expand Down
51 changes: 0 additions & 51 deletions test/catalogd-e2e/util.go

This file was deleted.

4 changes: 2 additions & 2 deletions test/catalogd-upgrade-e2e/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

catalogdv1 "github.com/operator-framework/operator-controller/catalogd/api/v1"
catalogde2e "github.com/operator-framework/operator-controller/test/catalogd-e2e"
testutils "github.com/operator-framework/operator-controller/test/utils"
)

var _ = Describe("ClusterCatalog Unpacking", func() {
Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() {

By("Making sure the catalog content is available via the http server")
Eventually(func(g Gomega) {
actualFBC, err := catalogde2e.ReadTestCatalogServerContents(ctx, catalog, c, kubeClient)
actualFBC, err := testutils.ReadTestCatalogServerContents(ctx, catalog, kubeClient)
g.Expect(err).To(Not(HaveOccurred()))
g.Expect(cmp.Diff(expectedFBC, actualFBC)).To(BeEmpty())
}).Should(Succeed())
Expand Down
46 changes: 46 additions & 0 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package utils

import (
"context"
"fmt"
"io"
"net/url"
"os/exec"
"strings"
"testing"

"k8s.io/client-go/kubernetes"

catalogdv1 "github.com/operator-framework/operator-controller/catalogd/api/v1"
)

// FindK8sClient returns the first available Kubernetes CLI client from the system,
Expand All @@ -21,3 +30,40 @@ func FindK8sClient(t *testing.T) string {
t.Fatal("k8s client not found")
return ""
}

func ReadTestCatalogServerContents(ctx context.Context, catalog *catalogdv1.ClusterCatalog, kubeClient kubernetes.Interface) ([]byte, error) {
if catalog == nil {
return nil, fmt.Errorf("cannot read nil catalog")
}
if catalog.Status.URLs == nil {
return nil, fmt.Errorf("catalog %q has no catalog urls", catalog.Name)
}
url, err := url.Parse(catalog.Status.URLs.Base)
if err != nil {
return nil, fmt.Errorf("error parsing clustercatalog url %q: %v", catalog.Status.URLs.Base, err)
}
// url is expected to be in the format of
// http://{service_name}.{namespace}.svc/catalogs/{catalog_name}/
// so to get the namespace and name of the service we grab only
// the hostname and split it on the '.' character
ns := strings.Split(url.Hostname(), ".")[1]
name := strings.Split(url.Hostname(), ".")[0]
port := url.Port()
// the ProxyGet() call below needs an explicit port value, so if
// value from url.Port() is empty, we assume port 443.
if port == "" {
if url.Scheme == "https" {
port = "443"
} else {
port = "80"
}
}
resp := kubeClient.CoreV1().Services(ns).ProxyGet(url.Scheme, name, port, url.JoinPath("api", "v1", "all").Path, map[string]string{})
rc, err := resp.Stream(ctx)
if err != nil {
return nil, err
}
defer rc.Close()

return io.ReadAll(rc)
}
Loading