-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy patherrors_test.go
50 lines (35 loc) · 1.32 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
package ngrok
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
"golang.ngrok.com/ngrok/internal/tunnel/proto"
)
// Sanity check for the approach to error construction/wrapping
func TestErrorWrapping(t *testing.T) {
inner := errors.New("testing, 1 2 3")
accept := errAcceptFailed{Inner: inner}
auth := errAuthFailed{true, accept}
require.ErrorIs(t, accept, errAcceptFailed{})
require.ErrorIs(t, auth, errAuthFailed{})
require.ErrorIs(t, auth, errAcceptFailed{})
var downcastAuth errAuthFailed
var downcastAccept errAcceptFailed
require.ErrorAs(t, auth, &downcastAuth)
require.ErrorAs(t, auth, &downcastAccept)
require.ErrorAs(t, accept, &downcastAccept)
require.True(t, downcastAuth.Remote)
}
func TestNgrokErrorWrapping(t *testing.T) {
rootErr := proto.StringError("ngrok error\n\nERR_NGROK_123")
nonNgrokRootErr := errors.New("generic non ngrok error")
ngrokErr := errAuthFailed{true, rootErr}
nonNgrokErr := errAuthFailed{true, nonNgrokRootErr}
require.EqualError(t, ngrokErr, "authentication failed: ngrok error\n\nERR_NGROK_123")
var nerr Error
require.ErrorAs(t, ngrokErr, &nerr)
require.EqualError(t, nerr, "ngrok error\n\nERR_NGROK_123")
require.Equal(t, "ngrok error", nerr.Msg())
require.Equal(t, "ERR_NGROK_123", nerr.ErrorCode())
require.False(t, errors.As(nonNgrokErr, &nerr))
}