github.com/whiteboxio/flow@v0.0.3-0.20190918184116-508d75d68a2c/pkg/cfg/default_provider_test.go (about) 1 package cfg 2 3 import ( 4 "reflect" 5 "sort" 6 "strings" 7 "testing" 8 9 "github.com/awesome-flow/flow/pkg/types" 10 ) 11 12 func TestDefaultProviderSetUp(t *testing.T) { 13 tests := []struct { 14 name string 15 registry map[string]types.Value 16 wantRegs []string 17 }{ 18 { 19 "empty map", 20 map[string]types.Value{}, 21 []string{}, 22 }, 23 { 24 "defaults", 25 defaults, 26 []string{ 27 "config.path", 28 "plugin.path", 29 "system.maxprocs", 30 }, 31 }, 32 { 33 "Custom registry", 34 map[string]types.Value{ 35 "foo.bar.baz": 42, 36 }, 37 []string{"foo.bar.baz"}, 38 }, 39 } 40 41 t.Parallel() 42 43 for _, testCase := range tests { 44 t.Run(testCase.name, func(t *testing.T) { 45 repo := NewRepository() 46 prov, err := NewDefaultProviderWithRegistry(repo, 0, testCase.registry) 47 if err != nil { 48 t.Fatalf("failed to initialize a new default provider: %s", err) 49 } 50 if err := prov.SetUp(repo); err != nil { 51 t.Fatalf("failed to set up default provider: %s", err) 52 } 53 54 gotRegs := flattenRepo(repo) 55 for _, k := range testCase.wantRegs { 56 provs, ok := gotRegs[k] 57 if !ok { 58 t.Fatalf("failed to find a registration for key %q", k) 59 } 60 if !reflect.DeepEqual(provs, []Provider{prov}) { 61 t.Fatalf("unexpected provider list for key %q: %#v, want: %#v", k, provs, []Provider{prov}) 62 } 63 delete(gotRegs, k) 64 } 65 if len(gotRegs) > 0 { 66 extraKeys := make([]string, 0, len(gotRegs)) 67 for k := range gotRegs { 68 extraKeys = append(extraKeys, k) 69 } 70 sort.Strings(extraKeys) 71 t.Fatalf("unexpected registration keys: %s", strings.Join(extraKeys, ", ")) 72 } 73 }) 74 } 75 }