-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_helper_test.go
More file actions
44 lines (37 loc) · 876 Bytes
/
test_helper_test.go
File metadata and controls
44 lines (37 loc) · 876 Bytes
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
// Copyright 2018 The OpenPitrix Authors. All rights reserved.
// Use of this source code is governed by a Apache license
// that can be found in the LICENSE file.
package logger
import (
"bytes"
"context"
"io/ioutil"
"testing"
"openpitrix.io/logger/ctxutil"
)
type tLogger struct {
t *testing.T
buf bytes.Buffer
*Logger
}
func tNewLogger(t *testing.T) *tLogger {
p := &tLogger{Logger: New()}
p.Logger.SetOutput(&p.buf)
return p
}
func (p *tLogger) ReadAll() string {
data, err := ioutil.ReadAll(&p.buf)
if err != nil {
p.t.Fatal(err)
}
return string(data)
}
func (p *tLogger) ReadAllMessage() []logMessage {
return readLogs(p.ReadAll())
}
func tNewCtxWithMessageId(reqId string, messageId ...string) context.Context {
ctx := context.Background()
ctx = ctxutil.SetRequestId(ctx, reqId)
ctx = ctxutil.SetMessageId(ctx, messageId...)
return ctx
}