From 6108d14981facdfb90813a4b644079aece2df18f Mon Sep 17 00:00:00 2001 From: Shruthi Kumar Date: Wed, 31 Jan 2024 15:25:40 -0600 Subject: [PATCH] Re-enable skipped test `Test_RecipeCommands` (#7080) # Description This re-enables `Test_RecipeCommands` ## 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 #6776 Fixes: #6776 --------- Signed-off-by: sk593 Co-authored-by: Karishma Chawla --- test/functional/shared/cli/cli_test.go | 66 +++++++++---------- .../corerp-resources-recipe-env.bicep | 8 ++- .../corerp-resources-extender-recipe.bicep | 5 +- .../corerp-redis-recipe.bicep | 4 +- 4 files changed, 45 insertions(+), 38 deletions(-) rename test/functional/shared/{cli/testdata => resources/testdata/recipes/test-bicep-recipes}/corerp-redis-recipe.bicep (83%) diff --git a/test/functional/shared/cli/cli_test.go b/test/functional/shared/cli/cli_test.go index b832e7b7fa..db16ddc634 100644 --- a/test/functional/shared/cli/cli_test.go +++ b/test/functional/shared/cli/cli_test.go @@ -62,24 +62,32 @@ const ( func verifyRecipeCLI(ctx context.Context, t *testing.T, test shared.RPTest) { options := shared.NewRPTestOptions(t) cli := radcli.NewCLI(t, options.ConfigFilePath) - // get the current environment to switch back to after the test since the environment is used - // for AWS test and has the AWS scope which the environment created in this does not. envName := test.Steps[0].RPResources.Resources[0].Name - recipeName := "recipeName" - recipeTemplate := "ghcr.io/testpublicrecipe/bicep/modules/testTemplate:v1" - templateKind := "bicep" - resourceType := "Applications.Datastores/mongoDatabases" - file := "testdata/corerp-redis-recipe.bicep" + registry := strings.TrimPrefix(functional.GetBicepRecipeRegistry(), "registry=") + version := strings.TrimPrefix(functional.GetBicepRecipeVersion(), "version=") + resourceType := "Applications.Datastores/redisCaches" + file := "../../shared/resources/testdata/recipes/test-bicep-recipes/corerp-redis-recipe.bicep" target := fmt.Sprintf("br:ghcr.io/radius-project/dev/test-bicep-recipes/redis-recipe:%s", generateUniqueTag()) + recipeName := "recipeName" + recipeTemplate := fmt.Sprintf("%s/recipes/local-dev/rediscaches:%s", registry, version) + + bicepRecipe := "recipe1" + bicepRecipeTemplate := fmt.Sprintf("%s/test/functional/shared/recipes/corerp-redis-recipe:%s", registry, version) + templateKindBicep := "bicep" + + terraformRecipe := "recipe2" + terraformRecipeTemplate := "Azure/cosmosdb/azurerm" + templateKindTerraform := "terraform" + t.Run("Validate rad recipe register", func(t *testing.T) { - output, err := cli.RecipeRegister(ctx, envName, recipeName, templateKind, recipeTemplate, resourceType, false) + output, err := cli.RecipeRegister(ctx, envName, recipeName, templateKindBicep, recipeTemplate, resourceType, false) require.NoError(t, err) require.Contains(t, output, "Successfully linked recipe") }) t.Run("Validate rad recipe register with insecure registry", func(t *testing.T) { - output, err := cli.RecipeRegister(ctx, envName, recipeName, templateKind, recipeTemplate, resourceType, true) + output, err := cli.RecipeRegister(ctx, envName, recipeName, templateKindBicep, recipeTemplate, resourceType, true) require.NoError(t, err) require.Contains(t, output, "Successfully linked recipe") }) @@ -87,10 +95,15 @@ func verifyRecipeCLI(ctx context.Context, t *testing.T, test shared.RPTest) { t.Run("Validate rad recipe list", func(t *testing.T) { output, err := cli.RecipeList(ctx, envName) require.NoError(t, err) + require.Regexp(t, bicepRecipe, output) + require.Regexp(t, terraformRecipe, output) require.Regexp(t, recipeName, output) require.Regexp(t, resourceType, output) + require.Regexp(t, bicepRecipeTemplate, output) + require.Regexp(t, terraformRecipeTemplate, output) require.Regexp(t, recipeTemplate, output) - require.Regexp(t, "true", output) + require.Regexp(t, templateKindBicep, output) + require.Regexp(t, templateKindTerraform, output) }) t.Run("Validate rad recipe unregister", func(t *testing.T) { @@ -100,31 +113,19 @@ func verifyRecipeCLI(ctx context.Context, t *testing.T, test shared.RPTest) { }) t.Run("Validate rad recipe show", func(t *testing.T) { - showRecipeName := "mongodbtest" - showRecipeTemplate := "ghcr.io/radius-project/dev/recipes/functionaltest/parameters/mongodatabases/azure:1.0" - showRecipeResourceType := "Applications.Datastores/mongoDatabases" - output, err := cli.RecipeRegister(ctx, envName, showRecipeName, templateKind, showRecipeTemplate, showRecipeResourceType, false) + output, err := cli.RecipeShow(ctx, envName, bicepRecipe, resourceType) require.NoError(t, err) - require.Contains(t, output, "Successfully linked recipe") - output, err = cli.RecipeShow(ctx, envName, showRecipeName, resourceType) - require.NoError(t, err) - require.Contains(t, output, showRecipeName) - require.Contains(t, output, showRecipeTemplate) - require.Contains(t, output, showRecipeResourceType) - require.Contains(t, output, "mongodbName") - require.Contains(t, output, "documentdbName") - require.Contains(t, output, "location") + require.Contains(t, output, bicepRecipe) + require.Contains(t, output, bicepRecipeTemplate) + require.Contains(t, output, resourceType) + require.Contains(t, output, "redisName") require.Contains(t, output, "string") - require.Contains(t, output, "resourceGroup().location]") }) t.Run("Validate rad recipe show - terraform recipe", func(t *testing.T) { showRecipeName := "redistesttf" - moduleServer := os.Getenv("TF_RECIPE_MODULE_SERVER_URL") - if moduleServer == "" { - moduleServer = "http://localhost:8999" - } - showRecipeTemplate := fmt.Sprintf("%s/kubernetes-redis.zip", moduleServer) + moduleServer := strings.TrimPrefix(functional.GetTerraformRecipeModuleServerURL(), "moduleServer=") + showRecipeTemplate := fmt.Sprintf("%s/kubernetes-redis.zip//modules", moduleServer) showRecipeResourceType := "Applications.Datastores/redisCaches" output, err := cli.RecipeRegister(ctx, envName, showRecipeName, "terraform", showRecipeTemplate, showRecipeResourceType, false) require.NoError(t, err) @@ -144,8 +145,8 @@ func verifyRecipeCLI(ctx context.Context, t *testing.T, test shared.RPTest) { require.Contains(t, output, "Successfully published") }) - t.Run("Validate rad recipe register with recipe name conflicting with dev recipe", func(t *testing.T) { - output, err := cli.RecipeRegister(ctx, envName, "mongo-azure", templateKind, recipeTemplate, resourceType, false) + t.Run("Validate rad recipe register with recipe name conflicting with existing recipe", func(t *testing.T) { + output, err := cli.RecipeRegister(ctx, envName, bicepRecipe, templateKindBicep, recipeTemplate, resourceType, false) require.Contains(t, output, "Successfully linked recipe") require.NoError(t, err) output, err = cli.RecipeList(ctx, envName) @@ -692,13 +693,12 @@ func Test_CLI_Only_version(t *testing.T) { } func Test_RecipeCommands(t *testing.T) { - t.Skip("TODO: disabling this test temporarily while we determine which recipes it should pull") template := "testdata/corerp-resources-recipe-env.bicep" name := "corerp-resources-recipe-env" test := shared.NewRPTest(t, name, []shared.TestStep{ { - Executor: step.NewDeployExecutor(template), + Executor: step.NewDeployExecutor(template, functional.GetBicepRecipeRegistry(), functional.GetBicepRecipeVersion()), RPResources: &validation.RPResourceSet{ Resources: []validation.RPResource{ { diff --git a/test/functional/shared/cli/testdata/corerp-resources-recipe-env.bicep b/test/functional/shared/cli/testdata/corerp-resources-recipe-env.bicep index 0c01851bed..359b58fccc 100644 --- a/test/functional/shared/cli/testdata/corerp-resources-recipe-env.bicep +++ b/test/functional/shared/cli/testdata/corerp-resources-recipe-env.bicep @@ -2,6 +2,10 @@ import radius as radius @description('Specifies the location for resources.') param location string = 'global' +@description('The OCI registry for test Bicep recipes.') +param registry string +@description('The OCI tag for test Bicep recipes.') +param version string resource env 'Applications.Core/environments@2023-10-01-preview' = { name: 'corerp-resources-recipe-env' @@ -13,10 +17,10 @@ resource env 'Applications.Core/environments@2023-10-01-preview' = { namespace: 'corerp-resources-recipe-env' } recipes: { - 'Applications.Datastores/mongoDatabases':{ + 'Applications.Datastores/redisCaches':{ recipe1: { templateKind: 'bicep' - templatePath: 'ghcr.io/testpublicrecipe/bicep/modules/mongodatabases:v1' + templatePath: '${registry}/test/functional/shared/recipes/corerp-redis-recipe:${version}' } recipe2: { templateKind: 'terraform' diff --git a/test/functional/shared/resources/testdata/corerp-resources-extender-recipe.bicep b/test/functional/shared/resources/testdata/corerp-resources-extender-recipe.bicep index 57db6b55d2..b111e6d8c8 100644 --- a/test/functional/shared/resources/testdata/corerp-resources-extender-recipe.bicep +++ b/test/functional/shared/resources/testdata/corerp-resources-extender-recipe.bicep @@ -1,7 +1,8 @@ import radius as radius -param registry string - +@description('The OCI registry for test Bicep recipes.') +param registry string +@description('The OCI tag for test Bicep recipes.') param version string resource env 'Applications.Core/environments@2023-10-01-preview' = { diff --git a/test/functional/shared/cli/testdata/corerp-redis-recipe.bicep b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/corerp-redis-recipe.bicep similarity index 83% rename from test/functional/shared/cli/testdata/corerp-redis-recipe.bicep rename to test/functional/shared/resources/testdata/recipes/test-bicep-recipes/corerp-redis-recipe.bicep index 766d295a90..4a11bde123 100644 --- a/test/functional/shared/cli/testdata/corerp-redis-recipe.bicep +++ b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/corerp-redis-recipe.bicep @@ -1,5 +1,7 @@ +param redisName string + resource redis 'Microsoft.Cache/redis@2022-06-01' = { - name: 'rds-${uniqueString(resourceGroup().id, deployment().name)}' + name: 'rds-${uniqueString(resourceGroup().id, redisName, deployment().name)}' location: 'global' properties: { enableNonSslPort: false