Skip to content
Open
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: 3 additions & 0 deletions test/cvo/accept_risks.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ var _ = g.Describe(`[Jira:"Cluster Version Operator"] cluster-version-operator`,
})

g.It("should work with accept risks", g.Label("Serial"), func() {
// This test case relies on a public service util.FauxinnatiAPIURL
util.SkipIfNetworkRestricted()

cv, err := configClient.ClusterVersions().Get(ctx, external.DefaultClusterVersionName, metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())

Expand Down
25 changes: 25 additions & 0 deletions test/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"context"
"net/http"
"time"

g "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -135,3 +136,27 @@ const (
// fauxinnati mocks Cincinnati Update Graph Server for OpenShift
FauxinnatiAPIURL = "https://fauxinnati-fauxinnati.apps.ota-stage.q2z4.p1.openshiftapps.com/api/upgrades_info/graph"
)

func accessible(url string) bool {
client := &http.Client{
Timeout: 5 * time.Second,
}
resp, err := client.Get(url)
defer func() {
if resp != nil && resp.Body != nil {
_ = resp.Body.Close()
}
}()
return err == nil
}

func NetworkRestricted() bool {
// TODO: Use a more precise method
return !accessible("http://google.com")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could take an argument here, and pass through FauxinnatiAPIURL for the should work with accept risks case. If you get a HTTP response, it's accessible. If you get a network-connection error, it's not accessible. But that would test the exact endpoint you need to reach, and avoid having to hard-code something here.

}

func SkipIfNetworkRestricted() {
if NetworkRestricted() {
g.Skip("This test is skipped because the network is restricted")
}
}