Skip to content

Commit

Permalink
Adding test for long var names in error message
Browse files Browse the repository at this point in the history
  • Loading branch information
c0sco authored and kmoe committed Nov 27, 2020
1 parent fb3bae7 commit 563fa8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
27 changes: 23 additions & 4 deletions tfexec/internal/e2etest/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion tfexec/internal/e2etest/testdata/var/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ variable "default" {
}

variable "no_default" {
}
}

variable "no_default_really_long_variable_name_that_will_line_wrap_tf_output" {
}

0 comments on commit 563fa8b

Please sign in to comment.