forked from hillu/go-yara
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcbpool_test.go
63 lines (59 loc) · 1.3 KB
/
cbpool_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
// Copyright © 2015-2020 Hilko Bengen <[email protected]>
// All rights reserved.
//
// Use of this source code is governed by the license that can be
// found in the LICENSE file.
package yara
import (
"testing"
)
func TestBasic(t *testing.T) {
pool := makecbPool(32)
p1 := pool.Put("asdf")
p2 := pool.Put("ghjk")
s1, ok := pool.Get(p1).(string)
if !ok || s1 != "asdf" {
t.Errorf("s1: expected 'asdf', got '%v'", s1)
}
pool.Delete(p1)
i := func() interface{} {
defer func() {
if x := recover(); x != nil {
t.Logf("Get: Got expected panic: %v", x)
}
}()
x := pool.Get(p1)
t.Error("Get: No panic was triggered.")
return x
}()
if s1, ok := i.(string); ok || s1 == "asdf" {
t.Errorf("s1: expected nil, got '%v'", s1)
}
s2, ok := pool.Get(p2).(string)
if !ok || s2 != "ghjk" {
t.Errorf("s1: expected 'hjkl', got '%v'", s1)
}
pool.Delete(p2)
func() {
defer func() {
if x := recover(); x != nil {
t.Logf("Delete: Got expected panic: %v", x)
}
}()
pool.Delete(p2)
t.Error("Delete: No panic was triggered.")
}()
// Fill pool
for i := 0; i < 32; i++ {
pool.Put(i)
}
func() {
defer func() {
if x := recover(); x != nil {
t.Logf("full pool: Got expected panic: %v", x)
}
}()
pool.Put(100)
t.Error("full pool: No panic was triggered.")
}()
}