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}
)
|