55 "testing"
66 "time"
77
8- "github.com/stretchr/testify/require "
8+ "fortio.org/assert "
99)
1010
1111const noEvictionTTL = 0
@@ -15,28 +15,28 @@ func TestSetAndGet(t *testing.T) {
1515 cache .Set ("hello" , "world" )
1616
1717 value , ok := cache .Get ("hello" )
18- require .True (t , ok )
19- require .Equal (t , "world" , value )
18+ assert .True (t , ok )
19+ assert .Equal (t , "world" , value )
2020}
2121
2222func TestRemove (t * testing.T ) {
2323 cache := New [int , int ](10 , noEvictionTTL )
2424 cache .Set (1 , 10 )
2525
2626 val , ok := cache .Get (1 )
27- require .True (t , ok )
28- require .Equal (t , 10 , val )
27+ assert .True (t , ok )
28+ assert .Equal (t , 10 , val )
2929
3030 // After removing the key, it should not be found
3131 removed := cache .Remove (1 )
32- require .True (t , removed )
32+ assert .True (t , removed )
3333
3434 _ , ok = cache .Get (1 )
35- require .False (t , ok )
35+ assert .False (t , ok )
3636
3737 // This should not panic
3838 removed = cache .Remove (- 1 )
39- require .False (t , removed )
39+ assert .False (t , removed )
4040}
4141
4242func TestEvictOneHitWonders (t * testing.T ) {
@@ -55,14 +55,14 @@ func TestEvictOneHitWonders(t *testing.T) {
5555 // hit one-hit wonders only once
5656 for _ , v := range oneHitWonders {
5757 _ , ok := cache .Get (v )
58- require .True (t , ok )
58+ assert .True (t , ok )
5959 }
6060
6161 // hit the popular objects
6262 for i := 0 ; i < 3 ; i ++ {
6363 for _ , v := range popularObjects {
6464 _ , ok := cache .Get (v )
65- require .True (t , ok )
65+ assert .True (t , ok )
6666 }
6767 }
6868
@@ -74,13 +74,13 @@ func TestEvictOneHitWonders(t *testing.T) {
7474
7575 for _ , v := range oneHitWonders {
7676 _ , ok := cache .Get (v )
77- require .False (t , ok )
77+ assert .False (t , ok )
7878 }
7979
8080 // popular objects should still be in the cache
8181 for _ , v := range popularObjects {
8282 _ , ok := cache .Get (v )
83- require .True (t , ok )
83+ assert .True (t , ok )
8484 }
8585}
8686
@@ -97,8 +97,8 @@ func TestPeek(t *testing.T) {
9797 for i := 0 ; i < 10 ; i ++ {
9898 for _ , v := range entries {
9999 value , exist := cache .Peek (v )
100- require .True (t , exist )
101- require .Equal (t , v * 10 , value )
100+ assert .True (t , exist )
101+ assert .Equal (t , v * 10 , value )
102102 }
103103 }
104104
@@ -112,7 +112,7 @@ func TestPeek(t *testing.T) {
112112 // they should not exist in the cache
113113 for _ , v := range entries {
114114 _ , exist := cache .Peek (v )
115- require .False (t , exist )
115+ assert .False (t , exist )
116116 }
117117}
118118
@@ -126,27 +126,27 @@ func TestContains(t *testing.T) {
126126
127127 // check if each entry exists in the cache
128128 for _ , v := range entries {
129- require .True (t , cache .Contains (v ))
129+ assert .True (t , cache .Contains (v ))
130130 }
131131
132132 for i := 6 ; i <= 10 ; i ++ {
133- require .False (t , cache .Contains (i ))
133+ assert .False (t , cache .Contains (i ))
134134 }
135135}
136136
137137func TestLength (t * testing.T ) {
138138 cache := New [string , string ](10 , noEvictionTTL )
139139
140140 cache .Set ("hello" , "world" )
141- require .Equal (t , 1 , cache .Len ())
141+ assert .Equal (t , 1 , cache .Len ())
142142
143143 cache .Set ("hello2" , "world" )
144144 cache .Set ("hello" , "changed" )
145- require .Equal (t , 2 , cache .Len ())
145+ assert .Equal (t , 2 , cache .Len ())
146146
147147 value , ok := cache .Get ("hello" )
148- require .True (t , ok )
149- require .Equal (t , "changed" , value )
148+ assert .True (t , ok )
149+ assert .Equal (t , "changed" , value )
150150}
151151
152152func TestClean (t * testing.T ) {
@@ -156,15 +156,15 @@ func TestClean(t *testing.T) {
156156 for _ , v := range entries {
157157 cache .Set (v , v * 10 )
158158 }
159- require .Equal (t , 5 , cache .Len ())
159+ assert .Equal (t , 5 , cache .Len ())
160160 cache .Purge ()
161161
162162 // check if each entry exists in the cache
163163 for _ , v := range entries {
164164 _ , exist := cache .Peek (v )
165- require .False (t , exist )
165+ assert .False (t , exist )
166166 }
167- require .Equal (t , 0 , cache .Len ())
167+ assert .Equal (t , 0 , cache .Len ())
168168}
169169
170170func TestTimeToLive (t * testing.T ) {
@@ -175,16 +175,16 @@ func TestTimeToLive(t *testing.T) {
175175 for num := 1 ; num <= numberOfEntries ; num ++ {
176176 cache .Set (num , num )
177177 val , ok := cache .Get (num )
178- require .True (t , ok )
179- require .Equal (t , num , val )
178+ assert .True (t , ok )
179+ assert .Equal (t , num , val )
180180 }
181181
182182 time .Sleep (ttl * 2 )
183183
184184 // check all entries are evicted
185185 for num := 1 ; num <= numberOfEntries ; num ++ {
186186 _ , ok := cache .Get (num )
187- require .False (t , ok )
187+ assert .False (t , ok )
188188 }
189189}
190190
@@ -206,8 +206,8 @@ func TestEvictionCallback(t *testing.T) {
206206
207207 // check the first object is evicted
208208 _ , ok := cache .Get (1 )
209- require .False (t , ok )
210- require .Equal (t , 1 , evicted [1 ])
209+ assert .False (t , ok )
210+ assert .Equal (t , 1 , evicted [1 ])
211211
212212 cache .Close ()
213213}
@@ -237,7 +237,7 @@ func TestEvictionCallbackWithTTL(t *testing.T) {
237237 mu .Lock ()
238238 if len (evicted ) == 10 {
239239 for i := 1 ; i <= 10 ; i ++ {
240- require .Equal (t , i , evicted [i ])
240+ assert .Equal (t , i , evicted [i ])
241241 }
242242 return
243243 }
0 commit comments