command: Add test for backend config validation

This commit is contained in:
Alisdair McDiarmid 2020-08-26 11:37:11 -04:00
parent f028b0a2bf
commit 45437721c9
1 changed files with 25 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/configs"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/helper/copy"
"github.com/hashicorp/terraform/internal/getproviders"
"github.com/hashicorp/terraform/internal/providercache"
@ -429,6 +430,30 @@ func TestInit_backendConfigFile(t *testing.T) {
t.Errorf("wrong config\ngot: %s\nwant: %s", got, want)
}
})
// simulate the local backend having a required field which is not
// specified in the override file
t.Run("required-argument", func(t *testing.T) {
c := &InitCommand{}
schema := &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"path": {
Type: cty.String,
Optional: true,
},
"workspace_dir": {
Type: cty.String,
Required: true,
},
},
}
flagConfigExtra := newRawFlags("-backend-config")
flagConfigExtra.Set("input.config")
_, diags := c.backendConfigOverrideBody(flagConfigExtra, schema)
if len(diags) != 0 {
t.Errorf("expected no diags, got: %s", diags.Err())
}
})
}
func TestInit_backendConfigFilePowershellConfusion(t *testing.T) {