From bacf6be094e2963e13b1fc92c237f6dceadcc9e1 Mon Sep 17 00:00:00 2001 From: Karishma Chawla Date: Thu, 18 Jan 2024 09:33:06 -0800 Subject: [PATCH] Add Functional Test for Bicep Recipe Context Parameter (#7041) # Description Removing the dependency on Azure CosmosDB for context parameter functional test and replacing the existing skipped test by introducing a test that doesn't deploy any resources, as our primary goal is to verify the successful population of the context parameter. ## Type of change - This pull request is a minor refactor, code cleanup, test improvement, or other maintenance task and doesn't change the functionality of Radius (issue link optional). Fixes: https://github.com/radius-project/radius/issues/5418 https://github.com/radius-project/radius/issues/6293 --------- Signed-off-by: karishma-chawla <74574173+karishma-chawla@users.noreply.github.com> Co-authored-by: karishma-chawla <74574173+karishma-chawla@users.noreply.github.com> --- .../datastoresrp/resources/mongodb_test.go | 56 ------------------- .../shared/resources/recipe_bicep_test.go | 47 ++++++++++++++++ .../context-parameter.bicep | 12 ++++ 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep diff --git a/test/functional/datastoresrp/resources/mongodb_test.go b/test/functional/datastoresrp/resources/mongodb_test.go index a9995f2d8ea..beed65f745b 100644 --- a/test/functional/datastoresrp/resources/mongodb_test.go +++ b/test/functional/datastoresrp/resources/mongodb_test.go @@ -17,7 +17,6 @@ limitations under the License. package resource_test import ( - "os" "testing" "github.com/radius-project/radius/test/functional" @@ -117,58 +116,3 @@ func Test_MongoDB_Recipe(t *testing.T) { test.Test(t) } - -// Test_MongoDB_Recipe_ContextParameter validates creation of a mongoDB from -// a default recipe using the context parameter generated and set by DatastoresRP, -// and container using the mongoDatabases portable resource to connect to the underlying mongoDB resource. -func Test_MongoDB_Recipe_ContextParameter(t *testing.T) { - t.Skip("Skipping test as creating/deleting cosmosdb resource is unreliable - https://github.com/radius-project/radius/issues/5929") - - template := "testdata/datastoresrp-resources-mongodb-recipe-context.bicep" - name := "dsrp-resources-mongodb-recipe-context" - appNamespace := "dsrp-resources-mongodb-recipe-context-app" - rg := os.Getenv("INTEGRATION_TEST_RESOURCE_GROUP_NAME") - // Error the test if INTEGRATION_TEST_RESOURCE_GROUP_NAME is not set - // for running locally set the INTEGRATION_TEST_RESOURCE_GROUP_NAME with the test resourceGroup - if rg == "" { - t.Error("This test needs the env variable INTEGRATION_TEST_RESOURCE_GROUP_NAME to be set") - } - - test := shared.NewRPTest(t, name, []shared.TestStep{ - { - Executor: step.NewDeployExecutor(template, functional.GetMagpieImage(), functional.GetBicepRecipeRegistry(), functional.GetBicepRecipeVersion()), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: "dsrp-resources-env-recipes-context-env", - Type: validation.EnvironmentsResource, - }, - { - Name: name, - Type: validation.ApplicationsResource, - App: name, - }, - { - Name: "mdb-ctx-ctnr", - Type: validation.ContainersResource, - App: name, - }, - { - Name: "mdb-ctx", - Type: validation.MongoDatabasesResource, - App: name, - }, - }, - }, - K8sObjects: &validation.K8sObjectSet{ - Namespaces: map[string][]validation.K8sObject{ - appNamespace: { - validation.NewK8sPodForResource(name, "mdb-ctx-ctnr").ValidateLabels(false), - }, - }, - }, - }, - }) - - test.Test(t) -} diff --git a/test/functional/shared/resources/recipe_bicep_test.go b/test/functional/shared/resources/recipe_bicep_test.go index 3141f40f70b..59b4adc26e8 100644 --- a/test/functional/shared/resources/recipe_bicep_test.go +++ b/test/functional/shared/resources/recipe_bicep_test.go @@ -110,6 +110,53 @@ func Test_BicepRecipe_ParametersAndOutputs(t *testing.T) { test.Test(t) } +// This test validates that the recipe context parameter is populated as expected. +func Test_BicepRecipe_ContextParameter(t *testing.T) { + template := "testdata/corerp-resources-recipe-bicep.bicep" + name := "corerp-resources-recipe-bicep-contextparameter" + + parameters := []string{ + functional.GetBicepRecipeRegistry(), + functional.GetBicepRecipeVersion(), + fmt.Sprintf("basename=%s", name), + fmt.Sprintf("recipe=%s", "context-parameter"), + } + + test := shared.NewRPTest(t, name, []shared.TestStep{ + { + Executor: step.NewDeployExecutor(template, parameters...), + RPResources: &validation.RPResourceSet{ + Resources: []validation.RPResource{ + { + Name: name, + Type: validation.ApplicationsResource, + }, + { + Name: name, + Type: validation.ExtendersResource, + }, + }, + }, + K8sObjects: &validation.K8sObjectSet{}, + PostStepVerify: func(ctx context.Context, t *testing.T, test shared.RPTest) { + resource, err := test.Options.ManagementClient.ShowResource(ctx, "Applications.Core/extenders", name) + require.NoError(t, err) + + text, err := json.MarshalIndent(resource, "", " ") + require.NoError(t, err) + t.Logf("resource data:\n %s", text) + + require.Equal(t, name, resource.Properties["environment"]) + require.Equal(t, name, resource.Properties["application"]) + require.Equal(t, name, resource.Properties["resource"]) + require.Equal(t, name+"-app", resource.Properties["namespace"]) + require.Equal(t, name+"-env", resource.Properties["envNamespace"]) + }, + }, + }) + test.Test(t) +} + // This test actually creates a Radius resource using a recipe (yeah, not a real user scenario). // // The purpose of this test is to test creation and behavior of **output resources**. This way we diff --git a/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep new file mode 100644 index 00000000000..b961d8acdc0 --- /dev/null +++ b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep @@ -0,0 +1,12 @@ +// A simple Bicep recipe that tests context parameter is applied. It doesn't provision any resources. +param context object + +output result object = { + values: { + environment: context.environment.Name + application: context.application.Name + resource: context.resource.Name + namespace: context.runtime.kubernetes.namespace + envNamespace: context.runtime.kubernetes.environmentNamespace + } +}