-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_test.go
More file actions
executable file
·65 lines (56 loc) · 1.24 KB
/
dump_test.go
File metadata and controls
executable file
·65 lines (56 loc) · 1.24 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
// Package utils
// @author Daud Valentino
package utils
import (
"strings"
"testing"
)
func TestDumpToString(t *testing.T) {
t.Parallel()
if result := DumpToString("test"); result == "test" {
t.Logf("expected: %v, got: %v", "test", result)
} else {
t.Fatalf("expected: %v, got: %v", "test", result)
}
if result := DumpToString(1); strings.Trim(result, "\n") == "1" {
t.Logf("expected: %v, got: %s", "1", result)
} else {
t.Fatalf("expected: %v, got: %v", "1", result)
}
}
func TestDebugPrint(t *testing.T) {
DebugPrint("test print")
}
func TestToJSONByte(t *testing.T) {
testCase := []struct{
Input interface{}
Expected []byte
}{
{
Input: struct {
ID uint64 `json:"id"`
Name string `json:"name"`
}{
ID: 1,
Name: "testcase1",
},
Expected: []byte{123,34,105,100,34,58,49,44,34,110,97,109,101,34,58,34,116,101,115,116,99,97,115,101,49,34,125,10},
},
{
Input: "test",
Expected: []byte{116,101,115,116},
},
{
Input: []byte{116,101,115,116},
Expected: []byte{116,101,115,116},
},
}
for _, v := range testCase{
r := ToJSONByte(v.Input)
if string(v.Expected)== string(r){
t.Logf("expected %v, got %v", v.Expected, r)
} else {
t.Errorf("expected %v, got %v", v.Expected, r)
}
}
}