Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c09fb4d

Browse files
committedMar 5, 2025·
OPRUN-3692: Olmv1-catalogd tests for API endpoints
Introduces tests for the new `api/v1/metas` endpoint when NewOLMCatalogdAPIV1Metas feature gate in enabled.
1 parent 585968f commit c09fb4d

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed
 

‎test/extended/olm/olmv1.go

+84-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package operators
22

33
import (
44
"context"
5+
"crypto/tls"
56
"encoding/json"
67
"fmt"
8+
"net/http"
79
"os"
810
"path/filepath"
911
"strings"
@@ -71,7 +73,7 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM] OLMv1 CRDs", func() {
7173
})
7274
})
7375

74-
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 Catalogs", func() {
76+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 default Catalogs", func() {
7577
defer g.GinkgoRecover()
7678
oc := exutil.NewCLIWithoutNamespace("default")
7779

@@ -99,6 +101,43 @@ var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLM
99101
})
100102
})
101103

104+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 Catalog's /v1/api/all endpoint", func() {
105+
defer g.GinkgoRecover()
106+
oc := exutil.NewCLIWithoutNamespace("default")
107+
108+
g.It("should serve FBC", func(ctx g.SpecContext) {
109+
checkFeatureCapability(ctx, oc)
110+
111+
// Start port-forward in background
112+
_, _, _, err := oc.AsAdmin().Run("port-forward").Args("-n", "openshift-catalogd", "svc/catalogd-service", "8080:443").Background()
113+
o.Expect(err).NotTo(o.HaveOccurred())
114+
115+
// Wait for port-forward to be established
116+
time.Sleep(2 * time.Second)
117+
118+
g.By("Testing /api/v1/all endpoint for catalog openshift-community-operators")
119+
verifyAPIEndpoint(ctx, "https://localhost:8080/catalogs/openshift-community-operators/api/v1/all")
120+
})
121+
})
122+
123+
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLMCatalogdAPIV1Metas][Skipped:Disconnected] OLMv1 Catalog's /v1/api/metas endpoint", func() {
124+
defer g.GinkgoRecover()
125+
oc := exutil.NewCLIWithoutNamespace("default")
126+
g.It(" should serve the /v1/api/metas API endpoint", func(ctx g.SpecContext) {
127+
checkFeatureCapability(ctx, oc)
128+
129+
// Start port-forward in background
130+
_, _, _, err := oc.AsAdmin().Run("port-forward").Args("-n", "openshift-catalogd", "svc/catalogd-service", "8443:443").Background()
131+
o.Expect(err).NotTo(o.HaveOccurred())
132+
133+
// Wait for port-forward to be established
134+
time.Sleep(2 * time.Second)
135+
136+
g.By("Testing api/v1/metas endpoint for catalog openshift-community-operators")
137+
verifyAPIEndpoint(ctx, "https://localhost:8443/catalogs/openshift-community-operators/api/v1/metas?schema=olm.package")
138+
})
139+
})
140+
102141
var _ = g.Describe("[sig-olmv1][OCPFeatureGate:NewOLM][Skipped:Disconnected] OLMv1 New Catalog Install", func() {
103142
defer g.GinkgoRecover()
104143

@@ -419,3 +458,47 @@ func checkFeatureCapability(ctx context.Context, oc *exutil.CLI) {
419458
g.Skip("Test only runs with OperatorLifecycleManagerV1 capability")
420459
}
421460
}
461+
462+
// verifyAPIEndpoint tests that an API endpoint is accessible and returns valid JSON
463+
func verifyAPIEndpoint(ctx g.SpecContext, urlPath string) {
464+
var lastError error
465+
466+
// Retry API call a few times to handle potential connection issues
467+
err := wait.PollUntilContextTimeout(ctx, 2*time.Second, 30*time.Second, true,
468+
func(ctx context.Context) (bool, error) {
469+
// Create a custom HTTP client that skips TLS verification
470+
tr := &http.Transport{
471+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
472+
}
473+
client := &http.Client{Transport: tr}
474+
475+
resp, err := client.Get(urlPath)
476+
if err != nil {
477+
lastError = err
478+
return false, nil
479+
}
480+
defer resp.Body.Close()
481+
482+
// Check status code
483+
if resp.StatusCode != http.StatusOK {
484+
lastError = fmt.Errorf("unexpected status code: %d", resp.StatusCode)
485+
return false, nil
486+
}
487+
488+
// Try to parse response as JSON to verify it's valid
489+
var result interface{}
490+
decoder := json.NewDecoder(resp.Body)
491+
if err := decoder.Decode(&result); err != nil {
492+
lastError = fmt.Errorf("failed to parse JSON response: %v", err)
493+
return false, nil
494+
}
495+
496+
return true, nil
497+
})
498+
499+
if err != nil {
500+
g.Fail(fmt.Sprintf("API endpoint %s is not accessible: %v (last error: %v)", urlPath, err, lastError))
501+
}
502+
503+
g.GinkgoLogr.Info(fmt.Sprintf("Successfully verified API endpoint: %s", urlPath))
504+
}

0 commit comments

Comments
 (0)
Please sign in to comment.