func readData(f *source.File) (interface{}, error) { switch f.Extension() { case "yaml", "yml": return parser.HandleYamlMetaData(f.Bytes()) case "json": return parser.HandleJsonMetaData(f.Bytes()) case "toml": return parser.HandleTomlMetaData(f.Bytes()) default: return nil, fmt.Errorf("Data not supported for extension '%s'", f.Extension()) } }
func TestDataDirJson(t *testing.T) { sources := []source.ByteSource{ {filepath.FromSlash("test/foo.json"), []byte(`{ "bar": "foofoo" }`)}, {filepath.FromSlash("test.json"), []byte(`{ "hello": [ { "world": "foo" } ] }`)}, } expected, err := parser.HandleJsonMetaData([]byte(`{ "test": { "hello": [{ "world": "foo" }] , "foo": { "bar":"foofoo" } } }`)) if err != nil { t.Fatalf("Error %s", err) } doTestDataDir(t, expected, []source.Input{&source.InMemorySource{ByteSource: sources}}) }