github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/e2etest/terraform_test.go (about)

     1  package e2etest
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  	"testing"
     7  
     8  	"github.com/hashicorp/terraform/internal/addrs"
     9  	"github.com/hashicorp/terraform/internal/e2e"
    10  )
    11  
    12  func TestTerraformProviderData(t *testing.T) {
    13  
    14  	fixturePath := filepath.Join("testdata", "terraform-managed-data")
    15  	tf := e2e.NewBinary(t, terraformBin, fixturePath)
    16  
    17  	_, stderr, err := tf.Run("init", "-input=false")
    18  	if err != nil {
    19  		t.Fatalf("unexpected init error: %s\nstderr:\n%s", err, stderr)
    20  	}
    21  
    22  	stdout, stderr, err := tf.Run("plan", "-out=tfplan", "-input=false")
    23  	if err != nil {
    24  		t.Fatalf("unexpected plan error: %s\nstderr:\n%s", err, stderr)
    25  	}
    26  
    27  	if !strings.Contains(stdout, "4 to add, 0 to change, 0 to destroy") {
    28  		t.Errorf("incorrect plan tally; want 4 to add:\n%s", stdout)
    29  	}
    30  
    31  	stdout, stderr, err = tf.Run("apply", "-input=false", "tfplan")
    32  	if err != nil {
    33  		t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
    34  	}
    35  
    36  	if !strings.Contains(stdout, "Resources: 4 added, 0 changed, 0 destroyed") {
    37  		t.Errorf("incorrect apply tally; want 4 added:\n%s", stdout)
    38  	}
    39  
    40  	state, err := tf.LocalState()
    41  	if err != nil {
    42  		t.Fatalf("failed to read state file: %s", err)
    43  	}
    44  
    45  	// we'll check the final output to validate the resources
    46  	d := state.Module(addrs.RootModuleInstance).OutputValues["d"].Value
    47  	input := d.GetAttr("input")
    48  	output := d.GetAttr("output")
    49  	if input.IsNull() {
    50  		t.Fatal("missing input from resource d")
    51  	}
    52  	if !input.RawEquals(output) {
    53  		t.Fatalf("input %#v does not equal output %#v\n", input, output)
    54  	}
    55  }