From db1a623ed4dcbcadf1752b103aa759ea0393faec Mon Sep 17 00:00:00 2001 From: Ben Drucker Date: Wed, 6 May 2020 18:54:25 -0700 Subject: [PATCH] backend/terraform: additional test coverage for error cases in getBackend --- .../terraform/data_source_state_test.go | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/builtin/providers/terraform/data_source_state_test.go b/builtin/providers/terraform/data_source_state_test.go index 995bca5dcf..7123ef1ed0 100644 --- a/builtin/providers/terraform/data_source_state_test.go +++ b/builtin/providers/terraform/data_source_state_test.go @@ -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" ) @@ -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"), @@ -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) {