-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
53 lines (40 loc) · 1.06 KB
/
errors_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
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package x
import (
"bytes"
"net/http"
"strings"
"testing"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/ory/x/logrusx"
)
type errStackTracer struct{}
func (s *errStackTracer) StackTrace() errors.StackTrace {
return errors.StackTrace{}
}
func (s *errStackTracer) Error() string {
return "foo"
}
func TestLogError(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "https://hydra/some/endpoint", nil)
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer([]byte{})
l := logrusx.New("", "", logrusx.ForceLevel(logrus.TraceLevel))
l.Logger.Out = buf
LogError(r, errors.New("asdf"), l)
t.Logf("%s", buf.String())
assert.True(t, strings.Contains(buf.String(), "trace"))
LogError(r, errors.Wrap(new(errStackTracer), ""), l)
}
func TestLogErrorDoesNotPanic(t *testing.T) {
r, err := http.NewRequest(http.MethodGet, "https://hydra/some/endpoint", nil)
if err != nil {
t.Fatal(err)
}
LogError(r, errors.New("asdf"), nil)
}