ARO-RP/pkg/deploy/deploy_test.go

112 строки
2.8 KiB
Go

package deploy
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"reflect"
"testing"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/ARO-RP/pkg/util/arm"
)
func TestGetParameters(t *testing.T) {
databaseAccountName := to.StringPtr("databaseAccountName")
adminApiCaBundle := to.StringPtr("adminApiCaBundle")
extraClusterKeyVaultAccessPolicies := []interface{}{"a", "b", 1}
for _, tt := range []struct {
name string
ps map[string]interface{}
config Configuration
want arm.Parameters
}{
{
name: "when no parameters are present only default is returned",
want: arm.Parameters{
Parameters: map[string]*arm.ParametersParameter{},
},
},
{
name: "when all parameters present, everything is copied",
ps: map[string]interface{}{
"adminApiCaBundle": nil,
"databaseAccountName": nil,
"extraClusterKeyvaultAccessPolicies": nil,
},
config: Configuration{
DatabaseAccountName: databaseAccountName,
AdminAPICABundle: adminApiCaBundle,
ExtraClusterKeyvaultAccessPolicies: extraClusterKeyVaultAccessPolicies,
},
want: arm.Parameters{
Parameters: map[string]*arm.ParametersParameter{
"databaseAccountName": {
Value: databaseAccountName,
},
"extraClusterKeyvaultAccessPolicies": {
Value: extraClusterKeyVaultAccessPolicies,
},
"adminApiCaBundle": {
Value: adminApiCaBundle,
},
},
},
},
{
name: "when parameters with nil config are present, they are not returned",
ps: map[string]interface{}{
"adminApiCaBundle": nil,
"databaseAccountName": nil,
"extraClusterKeyvaultAccessPolicies": nil,
},
config: Configuration{
DatabaseAccountName: databaseAccountName,
},
want: arm.Parameters{
Parameters: map[string]*arm.ParametersParameter{
"databaseAccountName": {
Value: databaseAccountName,
},
},
},
},
{
name: "when nil slice parameter is present it is skipped",
ps: map[string]interface{}{
"extraClusterKeyvaultAccessPolicies": nil,
},
config: Configuration{},
want: arm.Parameters{
Parameters: map[string]*arm.ParametersParameter{},
},
},
{
name: "when malformed parameter is present, it is skipped",
ps: map[string]interface{}{
"dutabaseAccountName": nil,
},
config: Configuration{
DatabaseAccountName: databaseAccountName,
},
want: arm.Parameters{
Parameters: map[string]*arm.ParametersParameter{},
},
},
} {
t.Run(tt.name, func(t *testing.T) {
d := deployer{
config: &RPConfig{Configuration: &tt.config},
}
got := d.getParameters(tt.ps)
if !reflect.DeepEqual(got, &tt.want) {
t.Errorf("%#v", got)
}
})
}
}