diff --git a/tfexec/internal/e2etest/errors_test.go b/tfexec/internal/e2etest/errors_test.go index cd7b97df..d032c12b 100644 --- a/tfexec/internal/e2etest/errors_test.go +++ b/tfexec/internal/e2etest/errors_test.go @@ -43,7 +43,12 @@ func TestMissingVar(t *testing.T) { t.Fatalf("err during init: %s", err) } - _, err = tf.Plan(context.Background()) + // Variable names from testdata/var/main.tf + shortVarName := "no_default" + longVarName := "no_default_really_long_variable_name_that_will_line_wrap_tf_output" + + // Test for ErrMissingVar and properly formatted error message on shorter variable names + _, err = tf.Plan(context.Background(), tfexec.Var(longVarName+"=foo")) if err == nil { t.Fatalf("expected error running Plan, none returned") } @@ -52,11 +57,25 @@ func TestMissingVar(t *testing.T) { t.Fatalf("expected ErrMissingVar, got %T, %s", err, err) } - if e.VariableName != "no_default" { - t.Fatalf("expected missing no_default, got %q", e.VariableName) + if e.VariableName != shortVarName { + t.Fatalf("expected missing %s, got %q", shortVarName, e.VariableName) + } + + // Test for ErrMissingVar and properly formatted error message on long variable names + _, err = tf.Plan(context.Background(), tfexec.Var(shortVarName+"=foo")) + if err == nil { + t.Fatalf("expected error running Plan, none returned") + } + if !errors.As(err, &e) { + t.Fatalf("expected ErrMissingVar, got %T, %s", err, err) + } + + if e.VariableName != longVarName { + t.Fatalf("expected missing %s, got %q", longVarName, e.VariableName) } - _, err = tf.Plan(context.Background(), tfexec.Var("no_default=foo")) + // Test for no error when all variables have a value + _, err = tf.Plan(context.Background(), tfexec.Var(shortVarName+"=foo"), tfexec.Var(longVarName+"=foo")) if err != nil { t.Fatalf("expected no error, got %s", err) } diff --git a/tfexec/internal/e2etest/testdata/var/main.tf b/tfexec/internal/e2etest/testdata/var/main.tf index 4abb28c3..4911386a 100644 --- a/tfexec/internal/e2etest/testdata/var/main.tf +++ b/tfexec/internal/e2etest/testdata/var/main.tf @@ -3,4 +3,7 @@ variable "default" { } variable "no_default" { -} \ No newline at end of file +} + +variable "no_default_really_long_variable_name_that_will_line_wrap_tf_output" { +}