-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_assertion.go
56 lines (42 loc) · 1.18 KB
/
client_assertion.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
54
55
56
package grpcsteps
import (
"fmt"
"github.com/swaggest/assertjson"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func assertServerResponsePayload(req clientRequest, expected string) error {
actual, err := req.Do()
if err != nil {
return fmt.Errorf("an error occurred while send grpc request: %w", err)
}
return assertjson.FailNotEqual([]byte(expected), actual)
}
func assertServerResponseErrorCode(req clientRequest, expected codes.Code) error {
_, err := req.Do()
if err == nil {
if expected != codes.OK {
return fmt.Errorf("got no error, want %q", expected) // nolint: goerr113
}
return nil
}
actual := status.Convert(err).Code()
if expected != actual {
return fmt.Errorf("got %w, want %q", err, expected)
}
return nil
}
func assertServerResponseErrorMessage(req clientRequest, expected string) error {
_, err := req.Do()
if err == nil {
if expected != "" {
return fmt.Errorf("got no error, want %q", expected) // nolint: goerr113
}
return nil
}
actual := status.Convert(err).Message()
if expected != actual {
return fmt.Errorf("unexpected error message, got %q, want %q", actual, expected) // nolint: goerr113
}
return nil
}