Skip to content

Commit

Permalink
Add Functional Test for Bicep Recipe Context Parameter (radius-projec…
Browse files Browse the repository at this point in the history
…t#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:
radius-project#5418
radius-project#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>
  • Loading branch information
2 people authored and willdavsmith committed Mar 4, 2024
1 parent b2c3dfa commit 5a51f23
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 56 deletions.
56 changes: 0 additions & 56 deletions test/functional/datastoresrp/resources/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package resource_test

import (
"os"
"testing"

"github.com/radius-project/radius/test/functional"
Expand Down Expand Up @@ -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)
}
47 changes: 47 additions & 0 deletions test/functional/shared/resources/recipe_bicep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 5a51f23

Please sign in to comment.