opentofu/terraform/context_import_test.go

47 lines
819 B
Go
Raw Normal View History

package terraform
import (
"strings"
"testing"
)
2016-04-28 12:25:58 -05:00
func TestContextImport_basic(t *testing.T) {
p := testProvider("aws")
ctx := testContext2(t, &ContextOpts{
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
2016-04-28 12:25:58 -05:00
p.ImportStateReturn = []*InstanceState{
&InstanceState{
ID: "foo",
Ephemeral: EphemeralState{Type: "aws_instance"},
},
}
state, err := ctx.Import(&ImportOpts{
Targets: []*ImportTarget{
&ImportTarget{
Addr: "aws_instance.foo",
ID: "bar",
},
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(state.String())
expected := strings.TrimSpace(testImportStr)
if actual != expected {
t.Fatalf("bad: \n%s", actual)
}
}
2016-04-28 12:25:58 -05:00
const testImportStr = `
aws_instance.foo:
ID = foo
provider = aws
`