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