github.com/opentofu/opentofu@v1.7.1/internal/plans/plan_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 plans 7 8 import ( 9 "testing" 10 11 "github.com/go-test/deep" 12 13 "github.com/opentofu/opentofu/internal/addrs" 14 ) 15 16 func TestProviderAddrs(t *testing.T) { 17 18 plan := &Plan{ 19 VariableValues: map[string]DynamicValue{}, 20 Changes: &Changes{ 21 Resources: []*ResourceInstanceChangeSrc{ 22 { 23 Addr: addrs.Resource{ 24 Mode: addrs.ManagedResourceMode, 25 Type: "test_thing", 26 Name: "woot", 27 }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), 28 ProviderAddr: addrs.AbsProviderConfig{ 29 Module: addrs.RootModule, 30 Provider: addrs.NewDefaultProvider("test"), 31 }, 32 }, 33 { 34 Addr: addrs.Resource{ 35 Mode: addrs.ManagedResourceMode, 36 Type: "test_thing", 37 Name: "woot", 38 }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), 39 DeposedKey: "foodface", 40 ProviderAddr: addrs.AbsProviderConfig{ 41 Module: addrs.RootModule, 42 Provider: addrs.NewDefaultProvider("test"), 43 }, 44 }, 45 { 46 Addr: addrs.Resource{ 47 Mode: addrs.ManagedResourceMode, 48 Type: "test_thing", 49 Name: "what", 50 }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), 51 ProviderAddr: addrs.AbsProviderConfig{ 52 Module: addrs.RootModule.Child("foo"), 53 Provider: addrs.NewDefaultProvider("test"), 54 }, 55 }, 56 }, 57 }, 58 } 59 60 got := plan.ProviderAddrs() 61 want := []addrs.AbsProviderConfig{ 62 addrs.AbsProviderConfig{ 63 Module: addrs.RootModule.Child("foo"), 64 Provider: addrs.NewDefaultProvider("test"), 65 }, 66 addrs.AbsProviderConfig{ 67 Module: addrs.RootModule, 68 Provider: addrs.NewDefaultProvider("test"), 69 }, 70 } 71 72 for _, problem := range deep.Equal(got, want) { 73 t.Error(problem) 74 } 75 } 76 77 // Module outputs should not effect the result of Empty 78 func TestModuleOutputChangesEmpty(t *testing.T) { 79 changes := &Changes{ 80 Outputs: []*OutputChangeSrc{ 81 { 82 Addr: addrs.AbsOutputValue{ 83 Module: addrs.RootModuleInstance.Child("child", addrs.NoKey), 84 OutputValue: addrs.OutputValue{ 85 Name: "output", 86 }, 87 }, 88 ChangeSrc: ChangeSrc{ 89 Action: Update, 90 Before: []byte("a"), 91 After: []byte("b"), 92 }, 93 }, 94 }, 95 } 96 97 if !changes.Empty() { 98 t.Fatal("plan has no visible changes") 99 } 100 }