diff --git a/pkg/tests/ossm/initcontainer_test.go b/pkg/tests/ossm/initcontainer_test.go index 52f9dab8..a72427f8 100644 --- a/pkg/tests/ossm/initcontainer_test.go +++ b/pkg/tests/ossm/initcontainer_test.go @@ -18,13 +18,13 @@ import ( "testing" "github.com/maistra/maistra-test-tool/pkg/util/check/assert" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "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/test" ) func TestInitContainerNotRemovedDuringInjection(t *testing.T) { - const ns = "bookinfo" const goldString = "[init worked]" const podSelector = "app=sleep-init" @@ -32,20 +32,20 @@ func TestInitContainerNotRemovedDuringInjection(t *testing.T) { t.Log("Checking init container not removed during sidecar injection.") t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) DeployControlPlane(t) - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) t.LogStep("Deploying test pod.") - oc.ApplyString(t, ns, testInitContainerYAML) - oc.WaitDeploymentRolloutComplete(t, ns, "sleep-init") + oc.ApplyString(t, ns.Bookinfo, testInitContainerYAML) + oc.WaitDeploymentRolloutComplete(t, ns.Bookinfo, "sleep-init") t.LogStep("Checking pod logs for init message.") oc.Logs(t, - pod.MatchingSelector(podSelector, ns), + pod.MatchingSelector(podSelector, ns.Bookinfo), "init", assert.OutputContains(goldString, "Init container executed successfully.", diff --git a/pkg/tests/ossm/ratelimit_test.go b/pkg/tests/ossm/ratelimit_test.go index 405d9ff3..92e2d9b8 100644 --- a/pkg/tests/ossm/ratelimit_test.go +++ b/pkg/tests/ossm/ratelimit_test.go @@ -23,6 +23,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/app" "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/ns" "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/shell" @@ -41,15 +42,14 @@ var ( func TestRateLimiting(t *testing.T) { NewTest(t).Id("T28").Groups(Full, ARM).MaxVersion(version.SMCP_2_2).Run(func(t TestHelper) { - ns := "bookinfo" nsRedis := "redis" DeployControlPlane(t) t.LogStep("Install Bookinfo and Redis") - app.InstallAndWaitReady(t, app.Bookinfo(ns), app.Redis(nsRedis)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo), app.Redis(nsRedis)) t.Cleanup(func() { - app.Uninstall(t, app.Bookinfo(ns), app.Redis(nsRedis)) + app.Uninstall(t, app.Bookinfo(ns.Bookinfo), app.Redis(nsRedis)) oc.DeleteNamespace(t, nsRedis) // namespace redis is only used in this test, so delete it after test }) diff --git a/pkg/tests/ossm/smcp_annotation_test.go b/pkg/tests/ossm/smcp_annotation_test.go index 8439fdb3..bf81615e 100644 --- a/pkg/tests/ossm/smcp_annotation_test.go +++ b/pkg/tests/ossm/smcp_annotation_test.go @@ -20,6 +20,7 @@ import ( "gopkg.in/yaml.v2" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "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/retry" @@ -34,26 +35,24 @@ func TestSMCPAnnotations(t *testing.T) { t.NewSubTest("proxyEnvoy").Run(func(t test.TestHelper) { t.Parallel() - ns := "foo" t.Cleanup(func() { - oc.DeleteFromTemplate(t, ns, testSSLDeploymentWithAnnotation, nil) + oc.DeleteFromTemplate(t, ns.Foo, testSSLDeploymentWithAnnotation, nil) }) t.LogStep("Deploy TestSSL pod with annotations sidecar.maistra.io/proxyEnv") - oc.ApplyTemplate(t, ns, testSSLDeploymentWithAnnotation, nil) - oc.WaitDeploymentRolloutComplete(t, ns, "testenv") + oc.ApplyTemplate(t, ns.Foo, testSSLDeploymentWithAnnotation, nil) + oc.WaitDeploymentRolloutComplete(t, ns.Foo, "testenv") t.LogStep("Get annotations and verify that the pod has the expected: sidecar.maistra.io/proxyEnv : { \"maistra_test_env\": \"env_value\", \"maistra_test_env_2\": \"env_value_2\" }") - annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns)) + annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns.Foo)) assertAnnotationIsPresent(t, annotations, "sidecar.maistra.io/proxyEnv", `{ "maistra_test_env": "env_value", "maistra_test_env_2": "env_value_2" }`) }) // Test that the SMCP automatic injection with quotes works t.NewSubTest("quote_injection").Run(func(t test.TestHelper) { t.Parallel() - ns := "bar" t.Cleanup(func() { oc.Patch(t, meshNamespace, "smcp", smcpName, "json", `[{"op": "remove", "path": "/spec/proxy"}]`) - oc.DeleteFromTemplate(t, ns, testSSLDeploymentWithAnnotation, nil) + oc.DeleteFromTemplate(t, ns.Bar, testSSLDeploymentWithAnnotation, nil) }) t.LogStep("Enable annotation auto injection in SMCP") oc.Patch(t, @@ -64,12 +63,12 @@ func TestSMCPAnnotations(t *testing.T) { oc.WaitSMCPReady(t, meshNamespace, smcpName) t.LogStep("Deploy TestSSL pod with annotations sidecar.maistra.io/proxyEnv") - oc.ApplyTemplate(t, ns, testSSLDeploymentWithAnnotation, nil) - oc.WaitDeploymentRolloutComplete(t, ns, "testenv") + oc.ApplyTemplate(t, ns.Bar, testSSLDeploymentWithAnnotation, nil) + oc.WaitDeploymentRolloutComplete(t, ns.Bar, "testenv") t.LogStep("Get annotations and verify that the pod has the expected: test1.annotation-from-smcp : test1, test2.annotation-from-smcp : [\"test2\"], test3.annotation-from-smcp : {test3}") retry.UntilSuccess(t, func(t test.TestHelper) { - annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns)) + annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns.Bar)) assertAnnotationIsPresent(t, annotations, "test1.annotation-from-smcp", "test1") assertAnnotationIsPresent(t, annotations, "test2.annotation-from-smcp", `["test2"]`) assertAnnotationIsPresent(t, annotations, "test3.annotation-from-smcp", "{test3}") diff --git a/pkg/tests/ossm/smcp_must_gather_test.go b/pkg/tests/ossm/smcp_must_gather_test.go index 834f1800..9cfd6417 100644 --- a/pkg/tests/ossm/smcp_must_gather_test.go +++ b/pkg/tests/ossm/smcp_must_gather_test.go @@ -25,6 +25,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/util/check/assert" "github.com/maistra/maistra-test-tool/pkg/util/check/common" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/shell" @@ -35,15 +36,14 @@ func TestMustGather(t *testing.T) { NewTest(t).Id("T30").Groups(Full, ARM).Run(func(t TestHelper) { t.Log("This test verifies must-gather log collection") - ns := "bookinfo" t.Cleanup(func() { - oc.RecreateNamespace(t, ns) + oc.RecreateNamespace(t, ns.Bookinfo) }) DeployControlPlane(t) t.LogStep("Deploy bookinfo in bookinfo ns") - app.InstallAndWaitReady(t, app.Bookinfo(ns)) + app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo)) image := env.GetMustGatherImage() dir := shell.CreateTempDir(t, "must-gather-") diff --git a/pkg/tests/ossm/smm_test.go b/pkg/tests/ossm/smm_test.go index 6d91b3bb..7caac21e 100644 --- a/pkg/tests/ossm/smm_test.go +++ b/pkg/tests/ossm/smm_test.go @@ -17,8 +17,7 @@ import ( func TestSMMRAutoCreationAndDeletion(t *testing.T) { NewTest(t).Id("T39").Groups(Full, Disconnected, ARM).Run(func(t TestHelper) { t.Log("This test verifies what happens to the SMMR when SMM is created and deleted") - foo := "foo" - bar := "bar" + t.Cleanup(func() { oc.ApplyString(t, meshNamespace, smmr) // revert SMMR to original state }) @@ -29,14 +28,14 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) { oc.DeleteResource(t, meshNamespace, "smmr", "default") t.LogStep("Create two namespaces") - oc.CreateNamespace(t, foo, bar) + oc.CreateNamespace(t, ns.Foo, ns.Bar) t.NewSubTest("create first SMM").Run(func(t TestHelper) { t.Log("This test checks if the SMMR is created when you create a ServiceMeshMember") t.LogStep("Create ServiceMeshMembers in namespaces foo and bar") - oc.ApplyString(t, foo, smm) - oc.ApplyString(t, bar, smm) + oc.ApplyString(t, ns.Foo, smm) + oc.ApplyString(t, ns.Bar, smm) t.LogStep("Wait for SMMR to be ready") oc.WaitSMMRReady(t, meshNamespace) @@ -45,8 +44,8 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) { retry.UntilSuccess(t, func(t TestHelper) { shell.Execute(t, fmt.Sprintf(`oc get smmr default -n %s -o=jsonpath='{.status.members[*]}{"\n"}'`, meshNamespace), - assert.OutputContains(foo, "SMMR has the member foo", "SMMR does not have the namespaces foo and bar"), - assert.OutputContains(bar, "SMMR has the member bar", "SMMR does not have the namespaces foo and bar")) + assert.OutputContains(ns.Foo, "SMMR has the member foo", "SMMR does not have the namespaces foo and bar"), + assert.OutputContains(ns.Bar, "SMMR has the member bar", "SMMR does not have the namespaces foo and bar")) }) }) @@ -56,7 +55,7 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) { t.Log("See https://issues.redhat.com/browse/OSSM-3450 (test)") t.LogStep("Delete one SMM, but keep the other") - oc.DeleteFromString(t, bar, smm) + oc.DeleteFromString(t, ns.Bar, smm) t.LogStep("Check if SMMR becomes ready (it won't be if it gets deleted)") retry.UntilSuccess(t, func(t TestHelper) { @@ -70,7 +69,7 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) { t.Log("See https://issues.redhat.com/browse/OSSM-3450 (test)") t.LogStep("Delete last SMM") - oc.DeleteFromString(t, foo, smm) + oc.DeleteFromString(t, ns.Foo, smm) t.LogStep("Check that SMMR is deleted") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/ossm/testssl_test.go b/pkg/tests/ossm/testssl_test.go index c3f1a368..7610b0f4 100644 --- a/pkg/tests/ossm/testssl_test.go +++ b/pkg/tests/ossm/testssl_test.go @@ -20,6 +20,7 @@ import ( "github.com/maistra/maistra-test-tool/pkg/app" "github.com/maistra/maistra-test-tool/pkg/util/check/assert" "github.com/maistra/maistra-test-tool/pkg/util/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "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/retry" @@ -28,7 +29,6 @@ import ( func TestSSL(t *testing.T) { NewTest(t).Id("T27").Groups(Full, InterOp, ARM).Run(func(t TestHelper) { - ns := "bookinfo" t.Cleanup(func() { oc.Patch(t, meshNamespace, "smcp", smcpName, "json", `[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]`) oc.Patch(t, meshNamespace, "smcp", smcpName, "merge", ` @@ -39,8 +39,8 @@ spec: controlPlane: mtls: false `) - app.Uninstall(t, app.BookinfoWithMTLS(ns)) - oc.DeleteFromTemplate(t, ns, testSSLDeployment, nil) + app.Uninstall(t, app.BookinfoWithMTLS(ns.Bookinfo)) + oc.DeleteFromTemplate(t, ns.Bookinfo, testSSLDeployment, nil) }) DeployControlPlane(t) // TODO: integrate below patch here @@ -65,9 +65,9 @@ spec: oc.WaitSMCPReady(t, meshNamespace, smcpName) t.LogStep("Install bookinfo with mTLS and testssl pod") - oc.ApplyTemplate(t, ns, testSSLDeployment, nil) - app.InstallAndWaitReady(t, app.BookinfoWithMTLS(ns)) - oc.WaitDeploymentRolloutComplete(t, ns, "testssl") + oc.ApplyTemplate(t, ns.Bookinfo, testSSLDeployment, nil) + app.InstallAndWaitReady(t, app.BookinfoWithMTLS(ns.Bookinfo)) + oc.WaitDeploymentRolloutComplete(t, ns.Bookinfo, "testssl") t.LogStep("Check testssl.sh results") command := "./testssl/testssl.sh -P -6 productpage:9080 || true" @@ -76,7 +76,7 @@ spec: } retry.UntilSuccessWithOptions(t, retry.Options().MaxAttempts(10), func(t TestHelper) { oc.Exec(t, - pod.MatchingSelector("app=testssl", ns), + pod.MatchingSelector("app=testssl", ns.Bookinfo), "testssl", command, assert.OutputContains( diff --git a/pkg/tests/tasks/security/authentication/auth_test.go b/pkg/tests/tasks/security/authentication/auth_test.go index 97c3679c..c2ae1c03 100644 --- a/pkg/tests/tasks/security/authentication/auth_test.go +++ b/pkg/tests/tasks/security/authentication/auth_test.go @@ -27,6 +27,7 @@ import ( "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/istio" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "github.com/maistra/maistra-test-tool/pkg/util/oc" "github.com/maistra/maistra-test-tool/pkg/util/request" "github.com/maistra/maistra-test-tool/pkg/util/retry" @@ -41,22 +42,22 @@ func TestAuthPolicy(t *testing.T) { t.Log("Doc reference: https://istio.io/latest/docs/tasks/security/authentication/authn-policy/") t.Cleanup(func() { - oc.RecreateNamespace(t, "foo", "bar", "legacy") + oc.RecreateNamespace(t, ns.Foo, ns.Bar, ns.Legacy) }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin and sleep in multiple namespaces") app.InstallAndWaitReady(t, - app.Httpbin("foo"), - app.Httpbin("bar"), - app.HttpbinNoSidecar("legacy"), - app.Sleep("foo"), - app.Sleep("bar"), - app.SleepNoSidecar("legacy")) - - fromNamespaces := []string{"foo", "bar", "legacy"} - toNamespaces := []string{"foo", "bar"} + app.Httpbin(ns.Foo), + app.Httpbin(ns.Bar), + app.HttpbinNoSidecar(ns.Legacy), + app.Sleep(ns.Foo), + app.Sleep(ns.Bar), + app.SleepNoSidecar(ns.Legacy)) + + fromNamespaces := []string{ns.Foo, ns.Bar, ns.Legacy} + toNamespaces := []string{ns.Foo, ns.Bar} t.LogStep("Check connectivity from namespaces foo, bar, and legacy to namespaces foo and bar") retry.UntilSuccess(t, func(t TestHelper) { diff --git a/pkg/tests/tasks/security/authentication/mtls_migration_test.go b/pkg/tests/tasks/security/authentication/mtls_migration_test.go index 4ce7c602..297faf09 100644 --- a/pkg/tests/tasks/security/authentication/mtls_migration_test.go +++ b/pkg/tests/tasks/security/authentication/mtls_migration_test.go @@ -21,6 +21,7 @@ import ( "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/env" + "github.com/maistra/maistra-test-tool/pkg/util/ns" "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" @@ -31,21 +32,21 @@ func TestMTlsMigration(t *testing.T) { meshNamespace := env.GetDefaultMeshNamespace() t.Cleanup(func() { - oc.RecreateNamespace(t, "foo", "bar", "legacy") // TODO: recreate all three namespaces with a single call to RecreateNamespace + oc.RecreateNamespace(t, ns.Foo, ns.Bar, ns.Legacy) // TODO: recreate all three namespaces with a single call to RecreateNamespace }) ossm.DeployControlPlane(t) t.LogStep("Install httpbin and sleep in multiple namespaces") app.InstallAndWaitReady(t, - app.Httpbin("foo"), - app.Httpbin("bar"), - app.Sleep("foo"), - app.Sleep("bar"), - app.SleepNoSidecar("legacy")) + app.Httpbin(ns.Foo), + app.Httpbin(ns.Bar), + app.Sleep(ns.Foo), + app.Sleep(ns.Bar), + app.SleepNoSidecar(ns.Legacy)) - fromNamespaces := []string{"foo", "bar", "legacy"} - toNamespaces := []string{"foo", "bar"} + fromNamespaces := []string{ns.Foo, ns.Bar, ns.Legacy} + toNamespaces := []string{ns.Foo, ns.Bar} t.LogStep("Check connectivity from namespaces foo, bar, and legacy to namespace foo and bar") retry.UntilSuccess(t, func(t test.TestHelper) {