plugin: tests for ImportState

This commit is contained in:
Mitchell Hashimoto 2016-05-04 12:45:48 -07:00
parent a6b4bb4932
commit ba84485c87
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 39 additions and 0 deletions

View File

@ -317,6 +317,45 @@ func TestResourceProvider_refresh(t *testing.T) {
}
}
func TestResourceProvider_importState(t *testing.T) {
p := new(terraform.MockResourceProvider)
// Create a mock provider
client, _ := plugin.TestPluginRPCConn(t, pluginMap(&ServeOpts{
ProviderFunc: testProviderFixed(p),
}))
defer client.Close()
// Request the provider
raw, err := client.Dispense(ProviderPluginName)
if err != nil {
t.Fatalf("err: %s", err)
}
provider := raw.(terraform.ResourceProvider)
p.ImportStateReturn = []*terraform.InstanceState{
&terraform.InstanceState{
ID: "bob",
},
}
// ImportState
info := &terraform.InstanceInfo{}
states, err := provider.ImportState(info, "foo")
if !p.ImportStateCalled {
t.Fatal("ImportState should be called")
}
if !reflect.DeepEqual(p.ImportStateInfo, info) {
t.Fatalf("bad: %#v", p.ImportStateInfo)
}
if err != nil {
t.Fatalf("bad: %#v", err)
}
if !reflect.DeepEqual(p.ImportStateReturn, states) {
t.Fatalf("bad: %#v", states)
}
}
func TestResourceProvider_resources(t *testing.T) {
p := new(terraform.MockResourceProvider)