-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
41 lines (33 loc) · 930 Bytes
/
main_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
package main
import (
"context"
"errors"
"fmt"
"github.com/bufbuild/protovalidate-go"
"github.com/dmitrorezn/proto-validation-example/gen/apis/processor"
"github.com/stretchr/testify/assert"
"testing"
)
func TestProcessorSvc_Process(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
svc, err := newProcessorSvc(ctx)
assert.NoError(t, err)
request := processor.ProcessRequest{
Name: "",
}
_, err = svc.Process(ctx, &request)
assert.Error(t, err)
verr := &protovalidate.ValidationError{}
assert.True(t, errors.As(err, &verr))
fmt.Println("verr", verr)
if assert.Len(t, verr.Violations, 1) {
assert.Equal(t, verr.Violations[0].Message, "name: value length must be at least 1 characters [string.min_len]")
}
request = processor.ProcessRequest{
Name: "Test",
}
resp, err := svc.Process(ctx, &request)
assert.NoError(t, err)
assert.NotEmpty(t, resp.GetId())
}