forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
40 lines (33 loc) · 1.2 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
package errors_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/argoproj/argo-workflows/v3/errors"
)
// TestErrorf tests the initializer of error package
func TestErrorf(t *testing.T) {
err := errors.Errorf(errors.CodeInternal, "test internal")
assert.Equal(t, "test internal", err.Error())
}
// 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)
assert.Equal(t, "random error", intWrap.Error())
intWrap = errors.InternalWrapError(err, "different message")
assert.Equal(t, "different message", intWrap.Error())
intWrap = errors.InternalWrapErrorf(err, "hello %s", "world")
assert.Equal(t, "hello world", intWrap.Error())
}