-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils_test.go
More file actions
72 lines (59 loc) · 1.42 KB
/
utils_test.go
File metadata and controls
72 lines (59 loc) · 1.42 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package bitxid
import (
"testing"
"github.com/meshplus/bitxhub-kit/log"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
const (
loggerAccountDID = "account-did"
loggerChainDID = "chain-did"
)
var w *loggerWrapper
type loggerWrapper struct {
loggers map[string]*logrus.Entry
}
// Init initializes all loggers
func loggerInit() {
// config *repo.Config
m := make(map[string]*logrus.Entry)
m[loggerAccountDID] = log.NewWithModule(loggerAccountDID)
m[loggerAccountDID].Logger.SetLevel(log.ParseLevel("info"))
m[loggerChainDID] = log.NewWithModule(loggerChainDID)
m[loggerChainDID].Logger.SetLevel(log.ParseLevel("info"))
w = &loggerWrapper{loggers: m}
}
// Get gets logger for specific module
func loggerGet(name string) logrus.FieldLogger {
return w.loggers[name]
}
type s struct {
A string
B int
}
var testBytes []byte
func TestMarshal(t *testing.T) {
testStruct := s{
A: "aaa",
B: 1,
}
expectedByte := []byte{27, 255, 161, 3, 1, 1, 1, 115,
1, 255, 162, 0, 1, 2, 1, 1,
65, 1, 12, 0, 1, 1, 66, 1,
4, 0, 0, 0, 10, 255, 162, 1,
3, 97, 97, 97, 1, 2, 0}
testBytes1, err := Marshal(testStruct)
assert.Nil(t, err)
assert.Equal(t, expectedByte, testBytes1)
testBytes = testBytes1
}
func TestUnmarshal(t *testing.T) {
expectedStruct := s{
A: "aaa",
B: 1,
}
var testStruct s
err := Unmarshal(testBytes, &testStruct)
assert.Nil(t, err)
assert.Equal(t, expectedStruct, testStruct)
}