-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinterface_test.go
More file actions
50 lines (36 loc) · 905 Bytes
/
interface_test.go
File metadata and controls
50 lines (36 loc) · 905 Bytes
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
package protobuf
import (
"testing"
"github.com/stretchr/testify/require"
)
type testInterface interface {
String() string
}
type testStructA struct{}
func (a *testStructA) String() string {
return "A"
}
func (a *testStructA) MarshalID() [8]byte {
return [8]byte{'a'}
}
func (a *testStructA) MarshalBinary() ([]byte, error) {
return nil, nil
}
type testStructB struct{}
func (b *testStructB) String() string {
return "B"
}
func (b *testStructB) MarshalID() [8]byte {
return [8]byte{'b'}
}
func (b *testStructB) MarshalBinary() ([]byte, error) {
return nil, nil
}
func TestInterfaceRegistry(t *testing.T) {
r := newInterfaceRegistry()
r.register(func() interface{} { return &testStructA{} })
r.register(func() interface{} { return &testStructB{} })
require.NotNil(t, r.get(GeneratorID{'a'}))
require.NotNil(t, r.get(GeneratorID{'b'}))
require.Nil(t, r.get(GeneratorID{'c'}))
}