|
|
|
|
@ -18,6 +18,7 @@ import (
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-version"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/configs"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
|
|
|
@ -2620,6 +2621,96 @@ func TestInit_invalidBuiltInProviders(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInit_invalidSyntaxNoBackend(t *testing.T) {
|
|
|
|
|
td := t.TempDir()
|
|
|
|
|
testCopyDir(t, testFixturePath("init-syntax-invalid-no-backend"), td)
|
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
view, _ := testView(t)
|
|
|
|
|
m := Meta{
|
|
|
|
|
Ui: ui,
|
|
|
|
|
View: view,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c := &InitCommand{
|
|
|
|
|
Meta: m,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if code := c.Run(nil); code == 0 {
|
|
|
|
|
t.Fatalf("succeeded, but was expecting error\nstdout:\n%s\nstderr:\n%s", ui.OutputWriter, ui.ErrorWriter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errStr := ui.ErrorWriter.String()
|
|
|
|
|
if subStr := "There are some problems with the configuration, described below"; !strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should include preamble\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
if subStr := "Error: Unsupported block type"; !strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should mention the syntax problem\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInit_invalidSyntaxWithBackend(t *testing.T) {
|
|
|
|
|
td := t.TempDir()
|
|
|
|
|
testCopyDir(t, testFixturePath("init-syntax-invalid-with-backend"), td)
|
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
view, _ := testView(t)
|
|
|
|
|
m := Meta{
|
|
|
|
|
Ui: ui,
|
|
|
|
|
View: view,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c := &InitCommand{
|
|
|
|
|
Meta: m,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if code := c.Run(nil); code == 0 {
|
|
|
|
|
t.Fatalf("succeeded, but was expecting error\nstdout:\n%s\nstderr:\n%s", ui.OutputWriter, ui.ErrorWriter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errStr := ui.ErrorWriter.String()
|
|
|
|
|
if subStr := "There are some problems with the configuration, described below"; !strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should include preamble\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
if subStr := "Error: Unsupported block type"; !strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should mention the syntax problem\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInit_invalidSyntaxInvalidBackend(t *testing.T) {
|
|
|
|
|
td := t.TempDir()
|
|
|
|
|
testCopyDir(t, testFixturePath("init-syntax-invalid-backend-invalid"), td)
|
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
|
view, _ := testView(t)
|
|
|
|
|
m := Meta{
|
|
|
|
|
Ui: ui,
|
|
|
|
|
View: view,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c := &InitCommand{
|
|
|
|
|
Meta: m,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if code := c.Run(nil); code == 0 {
|
|
|
|
|
t.Fatalf("succeeded, but was expecting error\nstdout:\n%s\nstderr:\n%s", ui.OutputWriter, ui.ErrorWriter)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errStr := ui.ErrorWriter.String()
|
|
|
|
|
if subStr := "There are some problems with the configuration, described below"; strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should not include preamble\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
if subStr := "Error: Unsupported block type"; strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should not mention syntax errors\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
if subStr := "Error: Unsupported backend type"; !strings.Contains(errStr, subStr) {
|
|
|
|
|
t.Errorf("Error output should mention the invalid backend\nwant substr: %s\ngot:\n%s", subStr, errStr)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newMockProviderSource is a helper to succinctly construct a mock provider
|
|
|
|
|
// source that contains a set of packages matching the given provider versions
|
|
|
|
|
// that are available for installation (from temporary local files).
|
|
|
|
|
|