Test public interface
(t *testing.T, indexer Indexer)
| 88 | |
| 89 | // Test public interface |
| 90 | func doTestIndex(t *testing.T, indexer Indexer) { |
| 91 | mkObj := func(id string, val string) testStoreObject { |
| 92 | return testStoreObject{id: id, val: val} |
| 93 | } |
| 94 | |
| 95 | // Test Index |
| 96 | expected := map[string]sets.String{} |
| 97 | expected["b"] = sets.NewString("a", "c") |
| 98 | expected["f"] = sets.NewString("e") |
| 99 | expected["h"] = sets.NewString("g") |
| 100 | indexer.Add(mkObj("a", "b")) |
| 101 | indexer.Add(mkObj("c", "b")) |
| 102 | indexer.Add(mkObj("e", "f")) |
| 103 | indexer.Add(mkObj("g", "h")) |
| 104 | { |
| 105 | for k, v := range expected { |
| 106 | found := sets.String{} |
| 107 | indexResults, err := indexer.Index("by_val", mkObj("", k)) |
| 108 | if err != nil { |
| 109 | t.Errorf("Unexpected error %v", err) |
| 110 | } |
| 111 | for _, item := range indexResults { |
| 112 | found.Insert(item.(testStoreObject).id) |
| 113 | } |
| 114 | items := v.List() |
| 115 | if !found.HasAll(items...) { |
| 116 | t.Errorf("missing items, index %s, expected %v but found %v", k, items, found.List()) |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | func testStoreKeyFunc(obj interface{}) (string, error) { |
| 123 | return obj.(testStoreObject).id, nil |