github.com/federicobaldo/terraform@v0.6.15-0.20160323222747-b20f680cbf05/terraform/eval_provider_test.go (about)

     1  package terraform
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestEvalBuildProviderConfig_impl(t *testing.T) {
     9  	var _ EvalNode = new(EvalBuildProviderConfig)
    10  }
    11  
    12  func TestEvalBuildProviderConfig(t *testing.T) {
    13  	config := testResourceConfig(t, map[string]interface{}{})
    14  	provider := "foo"
    15  
    16  	n := &EvalBuildProviderConfig{
    17  		Provider: provider,
    18  		Config:   &config,
    19  		Output:   &config,
    20  	}
    21  
    22  	ctx := &MockEvalContext{
    23  		ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
    24  			"foo": "bar",
    25  		}),
    26  		ProviderInputConfig: map[string]interface{}{
    27  			"bar": "baz",
    28  		},
    29  	}
    30  	if _, err := n.Eval(ctx); err != nil {
    31  		t.Fatalf("err: %s", err)
    32  	}
    33  
    34  	expected := map[string]interface{}{
    35  		"foo": "bar",
    36  		"bar": "baz",
    37  	}
    38  	if !reflect.DeepEqual(config.Raw, expected) {
    39  		t.Fatalf("bad: %#v", config.Raw)
    40  	}
    41  }
    42  
    43  func TestEvalBuildProviderConfig_parentPriority(t *testing.T) {
    44  	config := testResourceConfig(t, map[string]interface{}{})
    45  	provider := "foo"
    46  
    47  	n := &EvalBuildProviderConfig{
    48  		Provider: provider,
    49  		Config:   &config,
    50  		Output:   &config,
    51  	}
    52  
    53  	ctx := &MockEvalContext{
    54  		ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
    55  			"foo": "bar",
    56  		}),
    57  		ProviderInputConfig: map[string]interface{}{
    58  			"foo": "baz",
    59  		},
    60  	}
    61  	if _, err := n.Eval(ctx); err != nil {
    62  		t.Fatalf("err: %s", err)
    63  	}
    64  
    65  	expected := map[string]interface{}{
    66  		"foo": "bar",
    67  	}
    68  	if !reflect.DeepEqual(config.Raw, expected) {
    69  		t.Fatalf("bad: %#v", config.Raw)
    70  	}
    71  }
    72  
    73  func TestEvalConfigProvider_impl(t *testing.T) {
    74  	var _ EvalNode = new(EvalConfigProvider)
    75  }
    76  
    77  func TestEvalConfigProvider(t *testing.T) {
    78  	config := testResourceConfig(t, map[string]interface{}{})
    79  	provider := &MockResourceProvider{}
    80  	n := &EvalConfigProvider{Config: &config}
    81  
    82  	ctx := &MockEvalContext{ProviderProvider: provider}
    83  	if _, err := n.Eval(ctx); err != nil {
    84  		t.Fatalf("err: %s", err)
    85  	}
    86  
    87  	if !ctx.ConfigureProviderCalled {
    88  		t.Fatal("should be called")
    89  	}
    90  	if !reflect.DeepEqual(ctx.ConfigureProviderConfig, config) {
    91  		t.Fatalf("bad: %#v", ctx.ConfigureProviderConfig)
    92  	}
    93  }
    94  
    95  func TestEvalInitProvider_impl(t *testing.T) {
    96  	var _ EvalNode = new(EvalInitProvider)
    97  }
    98  
    99  func TestEvalInitProvider(t *testing.T) {
   100  	n := &EvalInitProvider{Name: "foo"}
   101  	provider := &MockResourceProvider{}
   102  	ctx := &MockEvalContext{InitProviderProvider: provider}
   103  	if _, err := n.Eval(ctx); err != nil {
   104  		t.Fatalf("err: %s", err)
   105  	}
   106  
   107  	if !ctx.InitProviderCalled {
   108  		t.Fatal("should be called")
   109  	}
   110  	if ctx.InitProviderName != "foo" {
   111  		t.Fatalf("bad: %#v", ctx.InitProviderName)
   112  	}
   113  }
   114  
   115  func TestEvalCloseProvider(t *testing.T) {
   116  	n := &EvalCloseProvider{Name: "foo"}
   117  	provider := &MockResourceProvider{}
   118  	ctx := &MockEvalContext{CloseProviderProvider: provider}
   119  	if _, err := n.Eval(ctx); err != nil {
   120  		t.Fatalf("err: %s", err)
   121  	}
   122  
   123  	if !ctx.CloseProviderCalled {
   124  		t.Fatal("should be called")
   125  	}
   126  	if ctx.CloseProviderName != "foo" {
   127  		t.Fatalf("bad: %#v", ctx.CloseProviderName)
   128  	}
   129  }
   130  
   131  func TestEvalGetProvider_impl(t *testing.T) {
   132  	var _ EvalNode = new(EvalGetProvider)
   133  }
   134  
   135  func TestEvalGetProvider(t *testing.T) {
   136  	var actual ResourceProvider
   137  	n := &EvalGetProvider{Name: "foo", Output: &actual}
   138  	provider := &MockResourceProvider{}
   139  	ctx := &MockEvalContext{ProviderProvider: provider}
   140  	if _, err := n.Eval(ctx); err != nil {
   141  		t.Fatalf("err: %s", err)
   142  	}
   143  	if actual != provider {
   144  		t.Fatalf("bad: %#v", actual)
   145  	}
   146  
   147  	if !ctx.ProviderCalled {
   148  		t.Fatal("should be called")
   149  	}
   150  	if ctx.ProviderName != "foo" {
   151  		t.Fatalf("bad: %#v", ctx.ProviderName)
   152  	}
   153  }