helper/resource: fix tests
This commit is contained in:
parent
5c4f78796b
commit
f2c4f8e9ba
|
@ -12,6 +12,11 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
testTesting = true
|
testTesting = true
|
||||||
|
|
||||||
|
// TODO: Remove when we remove the guard on id checks
|
||||||
|
if err := os.Setenv("TF_ACC_IDONLY", "1"); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := os.Setenv(TestEnvVar, "1"); err != nil {
|
if err := os.Setenv(TestEnvVar, "1"); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -21,17 +26,23 @@ func TestTest(t *testing.T) {
|
||||||
mp := testProvider()
|
mp := testProvider()
|
||||||
mp.DiffReturn = nil
|
mp.DiffReturn = nil
|
||||||
|
|
||||||
mp.ApplyReturn = &terraform.InstanceState{
|
mp.ApplyFn = func(
|
||||||
ID: "foo",
|
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
|
var refreshCount int32
|
||||||
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
atomic.AddInt32(&refreshCount, 1)
|
atomic.AddInt32(&refreshCount, 1)
|
||||||
if atomic.LoadInt32(&refreshCount) == 1 {
|
return &terraform.InstanceState{ID: "foo"}, nil
|
||||||
return &terraform.InstanceState{ID: "foo"}, nil
|
|
||||||
} else {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkDestroy := false
|
checkDestroy := false
|
||||||
|
@ -93,17 +104,23 @@ func TestTest_idRefresh(t *testing.T) {
|
||||||
mp := testProvider()
|
mp := testProvider()
|
||||||
mp.DiffReturn = nil
|
mp.DiffReturn = nil
|
||||||
|
|
||||||
mp.ApplyReturn = &terraform.InstanceState{
|
mp.ApplyFn = func(
|
||||||
ID: "foo",
|
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
|
var refreshCount int32
|
||||||
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
atomic.AddInt32(&refreshCount, 1)
|
atomic.AddInt32(&refreshCount, 1)
|
||||||
if atomic.LoadInt32(&refreshCount) < expectedRefresh {
|
return &terraform.InstanceState{ID: "foo"}, nil
|
||||||
return &terraform.InstanceState{ID: "foo"}, nil
|
|
||||||
} else {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mt := new(mockT)
|
mt := new(mockT)
|
||||||
|
@ -138,9 +155,19 @@ func TestTest_idRefreshFail(t *testing.T) {
|
||||||
mp := testProvider()
|
mp := testProvider()
|
||||||
mp.DiffReturn = nil
|
mp.DiffReturn = nil
|
||||||
|
|
||||||
mp.ApplyReturn = &terraform.InstanceState{
|
mp.ApplyFn = func(
|
||||||
ID: "foo",
|
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
|
var refreshCount int32
|
||||||
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
mp.RefreshFn = func(*terraform.InstanceInfo, *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
atomic.AddInt32(&refreshCount, 1)
|
atomic.AddInt32(&refreshCount, 1)
|
||||||
|
@ -171,6 +198,7 @@ func TestTest_idRefreshFail(t *testing.T) {
|
||||||
if !mt.failed() {
|
if !mt.failed() {
|
||||||
t.Fatal("test didn't fail")
|
t.Fatal("test didn't fail")
|
||||||
}
|
}
|
||||||
|
t.Logf("failure reason: %s", mt.failMessage())
|
||||||
|
|
||||||
// See declaration of expectedRefresh for why that number
|
// See declaration of expectedRefresh for why that number
|
||||||
if refreshCount != expectedRefresh {
|
if refreshCount != expectedRefresh {
|
||||||
|
|
Loading…
Reference in New Issue