helper/resource: test for failing id-only refresh check

This commit is contained in:
Mitchell Hashimoto 2016-04-20 09:18:25 -07:00
parent 060b43fbd9
commit 86e0c853db
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 50 additions and 0 deletions

View File

@ -128,6 +128,56 @@ func TestTest_idRefresh(t *testing.T) {
}
}
func TestTest_idRefreshFail(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.ApplyReturn = &terraform.InstanceState{
ID: "foo",
}
var refreshCount int32
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
atomic.AddInt32(&refreshCount, 1)
if atomic.LoadInt32(&refreshCount) == expectedRefresh-1 {
return &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{"foo": "bar"},
}, nil
} else if atomic.LoadInt32(&refreshCount) < expectedRefresh {
return &terraform.InstanceState{ID: "foo"}, nil
} else {
return nil, nil
}
}
mt := new(mockT)
Test(mt, TestCase{
Providers: map[string]terraform.ResourceProvider{
"test": mp,
},
Steps: []TestStep{
TestStep{
Config: testConfigStr,
},
},
})
if !mt.failed() {
t.Fatal("test didn't fail")
}
// See declaration of expectedRefresh for why that number
if refreshCount != expectedRefresh {
t.Fatalf("bad refresh count: %d", refreshCount)
}
}
func TestTest_empty(t *testing.T) {
destroyCalled := false
checkDestroyFn := func(*terraform.State) error {