Skip to content

Commit ad34ffb

Browse files
(cleanup): Remove export of func from the tests since it is not required
1 parent 9864ba7 commit ad34ffb

File tree

2 files changed

+43
-52
lines changed

2 files changed

+43
-52
lines changed

test/catalogd-e2e/unpack_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ package catalogde2e
22

33
import (
44
"context"
5+
"fmt"
6+
"io"
7+
"k8s.io/client-go/kubernetes"
8+
"net/url"
59
"os"
10+
"strings"
611

712
. "github.com/onsi/ginkgo/v2"
813
. "github.com/onsi/gomega"
@@ -76,7 +81,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
7681
Expect(catalog.ObjectMeta.Labels).To(HaveKeyWithValue("olm.operatorframework.io/metadata.name", catalogName))
7782

7883
By("Making sure the catalog content is available via the http server")
79-
actualFBC, err := ReadTestCatalogServerContents(ctx, catalog, c, kubeClient)
84+
actualFBC, err := readTestCatalogServerContents(ctx, catalog, kubeClient)
8085
Expect(err).To(Not(HaveOccurred()))
8186

8287
expectedFBC, err := os.ReadFile("../../catalogd/testdata/catalogs/test-catalog/expected_all.json")
@@ -102,3 +107,40 @@ var _ = Describe("ClusterCatalog Unpacking", func() {
102107
})
103108
})
104109
})
110+
111+
func readTestCatalogServerContents(ctx context.Context, catalog *catalogdv1.ClusterCatalog, kubeClient kubernetes.Interface) ([]byte, error) {
112+
if catalog == nil {
113+
return nil, fmt.Errorf("cannot read nil catalog")
114+
}
115+
if catalog.Status.URLs == nil {
116+
return nil, fmt.Errorf("catalog %q has no catalog urls", catalog.Name)
117+
}
118+
url, err := url.Parse(catalog.Status.URLs.Base)
119+
if err != nil {
120+
return nil, fmt.Errorf("error parsing clustercatalog url %q: %v", catalog.Status.URLs.Base, err)
121+
}
122+
// url is expected to be in the format of
123+
// http://{service_name}.{namespace}.svc/catalogs/{catalog_name}/
124+
// so to get the namespace and name of the service we grab only
125+
// the hostname and split it on the '.' character
126+
ns := strings.Split(url.Hostname(), ".")[1]
127+
name := strings.Split(url.Hostname(), ".")[0]
128+
port := url.Port()
129+
// the ProxyGet() call below needs an explicit port value, so if
130+
// value from url.Port() is empty, we assume port 443.
131+
if port == "" {
132+
if url.Scheme == "https" {
133+
port = "443"
134+
} else {
135+
port = "80"
136+
}
137+
}
138+
resp := kubeClient.CoreV1().Services(ns).ProxyGet(url.Scheme, name, port, url.JoinPath("api", "v1", "all").Path, map[string]string{})
139+
rc, err := resp.Stream(ctx)
140+
if err != nil {
141+
return nil, err
142+
}
143+
defer rc.Close()
144+
145+
return io.ReadAll(rc)
146+
}

test/catalogd-e2e/util.go

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

0 commit comments

Comments
 (0)