helper/resource: pass config when testing import
Previously having a config was mutually exclusive with running an import, but we need to provide a config so that the provider is declared, or else we can't actually complete the import in the future world where providers are installed dynamically based on their declarations.
This commit is contained in:
parent
1c0b715999
commit
0573ff6793
|
@ -400,15 +400,18 @@ func Test(t TestT, c TestCase) {
|
|||
var err error
|
||||
log.Printf("[WARN] Test: Executing step %d", i)
|
||||
|
||||
// Determine the test mode to execute
|
||||
if step.Config != "" {
|
||||
state, err = testStepConfig(opts, state, step)
|
||||
} else if step.ImportState {
|
||||
state, err = testStepImportState(opts, state, step)
|
||||
} else {
|
||||
if step.Config == "" && !step.ImportState {
|
||||
err = fmt.Errorf(
|
||||
"unknown test mode for step. Please see TestStep docs\n\n%#v",
|
||||
step)
|
||||
} else {
|
||||
if step.ImportState {
|
||||
// Can optionally set step.Config in addition to
|
||||
// step.ImportState, to provide config for the import.
|
||||
state, err = testStepImportState(opts, state, step)
|
||||
} else {
|
||||
state, err = testStepConfig(opts, state, step)
|
||||
}
|
||||
}
|
||||
|
||||
// If there was an error, exit
|
||||
|
|
|
@ -40,6 +40,7 @@ func TestTest_importState(t *testing.T) {
|
|||
|
||||
Steps: []TestStep{
|
||||
TestStep{
|
||||
Config: testConfigStrProvider,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateId: "foo",
|
||||
|
@ -89,6 +90,7 @@ func TestTest_importStateFail(t *testing.T) {
|
|||
|
||||
Steps: []TestStep{
|
||||
TestStep{
|
||||
Config: testConfigStrProvider,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateId: "foo",
|
||||
|
@ -163,6 +165,7 @@ func TestTest_importStateDetectId(t *testing.T) {
|
|||
Config: testConfigStr,
|
||||
},
|
||||
TestStep{
|
||||
Config: testConfigStr,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateCheck: checkFn,
|
||||
|
@ -236,6 +239,7 @@ func TestTest_importStateIdPrefix(t *testing.T) {
|
|||
Config: testConfigStr,
|
||||
},
|
||||
{
|
||||
Config: testConfigStr,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateCheck: checkFn,
|
||||
|
@ -309,6 +313,7 @@ func TestTest_importStateVerify(t *testing.T) {
|
|||
Config: testConfigStr,
|
||||
},
|
||||
TestStep{
|
||||
Config: testConfigStr,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
|
@ -371,6 +376,7 @@ func TestTest_importStateVerifyFail(t *testing.T) {
|
|||
Config: testConfigStr,
|
||||
},
|
||||
TestStep{
|
||||
Config: testConfigStr,
|
||||
ResourceName: "test_instance.foo",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
|
|
|
@ -619,10 +619,6 @@ func testProvider() *terraform.MockResourceProvider {
|
|||
return mp
|
||||
}
|
||||
|
||||
const testConfigStr = `
|
||||
resource "test_instance" "foo" {}
|
||||
`
|
||||
|
||||
func TestTest_Main(t *testing.T) {
|
||||
flag.Parse()
|
||||
if *flagSweep == "" {
|
||||
|
@ -777,3 +773,11 @@ func TestTest_Main(t *testing.T) {
|
|||
func mockSweeperFunc(s string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const testConfigStr = `
|
||||
resource "test_instance" "foo" {}
|
||||
`
|
||||
|
||||
const testConfigStrProvider = `
|
||||
provider "test" {}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue