Skip to content

Commit 9a10b60

Browse files
Merge pull request #19807 from gabemontero/relax-cakephp-count
move cakephp ext test count check to greater than zero
2 parents 2e4973f + 65a8ad9 commit 9a10b60

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

test/extended/image_ecosystem/helper.go

+31
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package image_ecosystem
22

33
import (
44
"fmt"
5+
"regexp"
56
"strings"
67
"time"
78

@@ -54,3 +55,33 @@ func CheckPageContains(oc *exutil.CLI, endpoint, path, contents string) (bool, e
5455
}
5556
return success, nil
5657
}
58+
59+
// CheckPageRegexp makes a http request for an example application and checks
60+
// that the result satisfies a given regexp; it will also return the submatch array entry
61+
// present at index for possible comparisons
62+
func CheckPageRegexp(oc *exutil.CLI, endpoint, path, regex string, index int) (bool, string, error) {
63+
address, err := exutil.GetEndpointAddress(oc, endpoint)
64+
if err != nil {
65+
return false, "", err
66+
}
67+
68+
response, err := exutil.FetchURL(fmt.Sprintf("http://%s/%s", address, path), 3*time.Minute)
69+
if err != nil {
70+
return false, "", err
71+
}
72+
73+
val := ""
74+
r, _ := regexp.Compile(regex)
75+
parts := r.FindStringSubmatch(response)
76+
success := len(parts) > 0
77+
if !success {
78+
fmt.Fprintf(g.GinkgoWriter, "CheckPageContains was looking for %s but got %s\n", regex, response)
79+
} else {
80+
for i, part := range parts {
81+
if i == index {
82+
val = part
83+
}
84+
}
85+
}
86+
return success, val, nil
87+
}

test/extended/image_ecosystem/s2i_php.go

+26-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package image_ecosystem
22

33
import (
44
"fmt"
5+
"strconv"
56
"time"
67

78
g "github.com/onsi/ginkgo"
@@ -19,7 +20,8 @@ var _ = g.Describe("[image_ecosystem][php][Slow] hot deploy for openshift php im
1920
oc = exutil.NewCLI("s2i-php", exutil.KubeConfigPath())
2021
hotDeployParam = "OPCACHE_REVALIDATE_FREQ=0"
2122
modifyCommand = []string{"sed", "-ie", `s/\$result\['c'\]/1337/`, "src/Template/Pages/home.ctp"}
22-
pageCountFn = func(count int) string { return fmt.Sprintf(`<span class="code" id="count-value">%d</span>`, count) }
23+
pageRegexpCount = `<span class="code" id="count-value">([^0][0-9]*)</span>`
24+
pageExactCount = `<span class="code" id="count-value">%d</span>`
2325
dcName = "cakephp-mysql-example-1"
2426
dcLabel = exutil.ParseLabelsOrDie(fmt.Sprintf("deployment=%s", dcName))
2527
)
@@ -58,23 +60,41 @@ var _ = g.Describe("[image_ecosystem][php][Slow] hot deploy for openshift php im
5860
err = e2e.WaitForEndpoint(oc.KubeFramework().ClientSet, oc.Namespace(), "cakephp-mysql-example")
5961
o.Expect(err).NotTo(o.HaveOccurred())
6062

61-
assertPageCountIs := func(i int) {
63+
assertPageCountRegexp := func(priorValue string) string {
6264
_, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute)
6365
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
6466

65-
result, err := CheckPageContains(oc, "cakephp-mysql-example", "", pageCountFn(i))
67+
result, val, err := CheckPageRegexp(oc, "cakephp-mysql-example", "", pageRegexpCount, 1)
6668
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
6769
o.ExpectWithOffset(1, result).To(o.BeTrue())
70+
if len(priorValue) > 0 {
71+
p, err := strconv.Atoi(priorValue)
72+
o.Expect(err).NotTo(o.HaveOccurred())
73+
v, err := strconv.Atoi(val)
74+
g.By(fmt.Sprintf("comparing prior value %d with lastest value %d", p, v))
75+
o.Expect(err).NotTo(o.HaveOccurred())
76+
o.Expect(v).To(o.BeNumerically(">", p))
77+
}
78+
return val
6879
}
6980

7081
g.By("checking page count")
71-
72-
assertPageCountIs(1)
73-
assertPageCountIs(2)
82+
val := assertPageCountRegexp("")
83+
assertPageCountRegexp(val)
7484

7585
g.By("modifying the source code with hot deploy enabled")
7686
err = RunInPodContainer(oc, dcLabel, modifyCommand)
7787
o.Expect(err).NotTo(o.HaveOccurred())
88+
89+
assertPageCountIs := func(i int) {
90+
_, err := exutil.WaitForPods(oc.KubeClient().Core().Pods(oc.Namespace()), dcLabel, exutil.CheckPodIsRunning, 1, 4*time.Minute)
91+
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
92+
93+
result, err := CheckPageContains(oc, "cakephp-mysql-example", "", fmt.Sprintf(pageExactCount, i))
94+
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
95+
o.ExpectWithOffset(1, result).To(o.BeTrue())
96+
}
97+
7898
g.By("checking page count after modifying the source code")
7999
assertPageCountIs(1337)
80100
})

0 commit comments

Comments
 (0)