Skip to content

Commit

Permalink
refactor provisioningParamsAreChanged and add a test to isUpToDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Sushkov (teeverr) committed Sep 25, 2023
1 parent f5df6c5 commit 411752e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
49 changes: 49 additions & 0 deletions pkg/controller/servicecatalog/provisionedproduct/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestIsUpToDate(t *testing.T) {
provisioningArtifactName := provisioningArtifactName
productID := productID
newProductID := newProductID

type want struct {
result bool
err error
Expand Down Expand Up @@ -474,6 +475,54 @@ func TestIsUpToDate(t *testing.T) {
err: nil,
},
},
"ParametersSequenceAreChanged": {
args: args{
provisionedProduct: provisionedProduct([]provisionedProductModifier{
withSpec(v1alpha1.ProvisionedProductParameters{
ProvisioningArtifactID: aws.String(provisioningArtifactID),
ProvisioningParameters: []*v1alpha1.ProvisioningParameter{
{Key: aws.String("Parameter1"), Value: aws.String("foo")},
{Key: aws.String("Parameter2"), Value: aws.String("bar")},
},
}),
}...),
describeProvisionedProductOutput: describeProvisionedProduct([]describeProvisionedProductOutputModifier{
withDetails(svcsdk.ProvisionedProductDetail{
Id: aws.String("pp-fake"),
ProvisioningArtifactId: aws.String(provisioningArtifactID),
}),
}...),
customClient: &fake.MockCustomServiceCatalogClient{
MockGetCloudformationStackParameters: func(provisionedProductOutputs []*svcsdk.RecordOutput) ([]cfsdkv2types.Parameter, error) {
return []cfsdkv2types.Parameter{
{ParameterKey: aws.String("Parameter2"), ParameterValue: aws.String("bar")},
{ParameterKey: aws.String("Parameter1"), ParameterValue: aws.String("foo")},
},
nil
},
MockGetProvisionedProductOutputs: func(getPPInput *svcsdk.GetProvisionedProductOutputsInput) (*svcsdk.GetProvisionedProductOutputsOutput, error) {
return &svcsdk.GetProvisionedProductOutputsOutput{}, nil
},
MockDescribeProduct: func(dpInput *svcsdk.DescribeProductInput) (*svcsdk.DescribeProductOutput, error) {
return &svcsdk.DescribeProductOutput{
ProductViewSummary: &svcsdk.ProductViewSummary{
ProductId: dpInput.Id,
Name: aws.String("fake product"),
},
ProvisioningArtifacts: []*svcsdk.ProvisioningArtifact{
{
Id: aws.String(provisioningArtifactID),
},
},
}, nil
},
},
},
want: want{
result: false,
err: nil,
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
Expand Down
12 changes: 3 additions & 9 deletions pkg/controller/servicecatalog/provisionedproduct/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ func provisioningParamsAreChanged(cfStackParams []cfsdkv2types.Parameter, curren
return true
}

cfStackKeyValue := make(map[string]string)
for _, v := range cfStackParams {
cfStackKeyValue[*v.ParameterKey] = pointer.StringDeref(v.ParameterValue, "")
}

for _, v := range currentParams {
if cfv, ok := cfStackKeyValue[*v.Key]; ok && pointer.StringEqual(&cfv, v.Value) {
continue
} else {
for i, v := range cfStackParams {
if pointer.StringDeref(currentParams[i].Key, "") != pointer.StringDeref(v.ParameterKey, "") ||
pointer.StringDeref(currentParams[i].Value, "") != pointer.StringDeref(v.ParameterValue, "") {
return true
}
}
Expand Down

0 comments on commit 411752e

Please sign in to comment.