github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/plans/plan_test.go (about)

     1  package plans
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/go-test/deep"
     7  
     8  	"github.com/hashicorp/terraform-plugin-sdk/internal/addrs"
     9  )
    10  
    11  func TestProviderAddrs(t *testing.T) {
    12  
    13  	plan := &Plan{
    14  		VariableValues: map[string]DynamicValue{},
    15  		Changes: &Changes{
    16  			Resources: []*ResourceInstanceChangeSrc{
    17  				{
    18  					Addr: addrs.Resource{
    19  						Mode: addrs.ManagedResourceMode,
    20  						Type: "test_thing",
    21  						Name: "woot",
    22  					}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
    23  					ProviderAddr: addrs.ProviderConfig{
    24  						Type: "test",
    25  					}.Absolute(addrs.RootModuleInstance),
    26  				},
    27  				{
    28  					Addr: addrs.Resource{
    29  						Mode: addrs.ManagedResourceMode,
    30  						Type: "test_thing",
    31  						Name: "woot",
    32  					}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
    33  					DeposedKey: "foodface",
    34  					ProviderAddr: addrs.ProviderConfig{
    35  						Type: "test",
    36  					}.Absolute(addrs.RootModuleInstance),
    37  				},
    38  				{
    39  					Addr: addrs.Resource{
    40  						Mode: addrs.ManagedResourceMode,
    41  						Type: "test_thing",
    42  						Name: "what",
    43  					}.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance),
    44  					ProviderAddr: addrs.ProviderConfig{
    45  						Type: "test",
    46  					}.Absolute(addrs.RootModuleInstance.Child("foo", addrs.NoKey)),
    47  				},
    48  			},
    49  		},
    50  	}
    51  
    52  	got := plan.ProviderAddrs()
    53  	want := []addrs.AbsProviderConfig{
    54  		addrs.ProviderConfig{
    55  			Type: "test",
    56  		}.Absolute(addrs.RootModuleInstance.Child("foo", addrs.NoKey)),
    57  		addrs.ProviderConfig{
    58  			Type: "test",
    59  		}.Absolute(addrs.RootModuleInstance),
    60  	}
    61  
    62  	for _, problem := range deep.Equal(got, want) {
    63  		t.Error(problem)
    64  	}
    65  }