-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes_test.go
More file actions
54 lines (40 loc) · 1.33 KB
/
types_test.go
File metadata and controls
54 lines (40 loc) · 1.33 KB
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
package dlog
import (
"fmt"
"strings"
"testing"
"reflect"
"github.com/stretchr/testify/assert"
)
func TestFullMsgTypeName(t *testing.T) {
assert := assert.New(t)
type LocalType struct {
Name string
}
s, e := fullMsgTypeName(LocalType{})
assert.Nil(e)
assert.Equal("github.com-topicai-dlog.localtype", s)
// Registering pointer to struct is like registering struct.
s, e = fullMsgTypeName(&LocalType{})
assert.Nil(e)
assert.Equal("github.com-topicai-dlog.localtype", s)
// Registering unnamed struct.
s, e = fullMsgTypeName(struct{ Name string }{Name: "a name"})
assert.NotNil(e)
assert.True(strings.Contains(fmt.Sprint(e), "Cannot identity type name of dlog message"))
}
func TestRegisterType(t *testing.T) {
assert := assert.New(t)
type SomeType struct{}
type AnotherType struct{}
type anotherType struct{}
RegisterType(SomeType{})
assert.Equal(reflect.TypeOf(SomeType{}),
msgTypes["github.com-topicai-dlog.sometype"])
// Register of *struct as reasonable duplication with struct.
assert.NotPanics(func() { RegisterType(&SomeType{}) })
RegisterType(&AnotherType{}) // Registering pointer to struct is like registering struct.
assert.Equal(reflect.TypeOf(AnotherType{}),
msgTypes["github.com-topicai-dlog.anothertype"])
assert.Panics(func() { RegisterType(anotherType{}) }) // msgTypes keys are lower-case strings.
}