github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/meta_backend_migrate_test.go (about) 1 package command 2 3 import ( 4 "testing" 5 ) 6 7 func TestBackendMigrate_promptMultiStatePattern(t *testing.T) { 8 // Setup the meta 9 10 cases := map[string]struct { 11 renamePrompt string 12 patternPrompt string 13 expectedErr string 14 }{ 15 "valid pattern": { 16 renamePrompt: "1", 17 patternPrompt: "hello-*", 18 expectedErr: "", 19 }, 20 "invalid pattern, only one asterisk allowed": { 21 renamePrompt: "1", 22 patternPrompt: "hello-*-world-*", 23 expectedErr: "The pattern '*' cannot be used more than once.", 24 }, 25 "invalid pattern, missing asterisk": { 26 renamePrompt: "1", 27 patternPrompt: "hello-world", 28 expectedErr: "The pattern must have an '*'", 29 }, 30 "invalid rename": { 31 renamePrompt: "3", 32 expectedErr: "Please select 1 or 2 as part of this option.", 33 }, 34 "no rename": { 35 renamePrompt: "2", 36 }, 37 } 38 for name, tc := range cases { 39 t.Log("Test: ", name) 40 m := testMetaBackend(t, nil) 41 input := map[string]string{} 42 cleanup := testInputMap(t, input) 43 if tc.renamePrompt != "" { 44 input["backend-migrate-multistate-to-tfc"] = tc.renamePrompt 45 } 46 if tc.patternPrompt != "" { 47 input["backend-migrate-multistate-to-tfc-pattern"] = tc.patternPrompt 48 } 49 50 sourceType := "cloud" 51 _, err := m.promptMultiStateMigrationPattern(sourceType) 52 if tc.expectedErr == "" && err != nil { 53 t.Fatalf("expected error to be nil, but was %s", err.Error()) 54 } 55 if tc.expectedErr != "" && tc.expectedErr != err.Error() { 56 t.Fatalf("expected error to eq %s but got %s", tc.expectedErr, err.Error()) 57 } 58 59 cleanup() 60 } 61 }