-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprettyp_test.go
93 lines (85 loc) · 2.95 KB
/
prettyp_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package util
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type SourceLang struct {
En string `json:"en" bson:"en"`
Bn string `json:"bn" bson:"bn"`
}
type UserInfo struct {
Username string `json:"username" bson:"username"`
Email string `json:"email" bson:"email"`
}
func TestPretty(t *testing.T) {
project := struct {
Id int64 `json:"project_id"`
Title string `json:"title"`
Name string `json:"name"`
Budget float64 `json:"budget"`
Active bool `json:"active"`
Tags []string `json:"tags"`
Milestones []int `json:"milestones"`
Metadata map[string]interface{} `json:"metadata"`
NestedStruct struct {
Description string `json:"description"`
Completed bool `json:"completed"`
} `json:"nested_struct"`
}{
Id: 123,
Title: "Test Project",
Name: "Test Name",
Budget: 1000000.50,
Active: true,
Tags: []string{"Go", "JSON", "PrettyPrint"},
Milestones: []int{1, 2, 3, 4},
Metadata: map[string]interface{}{
"created_by": "User123",
"priority": "High",
},
NestedStruct: struct {
Description string `json:"description"`
Completed bool `json:"completed"`
}{
Description: "Nested Struct Description",
Completed: false,
},
}
err := PrettyPrint(project)
assert.NoError(t, err, "PrettyPrint should not return an error")
}
func TestPrettyPrintWithLocation(t *testing.T) {
location := struct {
Id string `bson:"_id,omitempty" json:"id,omitempty"`
Title SourceLang `bson:"title" json:"title"`
Address SourceLang `bson:"address" json:"address"`
Description SourceLang `bson:"description" json:"description"`
MapLink string `bson:"map_link" json:"map_link"`
CreatedAt time.Time `json:"created_at,omitempty" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at,omitempty" bson:"updated_at"`
CreatedBy UserInfo `bson:"created_by" json:"created_by"`
UpdatedBy UserInfo `bson:"updated_by" json:"updated_by"`
}{
Id: "673dcdb47484940c3f9fd08c",
Title: SourceLang{
En: "Uttara, EC",
Bn: "উত্তরা,EC",
},
Address: SourceLang{
En: "8th Floor, Millennium Tower, House 2, Road 7, Sector 3, Uttara",
Bn: "৮ম ফ্লোর, মিলেনিয়াম টাওয়ার, হাউজ ২, রোড ৭, সেক্টর ৩, উত্তরা।",
},
Description: SourceLang{
En: "Uttara Center",
Bn: "উত্তরা কেন্দ্র",
},
MapLink: "https://www.google.com/maps/dir/",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CreatedBy: UserInfo{Username: "creator_user", Email: "[email protected]"},
UpdatedBy: UserInfo{Username: "updater_user", Email: "[email protected]"},
}
err := PrettyPrint(location)
assert.NoError(t, err, "PrettyPrint should not return an error")
}