Skip to content

Commit

Permalink
OSSM-5382: Fixing the BI test case (#648)
Browse files Browse the repository at this point in the history
* updating the html file

* removed unnessary space

* updating the dynamic value in the HTML

* creating the common file

* Adding the TestreviewV3 parameter

* updated the root path

* updated the file var

---------

Co-authored-by: Praneeth Bajjuri <pbajjuri@pbajjuri-thinkpadp1gen4i.rmtustx.csb>
  • Loading branch information
pbajjuri20 and Praneeth Bajjuri authored Jan 23, 2024
1 parent bcb0b8c commit a9b054f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 16 deletions.
16 changes: 8 additions & 8 deletions images.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
# This file contains all the images used in maistra-test-tool (for each architecture).

bookinfo-mongodb:
x86: quay.io/maistra/examples-bookinfo-mongodb:2.3.0
x86: quay.io/maistra/examples-bookinfo-mongodb:2.4.0
arm: quay.io/maistra/examples-bookinfo-mongodb:2.4.0
p: quay.io/maistra/examples-bookinfo-mongodb:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-mongodb:2.1-z

bookinfo-productpage-v1:
x86: quay.io/maistra/examples-bookinfo-productpage-v1:2.3.0
x86: quay.io/maistra/examples-bookinfo-productpage-v1:2.4.0
arm: quay.io/maistra/examples-bookinfo-productpage-v1:2.4.0
p: quay.io/maistra/examples-bookinfo-productpage-v1:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-productpage-v1:2.1-z

bookinfo-details-v1:
x86: quay.io/maistra/examples-bookinfo-details-v1:2.3.0
x86: quay.io/maistra/examples-bookinfo-details-v1:2.4.0
arm: quay.io/maistra/examples-bookinfo-details-v1:2.4.0
p: quay.io/maistra/examples-bookinfo-details-v1:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-details-v1:2.1-z

bookinfo-ratings-v1:
x86: quay.io/maistra/examples-bookinfo-ratings-v1:2.3.0
x86: quay.io/maistra/examples-bookinfo-ratings-v1:2.4.0
arm: quay.io/maistra/examples-bookinfo-ratings-v1:2.4.0
p: quay.io/maistra/examples-bookinfo-ratings-v1:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-ratings-v1:2.1-z

bookinfo-ratings-v2:
x86: quay.io/maistra/examples-bookinfo-ratings-v2:2.3.0
x86: quay.io/maistra/examples-bookinfo-ratings-v2:2.4.0
arm: quay.io/maistra/examples-bookinfo-ratings-v2:2.4.0
p: quay.io/maistra/examples-bookinfo-ratings-v2:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-ratings-v2:2.1-z

bookinfo-reviews-v1:
x86: quay.io/maistra/examples-bookinfo-reviews-v1:2.3.0
x86: quay.io/maistra/examples-bookinfo-reviews-v1:2.4.0
arm: quay.io/maistra/examples-bookinfo-reviews-v1:2.4.0
p: quay.io/maistra/examples-bookinfo-reviews-v1:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-reviews-v1:2.1-z

bookinfo-reviews-v2:
x86: quay.io/maistra/examples-bookinfo-reviews-v2:2.3.0
x86: quay.io/maistra/examples-bookinfo-reviews-v2:2.4.0
arm: quay.io/maistra/examples-bookinfo-reviews-v2:2.4.0
p: quay.io/maistra/examples-bookinfo-reviews-v2:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-reviews-v2:2.1-z

bookinfo-reviews-v3:
x86: quay.io/maistra/examples-bookinfo-reviews-v3:2.3.0
x86: quay.io/maistra/examples-bookinfo-reviews-v3:2.4.0
arm: quay.io/maistra/examples-bookinfo-reviews-v3:2.4.0
p: quay.io/maistra/examples-bookinfo-reviews-v3:2.1.0-ibm-p
z: quay.io/maistra/examples-bookinfo-reviews-v3:2.1-z
Expand Down
63 changes: 63 additions & 0 deletions pkg/tests/tasks/traffic/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package traffic

import (
"fmt"
"os"

"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/pod"
"github.com/maistra/maistra-test-tool/pkg/util/template"

. "github.com/maistra/maistra-test-tool/pkg/util/test"
)

func TestreviewV1(t TestHelper, file string) string {

ns := "bookinfo"

reviewV1Podname := pod.MatchingSelector("app=reviews,version=v1", ns)(t, oc.DefaultOC).Name

templateString, err := os.ReadFile(env.GetRootDir() + "/testdata/resources/html/" + file)
if err != nil {
t.Fatalf("could not read template file %s: %v", file, err)
}
htmlFile := template.Run(t, string(templateString), struct{ ReviewV1Podname string }{ReviewV1Podname: reviewV1Podname})
fmt.Println(htmlFile)
os.WriteFile(env.GetRootDir()+"/testdata/resources/html/modified-"+file, []byte(htmlFile), 0644)

return "modified-" + file

}

func TestreviewV2(t TestHelper, file string) string {

ns := "bookinfo"

reviewV2Podname := pod.MatchingSelector("app=reviews,version=v2", ns)(t, oc.DefaultOC).Name
template2String, err := os.ReadFile(env.GetRootDir() + "/testdata/resources/html/" + file)
if err != nil {
t.Fatalf("could not read template file %s: %v", file, err)
}
html2File := template.Run(t, string(template2String), struct{ ReviewV2Podname string }{ReviewV2Podname: reviewV2Podname})
os.WriteFile(env.GetRootDir()+"/testdata/resources/html/modified-"+file, []byte(html2File), 0644)

return "modified-" + file

}

func TestreviewV3(t TestHelper, file string) string {

ns := "bookinfo"

reviewV3Podname := pod.MatchingSelector("app=reviews,version=v3", ns)(t, oc.DefaultOC).Name
template3String, err := os.ReadFile(env.GetRootDir() + "/testdata/resources/html/" + file)
if err != nil {
t.Fatalf("could not read template file %s: %v", file, err)
}
html2File := template.Run(t, string(template3String), struct{ ReviewV3Podname string }{ReviewV3Podname: reviewV3Podname})
os.WriteFile(env.GetRootDir()+"/testdata/resources/html/modified-"+file, []byte(html2File), 0644)

return "modified-" + file

}
7 changes: 6 additions & 1 deletion pkg/tests/tasks/traffic/fault_injection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package traffic

import (
_ "embed"
"os"
"testing"
"time"

"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/tests/ossm"
"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
. "github.com/maistra/maistra-test-tool/pkg/util/test"
Expand All @@ -42,6 +44,7 @@ func TestFaultInjection(t *testing.T) {

t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-test-user-v2-rating-unavailable.html`)
})

ossm.DeployControlPlane(t)
Expand Down Expand Up @@ -74,13 +77,15 @@ func TestFaultInjection(t *testing.T) {
t.NewSubTest("ratings-fault-abort").Run(func(t TestHelper) {
oc.ApplyString(t, ns, ratingsVirtualServiceWithHttpStatus500)

expectedResponseFile := TestreviewV2(t, "productpage-test-user-v2-rating-unavailable.html")

t.LogStep("check if productpage shows ratings service as unavailable due to abort injection")
retry.UntilSuccess(t, func(t TestHelper) {
curl.Request(t,
app.BookinfoProductPageURL(t, meshNamespace),
curl.WithCookieJar(testUserCookieJar),
assert.ResponseMatchesFile(
"productpage-test-user-v2-rating-unavailable.html",
expectedResponseFile,
"productpage shows 'ratings service is currently unavailable' as expected",
"expected productpage to show ratings service as unavailable, but got a different response",
app.ProductPageResponseFiles...))
Expand Down
12 changes: 10 additions & 2 deletions pkg/tests/tasks/traffic/request_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package traffic

import (
"os"
"testing"

"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/tests/ossm"
"github.com/maistra/maistra-test-tool/pkg/util/check/require"
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
. "github.com/maistra/maistra-test-tool/pkg/util/test"
Expand All @@ -32,6 +34,8 @@ func TestRequestRouting(t *testing.T) {

t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-test-user-v2.html`)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`)
})

ossm.DeployControlPlane(t)
Expand All @@ -45,13 +49,15 @@ func TestRequestRouting(t *testing.T) {
t.NewSubTest("not-logged-in").Run(func(t TestHelper) {
oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1)

expectedResponseFile := TestreviewV1(t, "productpage-normal-user-v1.html")

t.LogStep("get productpage without logging in; expect to get reviews-v1 (5x)")
retry.UntilSuccess(t, func(t TestHelper) {
for i := 0; i < 5; i++ {
curl.Request(t,
productpageURL, nil,
require.ResponseMatchesFile(
"productpage-normal-user-v1.html",
expectedResponseFile,
"productpage called reviews-v1",
"expected productpage to call reviews-v1, but got an unexpected response",
app.ProductPageResponseFiles...))
Expand All @@ -62,14 +68,16 @@ func TestRequestRouting(t *testing.T) {
t.NewSubTest("logged-in").Run(func(t TestHelper) {
oc.ApplyString(t, ns, app.BookinfoVirtualServiceReviewsV2)

expectedResponseFile2 := TestreviewV2(t, "productpage-test-user-v2.html")

t.LogStep("get productpage as logged-in user; expect to get reviews-v2 (5x)")
retry.UntilSuccess(t, func(t TestHelper) {
for i := 0; i < 5; i++ {
curl.Request(t,
productpageURL,
curl.WithCookieJar(testUserCookieJar),
require.ResponseMatchesFile(
"productpage-test-user-v2.html",
expectedResponseFile2,
"productpage called reviews-v2",
"expected productpage to call reviews-v2, but got an unexpected response",
app.ProductPageResponseFiles...))
Expand Down
8 changes: 7 additions & 1 deletion pkg/tests/tasks/traffic/request_timeouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ package traffic

import (
_ "embed"
"os"
"testing"

"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/tests/ossm"
"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/check/require"
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
. "github.com/maistra/maistra-test-tool/pkg/util/test"
Expand All @@ -37,6 +39,7 @@ func TestRequestTimeouts(t *testing.T) {

t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`)
})

ossm.DeployControlPlane(t)
Expand All @@ -49,11 +52,14 @@ func TestRequestTimeouts(t *testing.T) {
oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1)

t.LogStep("make sure there is no timeout before applying delay and timeout in VirtualServices")

expectedResponseFile := TestreviewV1(t, "productpage-normal-user-v1.html")

retry.UntilSuccess(t, func(t TestHelper) {
curl.Request(t,
productpageURL, nil,
assert.ResponseMatchesFile(
"productpage-normal-user-v1.html",
expectedResponseFile,
"received normal productpage response",
"unexpected response",
app.ProductPageResponseFiles...))
Expand Down
16 changes: 12 additions & 4 deletions pkg/tests/tasks/traffic/traffic_shifting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package traffic
import (
_ "embed"
"net/http"
"os"
"testing"
"time"

Expand All @@ -25,6 +26,7 @@ import (
. "github.com/maistra/maistra-test-tool/pkg/util"
"github.com/maistra/maistra-test-tool/pkg/util/check/require"
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
. "github.com/maistra/maistra-test-tool/pkg/util/test"
Expand All @@ -36,6 +38,8 @@ func TestTrafficShifting(t *testing.T) {

t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v3.html`)
os.Remove(env.GetRootDir() + `/testdata/resources/html/modified-productpage-normal-user-v1.html`)
})

ossm.DeployControlPlane(t)
Expand All @@ -46,16 +50,20 @@ func TestTrafficShifting(t *testing.T) {

oc.ApplyString(t, ns, app.BookinfoVirtualServicesAllV1)

expectedResponseFile := TestreviewV1(t, "productpage-normal-user-v1.html")
expectedResponseFile3 := TestreviewV3(t, "productpage-normal-user-v3.html")

t.NewSubTest("50 percent to v3").Run(func(t TestHelper) {
t.LogStep("configure VirtualService to split traffic 50% to v1 and 50% to v3")
oc.ApplyString(t, ns, splitReviews5050BetweenV1andV3)

t.LogStep("Make 100 requests and check if v1 and v3 get 50% of requests each (tolerance: 20%)")

retry.UntilSuccess(t, func(t TestHelper) {
tolerance := 0.20
checkTrafficRatio(t, productpageURL, 100, tolerance, map[string]float64{
"productpage-normal-user-v1.html": 0.5,
"productpage-normal-user-v3.html": 0.5,
expectedResponseFile: 0.5,
expectedResponseFile3: 0.5,
})
})
})
Expand All @@ -68,8 +76,8 @@ func TestTrafficShifting(t *testing.T) {
retry.UntilSuccess(t, func(t TestHelper) {
tolerance := 0.0
checkTrafficRatio(t, productpageURL, 100, tolerance, map[string]float64{
"productpage-normal-user-v1.html": 0.0,
"productpage-normal-user-v3.html": 1.0,
expectedResponseFile: 0.0,
expectedResponseFile3: 1.0,
})
})
})
Expand Down
5 changes: 5 additions & 0 deletions testdata/resources/html/productpage-normal-user-v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ <h4 class="text-center text-primary">Book Reviews</h4>

</blockquote>

<dl>
<dt>Reviews served by:</dt>
<u>{{.ReviewV1Podname}}</u>

</dl>

</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions testdata/resources/html/productpage-normal-user-v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ <h4 class="text-center text-primary">Book Reviews</h4>

</blockquote>

<dl>
<dt>Reviews served by:</dt>
<u>{{.ReviewV2Podname}}</u>

</dl>

</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions testdata/resources/html/productpage-normal-user-v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ <h4 class="text-center text-primary">Book Reviews</h4>

</blockquote>

<dl>
<dt>Reviews served by:</dt>
<u>{{.ReviewV3Podname}}</u>

</dl>

</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ <h4 class="text-center text-primary">Book Reviews</h4>

</blockquote>

<dl>
<dt>Reviews served by:</dt>
<u>{{.ReviewV2Podname}}</u>

</dl>

</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions testdata/resources/html/productpage-test-user-v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ <h4 class="text-center text-primary">Book Reviews</h4>

</blockquote>

<dl>
<dt>Reviews served by:</dt>
<u>{{.ReviewV2Podname}}</u>

</dl>

</div>
</div>
Expand Down

0 comments on commit a9b054f

Please sign in to comment.