forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
53 lines (45 loc) · 1.57 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
package errors_test
import (
"fmt"
"testing"
"github.com/argoproj/argo/errors"
pkgerr "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
// stackTracer is interface for error types that have a stack trace
type stackTracer interface {
StackTrace() pkgerr.StackTrace
}
// TestErrorf tests the initializer of error package
func TestErrorf(t *testing.T) {
err := errors.Errorf(errors.CodeInternal, "test internal")
assert.Equal(t, err.Error(), "test internal")
}
// TestWrap ensures we can wrap an error and use Cause() to retrieve the original error
func TestWrap(t *testing.T) {
err := fmt.Errorf("original error message")
argoErr := errors.Wrap(err, "WRAPPED", "wrapped message")
assert.Equal(t, "wrapped message", argoErr.Error())
orig := errors.Cause(argoErr)
assert.Equal(t, err.Error(), orig.Error())
}
// TestInternalError verifies
func TestInternalError(t *testing.T) {
err := errors.InternalError("test internal")
assert.Equal(t, "test internal", err.Error())
// Test wrapping errors
err = fmt.Errorf("random error")
intWrap := errors.InternalWrapError(err)
_ = intWrap.(stackTracer)
assert.Equal(t, "random error", intWrap.Error())
intWrap = errors.InternalWrapError(err, "different message")
_ = intWrap.(stackTracer)
assert.Equal(t, "different message", intWrap.Error())
intWrap = errors.InternalWrapErrorf(err, "hello %s", "world")
_ = intWrap.(stackTracer)
assert.Equal(t, "hello world", intWrap.Error())
}
func TestStackTrace(t *testing.T) {
err := errors.New("MYCODE", "my message")
assert.Contains(t, fmt.Sprintf("%+v", err), "errors_test.go")
}