mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 10:00:44 -05:00
bugfix(cliconfig.go): emit a warning msg if bad CLI config file path
This commit is contained in:
committed by
James Bardin
parent
15ecdb66c8
commit
fa9d044c58
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user