(t *testing.T, memcache *cache.Memcached)
| 26 | } |
| 27 | |
| 28 | func testMemcache(t *testing.T, memcache *cache.Memcached) { |
| 29 | numKeys := 1000 |
| 30 | |
| 31 | ctx := context.Background() |
| 32 | keysIncMissing := make([]string, 0, numKeys) |
| 33 | keys := make([]string, 0, numKeys) |
| 34 | bufs := make([][]byte, 0, numKeys) |
| 35 | |
| 36 | // Insert 1000 keys skipping all multiples of 5. |
| 37 | for i := 0; i < numKeys; i++ { |
| 38 | keysIncMissing = append(keysIncMissing, fmt.Sprint(i)) |
| 39 | if i%5 == 0 { |
| 40 | continue |
| 41 | } |
| 42 | |
| 43 | keys = append(keys, fmt.Sprint(i)) |
| 44 | bufs = append(bufs, []byte(fmt.Sprint(i))) |
| 45 | } |
| 46 | memcache.Store(ctx, keys, bufs) |
| 47 | |
| 48 | found, bufs, missing := memcache.Fetch(ctx, keysIncMissing) |
| 49 | for i := 0; i < numKeys; i++ { |
| 50 | if i%5 == 0 { |
| 51 | require.Equal(t, fmt.Sprint(i), missing[0]) |
| 52 | missing = missing[1:] |
| 53 | continue |
| 54 | } |
| 55 | |
| 56 | require.Equal(t, fmt.Sprint(i), found[0]) |
| 57 | require.Equal(t, fmt.Sprint(i), string(bufs[0])) |
| 58 | found = found[1:] |
| 59 | bufs = bufs[1:] |
| 60 | } |
| 61 | |
| 62 | _, foundKey := memcache.FetchKey(ctx, "1") |
| 63 | assert.True(t, foundKey) |
| 64 | |
| 65 | _, foundKey = memcache.FetchKey(ctx, "5") |
| 66 | assert.False(t, foundKey) |
| 67 | } |
| 68 | |
| 69 | // mockMemcache whose calls fail 1/3rd of the time. |
| 70 | type mockMemcacheFailing struct { |
no test coverage detected