test/extended/util/disruption/frontends/frontends: match route contents by regexp, support OKD
@@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
+ "regexp"
"time"
"github.com/onsi/ginkgo"
@@ -38,6 +39,7 @@ type Frontend struct {
Path string
Expect string
+ ExpectRegexp *regexp.Regexp
}
func (AvailableTest) Name() string { return "frontend-ingress-available" }
@@ -49,7 +51,7 @@ func (AvailableTest) DisplayName() string {
func (t *AvailableTest) Setup(f *framework.Framework) {
t.frontends = []Frontend{
{Namespace: "openshift-authentication", Name: "oauth-openshift", Path: "/healthz", Expect: "ok"},
- {Namespace: "openshift-console", Name: "console", Expect: "Red Hat OpenShift Container Platform"},
+ {Namespace: "openshift-console", Name: "console", ExpectRegexp: regexp.MustCompile(`(Red Hat OpenShift Container Platform|OKD)`)},
}
config, err := framework.LoadConfig()
framework.ExpectNoError(err)
@@ -184,7 +186,10 @@ func startEndpointMonitoring(ctx context.Context, m *monitor.Monitor, frontend F
m.AddSampler(
monitor.StartSampling(ctx, m, time.Second, func(previous bool) (condition *monitor.Condition, next bool) {
data, err := client.Get().AbsPath(frontend.Path).DoRaw()
- if err == nil && !bytes.Contains(data, []byte(frontend.Expect)) {
+ switch {
+ case err == nil && len(frontend.Expect) != 0 && !bytes.Contains(data, []byte(frontend.Expect)):
+ err = fmt.Errorf("route returned success but did not contain the correct body contents: %q", string(data))
+ case err == nil && frontend.ExpectRegexp != nil && !frontend.ExpectRegexp.MatchString(string(data)):
err = fmt.Errorf("route returned success but did not contain the correct body contents: %q", string(data))
}
switch {
