-
Notifications
You must be signed in to change notification settings - Fork 6
/
actor_test.go
74 lines (57 loc) · 1.37 KB
/
actor_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
package grid
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewMakeRegistry(t *testing.T) {
t.Parallel()
m := newMakeActorRegistry()
require.NotZero(t, m)
assert.NotZero(t, m.r)
}
func TestMakeRegistryGetSet(t *testing.T) {
t.Parallel()
const n1 = "n1"
const n2 = "n2"
// we're using the errors here to distinguish between them
e1 := errors.New("e1")
e2 := errors.New("e2")
e3 := errors.New("e3")
var m1 MakeActor = func([]byte) (Actor, error) { return nil, e1 }
var m2 MakeActor = func([]byte) (Actor, error) { return nil, e2 }
var m3 MakeActor = func([]byte) (Actor, error) { return nil, e3 }
equal := func(t testing.TB, want error, got MakeActor) {
t.Helper()
_, err := got(nil)
assert.ErrorIs(t, err, want)
}
r := newMakeActorRegistry()
// Set one
_, ok := r.Get(n1)
assert.False(t, ok)
update := r.Set(n1, m1)
assert.False(t, update)
got1, ok := r.Get(n1)
assert.True(t, ok)
equal(t, e1, got1)
// Set second
update = r.Set(n2, m2)
assert.False(t, update)
got1, ok = r.Get(n1)
assert.True(t, ok)
equal(t, e1, got1)
got2, ok := r.Get(n2)
assert.True(t, ok)
equal(t, e2, got2)
// Overwrite first
update = r.Set(n1, m3)
assert.True(t, update)
got1, ok = r.Get(n1)
assert.True(t, ok)
equal(t, e3, got1)
got2, ok = r.Get(n2)
assert.True(t, ok)
equal(t, e2, got2)
}