Skip to content

Commit

Permalink
add coverage for primary error cases in getBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
bendrucker committed May 7, 2020
1 parent a271ca5 commit 979b6ba
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion builtin/providers/terraform/data_source_state_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package terraform

import (
"github.com/hashicorp/terraform/tfdiags"
"testing"

"github.com/apparentlymart/go-dump/dump"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/tfdiags"
"github.com/zclconf/go-cty/cty"
)

Expand Down Expand Up @@ -41,6 +41,26 @@ func TestState_basic(t *testing.T) {
}),
false,
},
"_local": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("_local"),
"config": cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal("./testdata/basic.tfstate"),
}),
}),
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("_local"),
"config": cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal("./testdata/basic.tfstate"),
}),
"outputs": cty.ObjectVal(map[string]cty.Value{
"foo": cty.StringVal("bar"),
}),
"workspace": cty.StringVal(backend.DefaultStateName),
"defaults": cty.NullVal(cty.DynamicPseudoType),
}),
false,
},
"complex outputs": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("local"),
Expand Down Expand Up @@ -213,6 +233,24 @@ func TestState_basic(t *testing.T) {
}),
false,
},
"nonexistent backend": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("nonexistent"),
"config": cty.ObjectVal(map[string]cty.Value{
"path": cty.StringVal("./testdata/basic.tfstate"),
}),
}),
cty.NilVal,
true,
},
"null config": {
cty.ObjectVal(map[string]cty.Value{
"backend": cty.StringVal("local"),
"config": cty.NullVal(cty.DynamicPseudoType),
}),
cty.NilVal,
true,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit 979b6ba

Please sign in to comment.