-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_test.go
52 lines (45 loc) · 1.08 KB
/
cache_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cache
import (
"testing"
)
func TestSet(t *testing.T) {
cache := New()
cache.Set("lemon.com", "172.28.5.64")
_, exists := cache.Get("lemon.com")
if !exists {
t.Errorf("TestSet: no entry for %v in cache", "lemon.com")
}
}
func TestGet(t *testing.T) {
cache := New()
cache.Set("lemon.com", "172.28.5.64")
ip, exists := cache.Get("lemon.com")
if !exists {
t.Errorf("TestGet: no entry for %v in cache", "lemon.com")
}
if ip!="172.28.5.64" {
t.Errorf("TestGet: cache entry does not match")
}
//test when key does not exist
_, exists = cache.Get("ginger.com")
if exists {
t.Errorf("TestGet: Unexpected entry for %v in cache", "lemon.com")
}
}
func TestRemove(t *testing.T) {
cache := New()
cache.Set("lemon.com", "172.28.5.64")
err := cache.Remove("lemon.com")
if err != nil{
t.Error(err)
}
_, exists := cache.Get("ginger.com")
if exists {
t.Errorf("TestRemove: Unexpected entry for %v in cache", "lemon.com")
}
//test to check nothing bad happens when try to remove key that doesn't exist
err = cache.Remove("IDon'tExist")
if err != nil{
t.Error(err)
}
}