File: test.manual_validator.pb.go

package info (click to toggle)
golang-github-grpc-ecosystem-go-grpc-middleware 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,464 kB
  • sloc: makefile: 107; sh: 9
file content (67 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
// Manual code for validation tests.

package testpb

import (
	"errors"
	"math"
)

func (x *PingRequest) Validate(bool) error {
	if x.SleepTimeMs > 10000 {
		return errors.New("cannot sleep for more than 10s")
	}
	return nil
}

func (x *PingErrorRequest) Validate() error {
	if x.SleepTimeMs > 10000 {
		return errors.New("cannot sleep for more than 10s")
	}
	return nil
}

func (x *PingListRequest) Validate(bool) error {
	if x.SleepTimeMs > 10000 {
		return errors.New("cannot sleep for more than 10s")
	}
	return nil
}

func (x *PingStreamRequest) Validate(bool) error {
	if x.SleepTimeMs > 10000 {
		return errors.New("cannot sleep for more than 10s")
	}
	return nil
}

// Validate implements the legacy validation interface from protoc-gen-validate.
func (x *PingResponse) Validate() error {
	if x.Counter > math.MaxInt16 {
		return errors.New("ping allocation exceeded")
	}
	return nil
}

// ValidateAll implements the new ValidateAll interface from protoc-gen-validate.
func (x *PingResponse) ValidateAll() error {
	if x.Counter > math.MaxInt16 {
		return errors.New("ping allocation exceeded")
	}
	return nil
}

var (
	GoodPing       = &PingRequest{Value: "something", SleepTimeMs: 9999}
	GoodPingError  = &PingErrorRequest{Value: "something", SleepTimeMs: 9999}
	GoodPingList   = &PingListRequest{Value: "something", SleepTimeMs: 9999}
	GoodPingStream = &PingStreamRequest{Value: "something", SleepTimeMs: 9999}

	BadPing       = &PingRequest{Value: "something", SleepTimeMs: 10001}
	BadPingError  = &PingErrorRequest{Value: "something", SleepTimeMs: 10001}
	BadPingList   = &PingListRequest{Value: "something", SleepTimeMs: 10001}
	BadPingStream = &PingStreamRequest{Value: "something", SleepTimeMs: 10001}

	GoodPingResponse = &PingResponse{Counter: 100}
	BadPingResponse  = &PingResponse{Counter: math.MaxInt16 + 1}
)