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

     1  package aws
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  func TestAWSKeyPairMigrateState(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_1": {
    18  			StateVersion: 0,
    19  			ID:           "tf-testing-file",
    20  			Attributes: map[string]string{
    21  				"fingerprint": "1d:cd:46:31:a9:4a:e0:06:8a:a1:22:cb:3b:bf:8e:42",
    22  				"key_name":    "tf-testing-file",
    23  				"public_key":  "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LBtwcFsQAYWw1cnOwRTZCJCzPSzq0dl3== ctshryock",
    24  			},
    25  			Expected: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LBtwcFsQAYWw1cnOwRTZCJCzPSzq0dl3== ctshryock",
    26  		},
    27  		"v0_2": {
    28  			StateVersion: 0,
    29  			ID:           "tf-testing-file",
    30  			Attributes: map[string]string{
    31  				"fingerprint": "1d:cd:46:31:a9:4a:e0:06:8a:a1:22:cb:3b:bf:8e:42",
    32  				"key_name":    "tf-testing-file",
    33  				"public_key":  "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LBtwcFsQAYWw1cnOwRTZCJCzPSzq0dl3== ctshryock\n",
    34  			},
    35  			Expected: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LBtwcFsQAYWw1cnOwRTZCJCzPSzq0dl3== ctshryock",
    36  		},
    37  	}
    38  
    39  	for tn, tc := range cases {
    40  		is := &terraform.InstanceState{
    41  			ID:         tc.ID,
    42  			Attributes: tc.Attributes,
    43  		}
    44  		is, err := resourceAwsKeyPairMigrateState(
    45  			tc.StateVersion, is, tc.Meta)
    46  
    47  		if err != nil {
    48  			t.Fatalf("bad: %s, err: %#v", tn, err)
    49  		}
    50  
    51  		if is.Attributes["public_key"] != tc.Expected {
    52  			t.Fatalf("Bad public_key migration: %s\n\n expected: %s", is.Attributes["public_key"], tc.Expected)
    53  		}
    54  	}
    55  }