0
0
Fork 0

add some tests for index names in results

This commit is contained in:
Marty Schoch 2015-12-08 14:38:46 -05:00
parent d73beac3b9
commit 84ec206fec
2 changed files with 15 additions and 2 deletions

View File

@ -573,6 +573,7 @@ func TestMultiSearchNoError(t *testing.T) {
Total: 1,
Hits: search.DocumentMatchCollection{
&search.DocumentMatch{
Index: "1",
ID: "a",
Score: 1.0,
},
@ -583,6 +584,7 @@ func TestMultiSearchNoError(t *testing.T) {
Total: 1,
Hits: search.DocumentMatchCollection{
&search.DocumentMatch{
Index: "2",
ID: "b",
Score: 2.0,
},
@ -596,10 +598,12 @@ func TestMultiSearchNoError(t *testing.T) {
Total: 2,
Hits: search.DocumentMatchCollection{
&search.DocumentMatch{
Index: "2",
ID: "b",
Score: 2.0,
},
&search.DocumentMatch{
Index: "1",
ID: "a",
Score: 1.0,
},

View File

@ -60,12 +60,12 @@ func TestIntegration(t *testing.T) {
}
if fi.IsDir() {
t.Logf("Running test: %s", fi.Name())
runTestDir(t, "tests"+string(filepath.Separator)+fi.Name())
runTestDir(t, "tests"+string(filepath.Separator)+fi.Name(), fi.Name())
}
}
}
func runTestDir(t *testing.T, dir string) {
func runTestDir(t *testing.T, dir, datasetName string) {
// read the mapping
mappingBytes, err := ioutil.ReadFile(dir + string(filepath.Separator) + "mapping.json")
if err != nil {
@ -93,6 +93,8 @@ func runTestDir(t *testing.T, dir string) {
t.Errorf("error creating new index: %v", err)
return
}
// set a custom index name
index.SetName(datasetName)
defer func() {
err := index.Close()
if err != nil {
@ -182,5 +184,12 @@ func runTestDir(t *testing.T, dir string) {
t.Errorf("test %d - expected facets: %#v got %#v", testNum, search.Result.Facets, res.Facets)
}
}
// check that custom index name is in results
for _, hit := range res.Hits {
if hit.Index != datasetName {
t.Fatalf("expected name: %s, got: %s", datasetName, hit.Index)
}
}
}
}