-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgottlmap_test.go
70 lines (65 loc) · 1.62 KB
/
gottlmap_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
package gottlmap_test
import (
"context"
"testing"
"time"
"github.com/MFlowAU/gottlmap"
)
func TestNew(t *testing.T) {
type testScenario struct {
Description string
KeyValues []map[string]interface{}
Tickers *time.Ticker
Hook gottlmap.Hook
ctx context.Context
err error
}
tests := []testScenario{
{
Description: "New() should return a new TTLMap with out Errors",
KeyValues: []map[string]interface{}{
{"key1": "value1"},
{"key2": "value2"},
{"key3": "value3"},
},
Tickers: time.NewTicker(1 * time.Second),
Hook: nil,
ctx: context.Background(),
err: nil,
},
{
Description: "New() should return error ErrTickerNotSet",
KeyValues: []map[string]interface{}{},
Tickers: nil,
Hook: nil,
ctx: context.Background(),
err: gottlmap.ErrTickerNotSet,
},
{
Description: "New() should return error ErrCtxNotSet",
KeyValues: []map[string]interface{}{},
Tickers: time.NewTicker(1 * time.Second),
Hook: nil,
ctx: nil,
err: gottlmap.ErrCtxNotSet,
},
}
for _, test := range tests {
ttl_map, err := gottlmap.New(test.Tickers, test.Hook, test.ctx)
if err != test.err {
t.Errorf("%s: %s", test.Description, err)
t.Fail()
}
if ttl_map == nil {
continue
}
for _, keyValue := range test.KeyValues {
for key, value := range keyValue {
ttl_map.Set(key, value, 10*time.Second)
}
}
if len(ttl_map.Keys()) != len(test.KeyValues) {
t.Errorf("%s: Expected %d keys, got %d", test.Description, len(test.KeyValues), len(ttl_map.Keys()))
}
}
}