helper/resource: Failure case for ImportStateIdFunc
Just to make sure returning an error was working.
This commit is contained in:
parent
7bba1d0c95
commit
dc1f155728
|
@ -1,6 +1,7 @@
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -446,3 +447,58 @@ func TestTest_importStateIdFunc(t *testing.T) {
|
||||||
t.Fatal("didn't call check")
|
t.Fatal("didn't call check")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTest_importStateIdFuncFail(t *testing.T) {
|
||||||
|
mp := testProvider()
|
||||||
|
mp.ImportStateFn = func(
|
||||||
|
info *terraform.InstanceInfo, id string) ([]*terraform.InstanceState, error) {
|
||||||
|
if id != "foo:bar" {
|
||||||
|
return nil, fmt.Errorf("bad import ID: %s", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []*terraform.InstanceState{
|
||||||
|
{
|
||||||
|
ID: "foo",
|
||||||
|
Ephemeral: terraform.EphemeralState{Type: "test_instance"},
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mp.RefreshFn = func(
|
||||||
|
i *terraform.InstanceInfo,
|
||||||
|
s *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
checked := false
|
||||||
|
checkFn := func(s []*terraform.InstanceState) error {
|
||||||
|
checked = true
|
||||||
|
|
||||||
|
if s[0].ID != "foo" {
|
||||||
|
return fmt.Errorf("bad: %#v", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
mt := new(mockT)
|
||||||
|
Test(mt, TestCase{
|
||||||
|
Providers: map[string]terraform.ResourceProvider{
|
||||||
|
"test": mp,
|
||||||
|
},
|
||||||
|
|
||||||
|
Steps: []TestStep{
|
||||||
|
TestStep{
|
||||||
|
Config: testConfigStrProvider,
|
||||||
|
ResourceName: "test_instance.foo",
|
||||||
|
ImportState: true,
|
||||||
|
ImportStateIdFunc: func(*terraform.State) (string, error) { return "foo:bar", errors.New("foobar") },
|
||||||
|
ImportStateCheck: checkFn,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if !mt.failed() {
|
||||||
|
t.Fatalf("test should fail")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue