helper/resource: can specify specific name to id refresh test

This commit is contained in:
Mitchell Hashimoto 2016-04-20 11:12:30 -07:00
parent 1a9fae6b2e
commit 0c8b0bff2c
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 60 additions and 0 deletions

View File

@ -179,6 +179,14 @@ func Test(t TestT, c TestCase) {
// Find the first non-nil resource in the state
for _, m := range state.Modules {
if len(m.Resources) > 0 {
if c.IDRefreshName != "" {
if v, ok := m.Resources[c.IDRefreshName]; ok {
idRefreshCheck = v
}
break
}
for _, v := range m.Resources {
if v != nil && v.Primary != nil {
idRefreshCheck = v

View File

@ -145,6 +145,58 @@ func TestTest_idRefresh(t *testing.T) {
}
}
func TestTest_idRefreshCustomName(t *testing.T) {
// Refresh count should be 3:
// 1.) initial Ref/Plan/Apply
// 2.) post Ref/Plan/Apply for plan-check
// 3.) id refresh check
var expectedRefresh int32 = 3
mp := testProvider()
mp.DiffReturn = nil
mp.ApplyFn = func(
info *terraform.InstanceInfo,
state *terraform.InstanceState,
diff *terraform.InstanceDiff) (*terraform.InstanceState, error) {
if !diff.Destroy {
return &terraform.InstanceState{
ID: "foo",
}, nil
}
return nil, nil
}
var refreshCount int32
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
atomic.AddInt32(&refreshCount, 1)
return &terraform.InstanceState{ID: "foo"}, nil
}
mt := new(mockT)
Test(mt, TestCase{
IDRefreshName: "test_instance.foo",
Providers: map[string]terraform.ResourceProvider{
"test": mp,
},
Steps: []TestStep{
TestStep{
Config: testConfigStr,
},
},
})
if mt.failed() {
t.Fatalf("test failed: %s", mt.failMessage())
}
// See declaration of expectedRefresh for why that number
if refreshCount != expectedRefresh {
t.Fatalf("bad refresh count: %d", refreshCount)
}
}
func TestTest_idRefreshDisable(t *testing.T) {
mp := testProvider()
mp.DiffReturn = nil