|
|
|
|
@ -2405,6 +2405,59 @@ func TestContext2Apply_provisionerMultiSelfRef(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestContext2Apply_provisionerMultiSelfRefCount(t *testing.T) {
|
|
|
|
|
var lock sync.Mutex
|
|
|
|
|
commands := make([]string, 0, 5)
|
|
|
|
|
|
|
|
|
|
m := testModule(t, "apply-provisioner-multi-self-ref-count")
|
|
|
|
|
p := testProvider("aws")
|
|
|
|
|
pr := testProvisioner()
|
|
|
|
|
p.ApplyFn = testApplyFn
|
|
|
|
|
p.DiffFn = testDiffFn
|
|
|
|
|
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
|
|
val, ok := c.Config["command"]
|
|
|
|
|
if !ok {
|
|
|
|
|
t.Fatalf("bad value for command: %v %#v", val, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commands = append(commands, val.(string))
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
|
|
|
|
Module: m,
|
|
|
|
|
Providers: map[string]ResourceProviderFactory{
|
|
|
|
|
"aws": testProviderFuncFixed(p),
|
|
|
|
|
},
|
|
|
|
|
Provisioners: map[string]ResourceProvisionerFactory{
|
|
|
|
|
"shell": testProvisionerFuncFixed(pr),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if _, err := ctx.Plan(); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := ctx.Apply(); err != nil {
|
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify apply was invoked
|
|
|
|
|
if !pr.ApplyCalled {
|
|
|
|
|
t.Fatalf("provisioner not invoked")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Verify our result
|
|
|
|
|
sort.Strings(commands)
|
|
|
|
|
expectedCommands := []string{"3", "3", "3"}
|
|
|
|
|
if !reflect.DeepEqual(commands, expectedCommands) {
|
|
|
|
|
t.Fatalf("bad: %#v", commands)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provisioner should NOT run on a diff, only create
|
|
|
|
|
func TestContext2Apply_Provisioner_Diff(t *testing.T) {
|
|
|
|
|
m := testModule(t, "apply-provisioner-diff")
|
|
|
|
|
|