Test public interface
(t *testing.T, store Store)
| 24 | |
| 25 | // Test public interface |
| 26 | func 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 { |