Resource sames test
This commit is contained in:
parent
96af4684db
commit
598f2c7213
|
@ -3115,3 +3115,106 @@ func TestExpectedUnneededDelete(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResoucesWithSames(t *testing.T) {
|
||||||
|
// This test checks that if between generating a constriant and running the update that if new resources have been added to the stack
|
||||||
|
// that the update doesn't change those resources in any way that they don't cause constraint errors
|
||||||
|
|
||||||
|
loaders := []*deploytest.ProviderLoader{
|
||||||
|
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
||||||
|
return &deploytest.Provider{
|
||||||
|
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64,
|
||||||
|
preview bool) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
||||||
|
return "created-id", news, resource.StatusOK, nil
|
||||||
|
},
|
||||||
|
UpdateF: func(urn resource.URN, id resource.ID, olds, news resource.PropertyMap, timeout float64,
|
||||||
|
ignoreChanges []string, preview bool) (resource.PropertyMap, resource.Status, error) {
|
||||||
|
return news, resource.StatusOK, nil
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
var ins resource.PropertyMap
|
||||||
|
createA := false
|
||||||
|
createB := false
|
||||||
|
program := deploytest.NewLanguageRuntime(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
||||||
|
if createA {
|
||||||
|
_, _, _, err := monitor.RegisterResource("pkgA:m:typA", "resA", true, deploytest.ResourceOptions{
|
||||||
|
Inputs: ins,
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if createB {
|
||||||
|
_, _, _, err := monitor.RegisterResource("pkgA:m:typA", "resB", true, deploytest.ResourceOptions{
|
||||||
|
Inputs: resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"X": "Y",
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
host := deploytest.NewPluginHost(nil, nil, program, loaders...)
|
||||||
|
|
||||||
|
p := &TestPlan{
|
||||||
|
Options: UpdateOptions{Host: host},
|
||||||
|
}
|
||||||
|
|
||||||
|
project := p.GetProject()
|
||||||
|
|
||||||
|
// Generate a plan to create A
|
||||||
|
createA = true
|
||||||
|
createB = false
|
||||||
|
computed := interface{}(resource.Computed{Element: resource.NewStringProperty("")})
|
||||||
|
ins = resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
"zed": computed,
|
||||||
|
})
|
||||||
|
plan, res := TestOp(Update).Plan(project, p.GetTarget(nil), p.Options, p.BackendClient, nil)
|
||||||
|
assert.Nil(t, res)
|
||||||
|
|
||||||
|
// Run an update that creates B
|
||||||
|
createA = false
|
||||||
|
createB = true
|
||||||
|
snap, res := TestOp(Update).Run(project, p.GetTarget(nil), p.Options, false, p.BackendClient, nil)
|
||||||
|
assert.Nil(t, res)
|
||||||
|
|
||||||
|
// Check the resource's state.
|
||||||
|
if !assert.Len(t, snap.Resources, 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"X": "Y",
|
||||||
|
})
|
||||||
|
assert.Equal(t, expected, snap.Resources[1].Outputs)
|
||||||
|
|
||||||
|
// Attempt to run an update with the plan on the stack that creates A and sames B
|
||||||
|
createA = true
|
||||||
|
createB = true
|
||||||
|
ins = resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
"zed": 24,
|
||||||
|
})
|
||||||
|
p.Options.Plan = plan
|
||||||
|
snap, res = TestOp(Update).Run(project, p.GetTarget(snap), p.Options, false, p.BackendClient, nil)
|
||||||
|
assert.Nil(t, res)
|
||||||
|
|
||||||
|
// Check the resource's state.
|
||||||
|
if !assert.Len(t, snap.Resources, 3) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"X": "Y",
|
||||||
|
})
|
||||||
|
assert.Equal(t, expected, snap.Resources[1].Outputs)
|
||||||
|
|
||||||
|
expected = resource.NewPropertyMapFromMap(map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
"zed": 24,
|
||||||
|
})
|
||||||
|
assert.Equal(t, expected, snap.Resources[2].Outputs)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue