github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/resource_aws_codebuild_project_migrate_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  func TestAWSCodebuildMigrateState(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  				"description": "some description",
    22  				"timeout":     "5",
    23  			},
    24  			Expected: "5",
    25  		},
    26  		"v0_2": {
    27  			StateVersion: 0,
    28  			ID:           "tf-testing-file",
    29  			Attributes: map[string]string{
    30  				"description":   "some description",
    31  				"build_timeout": "5",
    32  			},
    33  			Expected: "5",
    34  		},
    35  	}
    36  
    37  	for tn, tc := range cases {
    38  		is := &terraform.InstanceState{
    39  			ID:         tc.ID,
    40  			Attributes: tc.Attributes,
    41  		}
    42  		is, err := resourceAwsCodebuildMigrateState(
    43  			tc.StateVersion, is, tc.Meta)
    44  
    45  		if err != nil {
    46  			t.Fatalf("bad: %s, err: %#v", tn, err)
    47  		}
    48  
    49  		if is.Attributes["build_timeout"] != tc.Expected {
    50  			t.Fatalf("Bad build_timeout migration: %s\n\n expected: %s", is.Attributes["build_timeout"], tc.Expected)
    51  		}
    52  	}
    53  }