MCPcopy
hub / github.com/kubernetes/client-go / doTestIndex

Function doTestIndex

tools/cache/store_test.go:90–120  ·  view source on GitHub ↗

Test public interface

(t *testing.T, indexer Indexer)

Source from the content-addressed store, hash-verified

88
89// Test public interface
90func 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
122func testStoreKeyFunc(obj interface{}) (string, error) {
123 return obj.(testStoreObject).id, nil

Callers 1

TestIndexFunction · 0.85

Calls 4

AddMethod · 0.65
IndexMethod · 0.65
ErrorfMethod · 0.65
ListMethod · 0.65

Tested by

no test coverage detected