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

Function doTestStore

tools/cache/store_test.go:26–87  ·  view source on GitHub ↗

Test public interface

(t *testing.T, store Store)

Source from the content-addressed store, hash-verified

24
25// Test public interface
26func doTestStore(t *testing.T, store Store) {
27 mkObj := func(id string, val string) testStoreObject {
28 return testStoreObject{id: id, val: val}
29 }
30
31 store.Add(mkObj("foo", "bar"))
32 if item, ok, _ := store.Get(mkObj("foo", "")); !ok {
33 t.Errorf("didn't find inserted item")
34 } else {
35 if e, a := "bar", item.(testStoreObject).val; e != a {
36 t.Errorf("expected %v, got %v", e, a)
37 }
38 }
39 store.Update(mkObj("foo", "baz"))
40 if item, ok, _ := store.Get(mkObj("foo", "")); !ok {
41 t.Errorf("didn't find inserted item")
42 } else {
43 if e, a := "baz", item.(testStoreObject).val; e != a {
44 t.Errorf("expected %v, got %v", e, a)
45 }
46 }
47 store.Delete(mkObj("foo", ""))
48 if _, ok, _ := store.Get(mkObj("foo", "")); ok {
49 t.Errorf("found deleted item??")
50 }
51
52 // Test List.
53 store.Add(mkObj("a", "b"))
54 store.Add(mkObj("c", "d"))
55 store.Add(mkObj("e", "e"))
56 {
57 found := sets.String{}
58 for _, item := range store.List() {
59 found.Insert(item.(testStoreObject).val)
60 }
61 if !found.HasAll("b", "d", "e") {
62 t.Errorf("missing items, found: %v", found)
63 }
64 if len(found) != 3 {
65 t.Errorf("extra items")
66 }
67 }
68
69 // Test Replace.
70 store.Replace([]interface{}{
71 mkObj("foo", "foo"),
72 mkObj("bar", "bar"),
73 }, "0")
74
75 {
76 found := sets.String{}
77 for _, item := range store.List() {
78 found.Insert(item.(testStoreObject).val)
79 }
80 if !found.HasAll("foo", "bar") {
81 t.Errorf("missing items")
82 }
83 if len(found) != 2 {

Callers 3

TestCacheFunction · 0.85
TestFIFOCacheFunction · 0.85
TestUndeltaStoreFunction · 0.85

Calls 7

AddMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
UpdateMethod · 0.65
DeleteMethod · 0.65
ListMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected