Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: go/util/testing.go

Issue 1401563003: Enable clear/purge for failed digests (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Added unit test to FileDiffStore Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/util/caching_test.go ('k') | golden/go/diff/diff.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package util
2
3 import (
4 "fmt"
5 "strconv"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 )
10
11 type myTestType struct {
12 A int
13 B string
14 }
15
16 func UnitTestCodec() LRUCodec {
17 return JSONCodec(&myTestType{})
18 }
19
20 func UnitTestLRUCache(t *testing.T, cache LRUCache) {
21 purge(t, cache)
22 N := 256
23 for i := 0; i < N; i++ {
24 cache.Add(strconv.Itoa(i), i)
25 }
26
27 // Make sure out keys are correct
28 assert.Equal(t, N, cache.Len())
29 cacheKeys := cache.Keys()
30 assert.Equal(t, N, len(cacheKeys))
31 for _, k := range cacheKeys {
32 assert.IsType(t, "", k)
33 v, ok := cache.Get(k)
34 assert.True(t, ok)
35 assert.IsType(t, 0, v)
36 assert.Equal(t, k, strconv.Itoa(v.(int)))
37 }
38
39 for i := 0; i < N; i++ {
40 found, ok := cache.Get(strconv.Itoa(i))
41 assert.True(t, ok)
42 assert.IsType(t, 0, found)
43 assert.Equal(t, found.(int), i)
44 }
45
46 for i := 0; i < N; i++ {
47 _, ok := cache.Get(strconv.Itoa(i))
48 assert.True(t, ok)
49 oldLen := cache.Len()
50 cache.Remove(strconv.Itoa(i))
51 assert.Equal(t, oldLen-1, cache.Len())
52 }
53 assert.Equal(t, 0, cache.Len())
54
55 // Add some TestStructs to make sure the codec works.
56 for i := 0; i < N; i++ {
57 strKey := "structkey-" + strconv.Itoa(i)
58
59 ts := &myTestType{
60 A: i,
61 B: fmt.Sprintf("Val %d", i),
62 }
63 cache.Add(strKey, ts)
64 assert.Equal(t, i+1, cache.Len())
65 foundTS, ok := cache.Get(strKey)
66 assert.True(t, ok)
67 assert.IsType(t, &myTestType{}, foundTS)
68 assert.Equal(t, ts, foundTS)
69 }
70 }
71
72 func purge(t *testing.T, cache LRUCache) {
73 for _, k := range cache.Keys() {
74 cache.Remove(k)
75 }
76 assert.Equal(t, 0, cache.Len())
77 }
OLDNEW
« no previous file with comments | « go/util/caching_test.go ('k') | golden/go/diff/diff.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698