MCPcopy Create free account
hub / github.com/chain/txvm / TestPrintkv

Function TestPrintkv

log/log_test.go:105–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func TestPrintkv(t *testing.T) {
106 examples := []struct {
107 keyvals []interface{}
108 want []string
109 }{
110 // Basic example
111 {
112 keyvals: []interface{}{"msg", "hello world"},
113 want: []string{
114 "at=log_test.go:",
115 "t=",
116 `msg="hello world"`,
117 },
118 },
119
120 // Duplicate keys
121 {
122 keyvals: []interface{}{"msg", "hello world", "msg", "goodbye world"},
123 want: []string{
124 "at=log_test.go:",
125 "t=",
126 `msg="hello world"`,
127 `msg="goodbye world"`,
128 },
129 },
130
131 // Zero log params
132 {
133 keyvals: nil,
134 want: []string{
135 "at=log_test.go:",
136 "t=",
137 },
138 },
139
140 // Odd number of log params
141 {
142 keyvals: []interface{}{"k1", "v1", "k2"},
143 want: []string{
144 "at=log_test.go:",
145 "t=",
146 "k1=v1",
147 "k2=",
148 `log-error="odd number of log params"`,
149 },
150 },
151 }
152
153 for i, ex := range examples {
154 t.Log("Example", i)
155
156 buf := new(bytes.Buffer)
157 SetOutput(buf)
158
159 Printkv(context.Background(), ex.keyvals...)
160
161 read, err := ioutil.ReadAll(buf)
162 if err != nil {

Callers

nothing calls this directly

Calls 3

SetOutputFunction · 0.85
PrintkvFunction · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected