github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/google/resource_google_project_migrate_test.go (about) 1 package google 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 func TestGoogleProjectMigrateState(t *testing.T) { 10 cases := map[string]struct { 11 StateVersion int 12 Attributes map[string]string 13 Expected map[string]string 14 Meta interface{} 15 }{ 16 "deprecate policy_data and support creation/deletion": { 17 StateVersion: 0, 18 Attributes: map[string]string{}, 19 Expected: map[string]string{ 20 "project_id": "test-project", 21 "skip_delete": "true", 22 }, 23 Meta: &Config{}, 24 }, 25 } 26 27 for tn, tc := range cases { 28 is := &terraform.InstanceState{ 29 ID: "test-project", 30 Attributes: tc.Attributes, 31 } 32 is, err := resourceGoogleProjectMigrateState( 33 tc.StateVersion, is, tc.Meta) 34 35 if err != nil { 36 t.Fatalf("bad: %s, err: %#v", tn, err) 37 } 38 39 for k, v := range tc.Expected { 40 if is.Attributes[k] != v { 41 t.Fatalf( 42 "bad: %s\n\n expected: %#v -> %#v\n got: %#v -> %#v\n in: %#v", 43 tn, k, v, k, is.Attributes[k], is.Attributes) 44 } 45 } 46 } 47 } 48 49 func TestGoogleProjectMigrateState_empty(t *testing.T) { 50 var is *terraform.InstanceState 51 var meta *Config 52 53 // should handle nil 54 is, err := resourceGoogleProjectMigrateState(0, is, meta) 55 56 if err != nil { 57 t.Fatalf("err: %#v", err) 58 } 59 if is != nil { 60 t.Fatalf("expected nil instancestate, got: %#v", is) 61 } 62 63 // should handle non-nil but empty 64 is = &terraform.InstanceState{} 65 is, err = resourceGoogleProjectMigrateState(0, is, meta) 66 67 if err != nil { 68 t.Fatalf("err: %#v", err) 69 } 70 }