github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/jsonconfig/config_test.go (about) 1 package jsonconfig 2 3 import ( 4 "testing" 5 ) 6 7 func TestFindSourceProviderConfig(t *testing.T) { 8 tests := []struct { 9 StartKey string 10 FullName string 11 ProviderMap map[string]providerConfig 12 Want string 13 }{ 14 { 15 StartKey: "null", 16 FullName: "hashicorp/null", 17 ProviderMap: map[string]providerConfig{}, 18 Want: "", 19 }, 20 { 21 StartKey: "null", 22 FullName: "hashicorp/null", 23 ProviderMap: map[string]providerConfig{ 24 "null": { 25 Name: "null", 26 FullName: "hashicorp/null", 27 ModuleAddress: "", 28 }, 29 }, 30 Want: "null", 31 }, 32 { 33 StartKey: "null2", 34 FullName: "hashicorp/null", 35 ProviderMap: map[string]providerConfig{ 36 "null": { 37 Name: "null", 38 FullName: "hashicorp/null", 39 ModuleAddress: "", 40 }, 41 }, 42 Want: "", 43 }, 44 { 45 StartKey: "null", 46 FullName: "hashicorp2/null", 47 ProviderMap: map[string]providerConfig{ 48 "null": { 49 Name: "null", 50 FullName: "hashicorp/null", 51 ModuleAddress: "", 52 }, 53 }, 54 Want: "", 55 }, 56 { 57 StartKey: "module.a:null", 58 FullName: "hashicorp/null", 59 ProviderMap: map[string]providerConfig{ 60 "null": { 61 Name: "null", 62 FullName: "hashicorp/null", 63 ModuleAddress: "", 64 }, 65 "module.a:null": { 66 Name: "module.a:null", 67 FullName: "hashicorp/null", 68 ModuleAddress: "module.a", 69 parentKey: "null", 70 }, 71 }, 72 Want: "null", 73 }, 74 { 75 StartKey: "module.a:null", 76 FullName: "hashicorp2/null", 77 ProviderMap: map[string]providerConfig{ 78 "null": { 79 Name: "null", 80 FullName: "hashicorp/null", 81 ModuleAddress: "", 82 }, 83 "module.a:null": { 84 Name: "module.a:null", 85 FullName: "hashicorp2/null", 86 ModuleAddress: "module.a", 87 parentKey: "null", 88 }, 89 }, 90 Want: "module.a:null", 91 }, 92 } 93 94 for _, test := range tests { 95 got := findSourceProviderKey(test.StartKey, test.FullName, test.ProviderMap) 96 if got != test.Want { 97 t.Errorf("wrong result:\nGot: %#v\nWant: %#v\n", got, test.Want) 98 } 99 } 100 }