-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_test.go
90 lines (68 loc) · 1.36 KB
/
core_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"errors"
"testing"
)
func TestPut(t *testing.T) {
const key = "create-key"
const value = "create-value"
var val interface{}
var contains bool
defer delete(store, key) // Clean up after the test
// Sanity check
_, contains = store[key]
if contains {
t.Error("key/value already exists")
}
// err should be nil
err := Put(key, value)
if err != nil {
t.Error(err)
}
val, contains = store[key]
if !contains {
t.Error("create failed")
}
if val != value {
t.Error("val/value mismatch")
}
}
func TestGet(t *testing.T) {
const key = "read-key"
const value = "read-value"
var val interface{}
var err error
defer delete(store, key) // Clean up after the test
// Read a non-thing
val, err = Get(key)
if err == nil {
t.Error("expected an error")
}
if !errors.Is(err, ErrorNoSuchKey) {
t.Error("unexpected error:", err)
}
store[key] = value
val, err = Get(key)
if err != nil {
t.Error("unexpected error:", err)
}
if val != value {
t.Error("val/value mismatch")
}
}
func TestDelete(t *testing.T) {
const key = "delete-key"
const value = "delete-value"
var contains bool
defer delete(store, key) // Clean up after the test
store[key] = value
_, contains = store[key]
if !contains {
t.Error("key/value doesn't exist")
}
Delete(key)
_, contains = store[key]
if contains {
t.Error("Delete failed")
}
}