5
5
package proxy
6
6
7
7
import (
8
+ "context"
8
9
"errors"
9
10
"fmt"
10
11
"testing"
@@ -17,55 +18,59 @@ import (
17
18
18
19
func TestConvertError (t * testing.T ) {
19
20
scenarios := []struct {
20
- WebsocketError error
21
- ExpectedError error
21
+ Input error
22
+ ExpectedError error
22
23
}{
23
24
{
24
- WebsocketError : & protocol.ErrBadHandshake {
25
+ Input : & protocol.ErrBadHandshake {
25
26
URL : "https://foo.bar" ,
26
27
},
27
28
ExpectedError : connect .NewError (connect .CodeUnauthenticated , fmt .Errorf ("Failed to establish caller identity" )),
28
29
},
29
30
{
30
- WebsocketError : & jsonrpc2.Error {
31
+ Input : & jsonrpc2.Error {
31
32
Code : 400 ,
32
33
Message : "user id is a required argument" ,
33
34
},
34
35
ExpectedError : connect .NewError (connect .CodeInvalidArgument , fmt .Errorf ("user id is a required argument" )),
35
36
},
36
37
{
37
- WebsocketError : & jsonrpc2.Error {
38
+ Input : & jsonrpc2.Error {
38
39
Code : - 32603 ,
39
40
Message : "Request getWorkspace failed with message: No workspace with id 'some-id' found." ,
40
41
},
41
42
ExpectedError : connect .NewError (connect .CodeInternal , fmt .Errorf ("Request getWorkspace failed with message: No workspace with id 'some-id' found." )),
42
43
},
43
44
{
44
- WebsocketError : & jsonrpc2.Error {
45
+ Input : & jsonrpc2.Error {
45
46
Code : 409 ,
46
47
Message : "already exists" ,
47
48
},
48
49
ExpectedError : connect .NewError (connect .CodeAlreadyExists , fmt .Errorf ("already exists" )),
49
50
},
50
51
{
51
- WebsocketError : & jsonrpc2.Error {
52
+ Input : & jsonrpc2.Error {
52
53
Code : 470 ,
53
54
Message : "user blocked" ,
54
55
},
55
56
ExpectedError : connect .NewError (connect .CodePermissionDenied , fmt .Errorf ("user blocked" )),
56
57
},
57
58
{
58
- WebsocketError : nil ,
59
- ExpectedError : nil ,
59
+ Input : nil ,
60
+ ExpectedError : nil ,
60
61
},
61
62
{
62
- WebsocketError : errors .New ("some other random error returns internal error" ),
63
- ExpectedError : connect .NewError (connect .CodeInternal , fmt .Errorf ("some other random error returns internal error" )),
63
+ Input : errors .New ("some other random error returns internal error" ),
64
+ ExpectedError : connect .NewError (connect .CodeInternal , fmt .Errorf ("some other random error returns internal error" )),
65
+ },
66
+ {
67
+ Input : context .Canceled ,
68
+ ExpectedError : connect .NewError (connect .CodeDeadlineExceeded , fmt .Errorf ("Request timed out" )),
64
69
},
65
70
}
66
71
67
72
for _ , s := range scenarios {
68
- converted := ConvertError (s .WebsocketError )
73
+ converted := ConvertError (s .Input )
69
74
require .Equal (t , s .ExpectedError , converted )
70
75
}
71
76
}
0 commit comments