update command tests to use new mock provider
This commit is contained in:
parent
a0caed541d
commit
027a6c2cf6
|
@ -341,43 +341,26 @@ func TestApply_error(t *testing.T) {
|
|||
|
||||
var lock sync.Mutex
|
||||
errored := false
|
||||
p.ApplyFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
||||
p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
if !errored {
|
||||
errored = true
|
||||
return nil, fmt.Errorf("error")
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("error"))
|
||||
}
|
||||
|
||||
newState := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{},
|
||||
}
|
||||
newState.Attributes["id"] = newState.ID
|
||||
if ad, ok := d.Attributes["ami"]; ok {
|
||||
newState.Attributes["ami"] = ad.New
|
||||
}
|
||||
if ad, ok := d.Attributes["error"]; ok {
|
||||
newState.Attributes["error"] = ad.New
|
||||
}
|
||||
return newState, nil
|
||||
s := req.PlannedState.AsValueMap()
|
||||
s["id"] = cty.StringVal("foo")
|
||||
|
||||
resp.NewState = cty.ObjectVal(s)
|
||||
return
|
||||
}
|
||||
p.DiffFn = func(info *terraform.InstanceInfo, s *terraform.InstanceState, rc *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
ret := &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{},
|
||||
}
|
||||
if new, ok := rc.Get("ami"); ok {
|
||||
ret.Attributes["ami"] = &terraform.ResourceAttrDiff{
|
||||
New: new.(string),
|
||||
}
|
||||
}
|
||||
if new, ok := rc.Get("error"); ok {
|
||||
ret.Attributes["error"] = &terraform.ResourceAttrDiff{
|
||||
New: fmt.Sprintf("%t", new.(bool)),
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
s := req.ProposedNewState.AsValueMap()
|
||||
s["id"] = cty.UnknownVal(cty.String)
|
||||
resp.PlannedState = cty.ObjectVal(s)
|
||||
return
|
||||
}
|
||||
p.GetSchemaReturn = &terraform.ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
|
@ -902,25 +885,13 @@ func TestApply_shutdown(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
p.DiffFn = func(
|
||||
*terraform.InstanceInfo,
|
||||
*terraform.InstanceState,
|
||||
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
return &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"ami": &terraform.ResourceAttrDiff{
|
||||
New: "bar",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
resp.PlannedState = req.ProposedNewState
|
||||
return
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
p.ApplyFn = func(
|
||||
*terraform.InstanceInfo,
|
||||
*terraform.InstanceState,
|
||||
*terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
||||
|
||||
p.ApplyResourceChangeFn = func(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
||||
// only cancel once
|
||||
once.Do(func() {
|
||||
shutdownCh <- struct{}{}
|
||||
|
@ -934,12 +905,8 @@ func TestApply_shutdown(t *testing.T) {
|
|||
// canceled.
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
return &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"ami": "2",
|
||||
},
|
||||
}, nil
|
||||
resp.NewState = req.PlannedState
|
||||
return
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &terraform.ProviderSchema{
|
||||
|
|
|
@ -110,7 +110,7 @@ func TestImport_providerConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
configured = true
|
||||
|
||||
cfg := req.Config
|
||||
|
@ -217,7 +217,7 @@ func TestImport_remoteState(t *testing.T) {
|
|||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
var diags tfdiags.Diagnostics
|
||||
configured = true
|
||||
if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) {
|
||||
|
@ -364,7 +364,7 @@ func TestImport_providerConfigWithVar(t *testing.T) {
|
|||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
var diags tfdiags.Diagnostics
|
||||
configured = true
|
||||
if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) {
|
||||
|
@ -495,7 +495,7 @@ func TestImport_providerConfigWithVarDefault(t *testing.T) {
|
|||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
var diags tfdiags.Diagnostics
|
||||
configured = true
|
||||
if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) {
|
||||
|
@ -568,7 +568,7 @@ func TestImport_providerConfigWithVarFile(t *testing.T) {
|
|||
}
|
||||
|
||||
configured := false
|
||||
p.ConfigureNewFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
p.ConfigureFn = func(req providers.ConfigureRequest) providers.ConfigureResponse {
|
||||
var diags tfdiags.Diagnostics
|
||||
configured = true
|
||||
if got, want := req.Config.GetAttr("foo"), cty.StringVal("bar"); !want.RawEquals(got) {
|
||||
|
|
|
@ -524,15 +524,10 @@ func TestPlan_vars(t *testing.T) {
|
|||
}
|
||||
|
||||
actual := ""
|
||||
p.DiffFn = func(
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
if v, ok := c.Config["value"]; ok {
|
||||
actual = v.(string)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
actual = req.ProposedNewState.GetAttr("value").AsString()
|
||||
resp.PlannedState = req.ProposedNewState
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -656,15 +651,10 @@ func TestPlan_varFile(t *testing.T) {
|
|||
}
|
||||
|
||||
actual := ""
|
||||
p.DiffFn = func(
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
if v, ok := c.Config["value"]; ok {
|
||||
actual = v.(string)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
actual = req.ProposedNewState.GetAttr("value").AsString()
|
||||
resp.PlannedState = req.ProposedNewState
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -706,15 +696,10 @@ func TestPlan_varFileDefault(t *testing.T) {
|
|||
}
|
||||
|
||||
actual := ""
|
||||
p.DiffFn = func(
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
if v, ok := c.Config["value"]; ok {
|
||||
actual = v.(string)
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
actual = req.ProposedNewState.GetAttr("value").AsString()
|
||||
resp.PlannedState = req.ProposedNewState
|
||||
return
|
||||
}
|
||||
|
||||
args := []string{
|
||||
|
@ -824,11 +809,7 @@ func TestPlan_shutdown(t *testing.T) {
|
|||
|
||||
var once sync.Once
|
||||
|
||||
p.DiffFn = func(
|
||||
*terraform.InstanceInfo,
|
||||
*terraform.InstanceState,
|
||||
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
||||
|
||||
p.PlanResourceChangeFn = func(req providers.PlanResourceChangeRequest) (resp providers.PlanResourceChangeResponse) {
|
||||
once.Do(func() {
|
||||
shutdownCh <- struct{}{}
|
||||
})
|
||||
|
@ -841,14 +822,12 @@ func TestPlan_shutdown(t *testing.T) {
|
|||
// canceled.
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
return &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"ami": &terraform.ResourceAttrDiff{
|
||||
New: "bar",
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
s := req.ProposedNewState.AsValueMap()
|
||||
s["ami"] = cty.StringVal("bar")
|
||||
resp.PlannedState = cty.ObjectVal(s)
|
||||
return
|
||||
}
|
||||
|
||||
p.GetSchemaReturn = &terraform.ProviderSchema{
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"test_instance": {
|
||||
|
|
Loading…
Reference in New Issue