Skip to content

Commit d2026cb

Browse files
committed
Skip an accept-risk case on network-restricted environment
1 parent 55fa151 commit d2026cb

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

test/cvo/accept_risks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
6262
})
6363

6464
g.It("should work with accept risks", g.Label("Serial"), func() {
65+
// This test case relies on a public service util.FauxinnatiAPIURL
66+
util.SkipIfNetworkRestricted()
67+
6568
cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{})
6669
o.Expect(err).NotTo(o.HaveOccurred())
6770

test/util/util.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package util
22

33
import (
44
"context"
5+
"net/http"
56
"time"
67

78
g "github.com/onsi/ginkgo/v2"
@@ -135,3 +136,27 @@ const (
135136
// fauxinnati mocks Cincinnati Update Graph Server for OpenShift
136137
FauxinnatiAPIURL = "https://fauxinnati-fauxinnati.apps.ota-stage.q2z4.p1.openshiftapps.com/api/upgrades_info/graph"
137138
)
139+
140+
func accessible(url string) bool {
141+
client := &http.Client{
142+
Timeout: 5 * time.Second,
143+
}
144+
resp, err := client.Get(url)
145+
defer func() {
146+
if resp != nil && resp.Body != nil {
147+
_ = resp.Body.Close()
148+
}
149+
}()
150+
return err == nil
151+
}
152+
153+
func NetworkRestricted() bool {
154+
// TODO: Use a more precise method
155+
return !accessible("http://google.com")
156+
}
157+
158+
func SkipIfNetworkRestricted() {
159+
if NetworkRestricted() {
160+
g.Skip("This test is skipped because the network is restricted")
161+
}
162+
}

0 commit comments

Comments
 (0)