bugfix(cliconfig.go): emit a warning msg if bad CLI config file path

This commit is contained in:
Reda Khaled
2023-03-07 17:39:41 +01:00
committed by James Bardin
parent 15ecdb66c8
commit fa9d044c58
2 changed files with 41 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform/internal/tfdiags"
)
// This is the directory where our test fixtures are.
@@ -55,6 +56,31 @@ func TestLoadConfig_envSubst(t *testing.T) {
}
}
func TestLoadConfig_non_existing_file(t *testing.T) {
tmpDir := os.TempDir()
cliTmpFile := filepath.Join(tmpDir, "dev.tfrc")
os.Setenv("TF_CLI_CONFIG_FILE", cliTmpFile)
defer os.Unsetenv("TF_CLI_CONFIG_FILE")
c, errs := LoadConfig()
if errs.HasErrors() || c.Validate().HasErrors() {
t.Fatalf("err: %s", errs)
}
hasOpenFileWarn := false
for _, err := range errs {
if err.Severity() == tfdiags.Warning && err.Description().Summary == "Unable to open CLI configuration file" {
hasOpenFileWarn = true
break
}
}
if !hasOpenFileWarn {
t.Fatal("expecting a warning message because of nonexisting CLI configuration file")
}
}
func TestEnvConfig(t *testing.T) {
tests := map[string]struct {
env map[string]string