command: Update refresh_test.go for new provider types

This only makes it compile. It does not yet ensure that the tests pass.
This commit is contained in:
Martin Atkins 2018-09-30 08:01:59 -07:00
parent b195c712a3
commit dc0b5292a6
1 changed files with 38 additions and 20 deletions

View File

@ -11,8 +11,10 @@ import (
"testing" "testing"
"github.com/mitchellh/cli" "github.com/mitchellh/cli"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/helper/copy" "github.com/hashicorp/terraform/helper/copy"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/states"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -30,8 +32,12 @@ func TestRefresh(t *testing.T) {
}, },
} }
p.RefreshFn = nil p.ReadResourceFn = nil
p.RefreshReturn = &terraform.InstanceState{ID: "yes"} p.ReadResourceResponse = providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yes"),
}),
}
args := []string{ args := []string{
"-state", statePath, "-state", statePath,
@ -41,8 +47,8 @@ func TestRefresh(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if !p.RefreshCalled { if !p.ReadResourceCalled {
t.Fatal("refresh should be called") t.Fatal("ReadResource should have been called")
} }
f, err := os.Open(statePath) f, err := os.Open(statePath)
@ -79,8 +85,12 @@ func TestRefresh_empty(t *testing.T) {
}, },
} }
p.RefreshFn = nil p.ReadResourceFn = nil
p.RefreshReturn = &terraform.InstanceState{ID: "yes"} p.ReadResourceResponse = providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yes"),
}),
}
args := []string{ args := []string{
td, td,
@ -89,8 +99,8 @@ func TestRefresh_empty(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if p.RefreshCalled { if p.ReadResourceCalled {
t.Fatal("refresh should not be called") t.Fatal("ReadResource should not have been called")
} }
} }
@ -113,8 +123,12 @@ func TestRefresh_lockedState(t *testing.T) {
}, },
} }
p.RefreshFn = nil p.ReadResourceFn = nil
p.RefreshReturn = &terraform.InstanceState{ID: "yes"} p.ReadResourceResponse = providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yes"),
}),
}
args := []string{ args := []string{
"-state", statePath, "-state", statePath,
@ -153,8 +167,12 @@ func TestRefresh_cwd(t *testing.T) {
}, },
} }
p.RefreshFn = nil p.ReadResourceFn = nil
p.RefreshReturn = &terraform.InstanceState{ID: "yes"} p.ReadResourceResponse = providers.ReadResourceResponse{
NewState: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yes"),
}),
}
args := []string{ args := []string{
"-state", statePath, "-state", statePath,
@ -163,8 +181,8 @@ func TestRefresh_cwd(t *testing.T) {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
} }
if !p.RefreshCalled { if !p.ReadResourceCalled {
t.Fatal("refresh should be called") t.Fatal("ReadResource should have been called")
} }
f, err := os.Open(statePath) f, err := os.Open(statePath)
@ -369,8 +387,8 @@ func TestRefresh_var(t *testing.T) {
if !p.ConfigureCalled { if !p.ConfigureCalled {
t.Fatal("configure should be called") t.Fatal("configure should be called")
} }
if p.ConfigureConfig.Config["value"].(string) != "bar" { if got, want := p.ConfigureRequest.Config.GetAttr("value"), cty.StringVal("bar"); !want.RawEquals(got) {
t.Fatalf("bad: %#v", p.ConfigureConfig.Config) t.Fatalf("wrong provider configuration\ngot: %#v\nwant: %#v", got, want)
} }
} }
@ -404,8 +422,8 @@ func TestRefresh_varFile(t *testing.T) {
if !p.ConfigureCalled { if !p.ConfigureCalled {
t.Fatal("configure should be called") t.Fatal("configure should be called")
} }
if p.ConfigureConfig.Config["value"].(string) != "bar" { if got, want := p.ConfigureRequest.Config.GetAttr("value"), cty.StringVal("bar"); !want.RawEquals(got) {
t.Fatalf("bad: %#v", p.ConfigureConfig.Config) t.Fatalf("wrong provider configuration\ngot: %#v\nwant: %#v", got, want)
} }
} }
@ -448,8 +466,8 @@ func TestRefresh_varFileDefault(t *testing.T) {
if !p.ConfigureCalled { if !p.ConfigureCalled {
t.Fatal("configure should be called") t.Fatal("configure should be called")
} }
if p.ConfigureConfig.Config["value"].(string) != "bar" { if got, want := p.ConfigureRequest.Config.GetAttr("value"), cty.StringVal("bar"); !want.RawEquals(got) {
t.Fatalf("bad: %#v", p.ConfigureConfig.Config) t.Fatalf("wrong provider configuration\ngot: %#v\nwant: %#v", got, want)
} }
} }