github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/aws/resource_aws_route53_record_migrate_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  func TestAWSRoute53RecordMigrateState(t *testing.T) {
    10  	cases := map[string]struct {
    11  		StateVersion int
    12  		ID           string
    13  		Attributes   map[string]string
    14  		Expected     string
    15  		Meta         interface{}
    16  	}{
    17  		"v0_0": {
    18  			StateVersion: 0,
    19  			ID:           "some_id",
    20  			Attributes: map[string]string{
    21  				"name": "www",
    22  			},
    23  			Expected: "www",
    24  		},
    25  		"v0_1": {
    26  			StateVersion: 0,
    27  			ID:           "some_id",
    28  			Attributes: map[string]string{
    29  				"name": "www.notdomain.com.",
    30  			},
    31  			Expected: "www.notdomain.com",
    32  		},
    33  		"v0_2": {
    34  			StateVersion: 0,
    35  			ID:           "some_id",
    36  			Attributes: map[string]string{
    37  				"name": "www.notdomain.com",
    38  			},
    39  			Expected: "www.notdomain.com",
    40  		},
    41  	}
    42  
    43  	for tn, tc := range cases {
    44  		is := &terraform.InstanceState{
    45  			ID:         tc.ID,
    46  			Attributes: tc.Attributes,
    47  		}
    48  		is, err := resourceAwsRoute53RecordMigrateState(
    49  			tc.StateVersion, is, tc.Meta)
    50  
    51  		if err != nil {
    52  			t.Fatalf("bad: %s, err: %#v", tn, err)
    53  		}
    54  
    55  		if is.Attributes["name"] != tc.Expected {
    56  			t.Fatalf("bad Route 53 Migrate: %s\n\n expected: %s", is.Attributes["name"], tc.Expected)
    57  		}
    58  	}
    59  }
    60  
    61  func TestAWSRoute53RecordMigrateStateV1toV2(t *testing.T) {
    62  	cases := map[string]struct {
    63  		StateVersion int
    64  		Attributes   map[string]string
    65  		Expected     map[string]string
    66  		Meta         interface{}
    67  	}{
    68  		"v0_1": {
    69  			StateVersion: 1,
    70  			Attributes: map[string]string{
    71  				"weight":   "0",
    72  				"failover": "PRIMARY",
    73  			},
    74  			Expected: map[string]string{
    75  				"weighted_routing_policy.#":        "1",
    76  				"weighted_routing_policy.0.weight": "0",
    77  				"failover_routing_policy.#":        "1",
    78  				"failover_routing_policy.0.type":   "PRIMARY",
    79  			},
    80  		},
    81  		"v0_2": {
    82  			StateVersion: 0,
    83  			Attributes: map[string]string{
    84  				"weight": "-1",
    85  			},
    86  			Expected: map[string]string{},
    87  		},
    88  	}
    89  
    90  	for tn, tc := range cases {
    91  		is := &terraform.InstanceState{
    92  			ID:         "route53_record",
    93  			Attributes: tc.Attributes,
    94  		}
    95  		is, err := resourceAwsRoute53Record().MigrateState(
    96  			tc.StateVersion, is, tc.Meta)
    97  
    98  		if err != nil {
    99  			t.Fatalf("bad: %s, err: %#v", tn, err)
   100  		}
   101  
   102  		for k, v := range tc.Expected {
   103  			if is.Attributes[k] != v {
   104  				t.Fatalf(
   105  					"bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v",
   106  					tn, k, v, k, is.Attributes[k], is.Attributes)
   107  			}
   108  		}
   109  	}
   110  }