pulumi/pkg/resource/deploy/step_generator_test.go
Pat Gavlin 67ec74bdc5
Pass ignoreChanges to providers. (#3005)
These changes add support for passing `ignoreChanges` paths to resource
providers. This is intended to accommodate providers that perform diffs
between resource inputs and resource state (e.g. all Terraform-based
providers, the k8s provider when using API server dry-runs). These paths
are specified using the same syntax as the paths used in detailed diffs.

In addition to passing these paths to providers, the existing support
for `ignoreChanges` in inputs has been extended to accept paths rather
than top-level keys. It is an error to specify a path that is missing
one or more component in the old or new inputs.

Fixes #2936, #2663.
2019-07-31 11:39:07 -05:00

116 lines
2.4 KiB
Go

package deploy
import (
"testing"
"github.com/pulumi/pulumi/pkg/resource"
"github.com/stretchr/testify/assert"
)
func TestIgnoreChanges(t *testing.T) {
cases := []struct {
name string
oldInputs map[string]interface{}
newInputs map[string]interface{}
expected map[string]interface{}
ignoreChanges []string
expectFailure bool
}{
{
name: "Present in old and new sets",
oldInputs: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
},
newInputs: map[string]interface{}{
"a": map[string]interface{}{
"b": "bar",
},
"c": 42,
},
expected: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
"c": 42,
},
ignoreChanges: []string{"a.b"},
},
{
name: "Missing in new sets",
oldInputs: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
},
newInputs: map[string]interface{}{
"a": map[string]interface{}{},
"c": 42,
},
expected: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
"c": 42,
},
ignoreChanges: []string{"a.b"},
},
{
name: "Missing in old deletes",
oldInputs: map[string]interface{}{},
newInputs: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
"c": 42,
},
expected: map[string]interface{}{
"a": map[string]interface{}{},
"c": 42,
},
ignoreChanges: []string{"a.b"},
},
{
name: "Missing keys in old and new are OK",
oldInputs: map[string]interface{}{},
newInputs: map[string]interface{}{},
ignoreChanges: []string{
"a",
"a.b",
"a.c[0]",
},
},
{
name: "Missing parent keys in only new fail",
oldInputs: map[string]interface{}{
"a": map[string]interface{}{
"b": "foo",
},
},
newInputs: map[string]interface{}{},
ignoreChanges: []string{"a.b"},
expectFailure: true,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
olds, news := resource.NewPropertyMapFromMap(c.oldInputs), resource.NewPropertyMapFromMap(c.newInputs)
expected := olds
if c.expected != nil {
expected = resource.NewPropertyMapFromMap(c.expected)
}
processed, res := processIgnoreChanges(news, olds, c.ignoreChanges)
if c.expectFailure {
assert.NotNil(t, res)
} else {
assert.Nil(t, res)
assert.Equal(t, expected, processed)
}
})
}
}