-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
063bfec
commit ea95250
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package providers | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/radius-project/radius/pkg/corerp/datamodel" | ||
"github.com/radius-project/radius/pkg/recipes" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetRecipeProviderConfigs(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
envConfig *recipes.Configuration | ||
expected map[string]any | ||
}{ | ||
{ | ||
desc: "envConfig not set", | ||
envConfig: nil, | ||
expected: map[string]any{}, | ||
}, | ||
{ | ||
desc: "no providers configured", | ||
envConfig: &recipes.Configuration{}, | ||
expected: map[string]any{}, | ||
}, | ||
{ | ||
desc: "empty provider config", | ||
envConfig: &recipes.Configuration{ | ||
RecipeConfig: datamodel.RecipeConfigProperties{ | ||
Terraform: datamodel.TerraformConfigProperties{ | ||
Providers: map[string][]datamodel.ProviderConfigProperties{ | ||
"aws": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: map[string]any{}, | ||
}, | ||
{ | ||
desc: "Additional Properties set to nil in provider config", | ||
envConfig: &recipes.Configuration{ | ||
RecipeConfig: datamodel.RecipeConfigProperties{ | ||
Terraform: datamodel.TerraformConfigProperties{ | ||
Providers: map[string][]datamodel.ProviderConfigProperties{ | ||
"aws": { | ||
{ | ||
AdditionalProperties: nil, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: map[string]any{"aws": []any{map[string]any(nil)}}, | ||
}, | ||
{ | ||
desc: "provider with config", | ||
envConfig: &recipes.Configuration{ | ||
RecipeConfig: datamodel.RecipeConfigProperties{ | ||
Terraform: datamodel.TerraformConfigProperties{ | ||
Providers: map[string][]datamodel.ProviderConfigProperties{ | ||
"azurerm": { | ||
{ | ||
AdditionalProperties: map[string]any{ | ||
"subscriptionid": 1234, | ||
"tenant_id": "745fg88bf-86f1-41af-43ut", | ||
}, | ||
}, | ||
{ | ||
AdditionalProperties: map[string]any{ | ||
"alias": "az-paymentservice", | ||
"subscriptionid": 45678, | ||
"tenant_id": "gfhf45345-5d73-gh34-wh84", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: map[string]any{ | ||
"azurerm": []any{ | ||
map[string]any{ | ||
"subscriptionid": 1234, | ||
"tenant_id": "745fg88bf-86f1-41af-43ut", | ||
}, | ||
map[string]any{ | ||
"alias": "az-paymentservice", | ||
"subscriptionid": 45678, | ||
"tenant_id": "gfhf45345-5d73-gh34-wh84", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
result := GetRecipeProviderConfigs(context.Background(), tc.envConfig) | ||
require.Equal(t, tc.expected, result) | ||
}) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
pkg/recipes/terraform/config/testdata/providers-envrecipedefaultconfig.tf.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"terraform": { | ||
"backend": { | ||
"kubernetes": { | ||
"config_path": "/home/radius/.kube/config", | ||
"namespace": "radius-system", | ||
"secret_suffix": "test-secret-suffix" | ||
} | ||
} | ||
}, | ||
"provider": { | ||
"azurerm": [ | ||
null, | ||
{ | ||
"alias": "az-paymentservice", | ||
"subscriptionid": 45678, | ||
"tenant_id": "gfhf45345-5d73-gh34-wh84" | ||
} | ||
] | ||
}, | ||
"module": { | ||
"redis-azure": { | ||
"redis_cache_name": "redis-test", | ||
"resource_group_name": "test-rg", | ||
"sku": "P", | ||
"source": "Azure/redis/azurerm", | ||
"version": "1.1.0" | ||
} | ||
} | ||
} |