This repository was archived by the owner on Jan 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidator_test.go
More file actions
97 lines (95 loc) · 2.97 KB
/
Copy pathvalidator_test.go
File metadata and controls
97 lines (95 loc) · 2.97 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package service
import (
"github.com/kevinmichaelchen/api-dispatch/internal/idl/coop/drivers/dispatch/v1beta1"
"github.com/stretchr/testify/require"
"testing"
)
func Test_validateGetNearestDriversRequest(t *testing.T) {
buildValid := func() *v1beta1.GetNearestDriversRequest {
return &v1beta1.GetNearestDriversRequest{
PickupLocation: &v1beta1.LatLng{
Latitude: 40.2,
Longitude: -73.3,
},
Limit: 5,
}
}
cases := map[string]struct {
build func() *v1beta1.GetNearestDriversRequest
expect func(t *testing.T, err error)
}{
"Valid": {
build: buildValid,
expect: func(t *testing.T, err error) {
require.NoError(t, err)
},
},
"Negative limit": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.Limit = -5
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.Limit: value must be inside range (0, 1000]`)
},
},
"Excessive limit": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.Limit = 1001
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.Limit: value must be inside range (0, 1000]`)
},
},
"Latitude too low": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.PickupLocation.Latitude = -91
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.PickupLocation: embedded message failed validation | caused by: invalid LatLng.Latitude: value must be inside range [-90, 90]`)
},
},
"Latitude too high": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.PickupLocation.Latitude = 91
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.PickupLocation: embedded message failed validation | caused by: invalid LatLng.Latitude: value must be inside range [-90, 90]`)
},
},
"Longitude too low": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.PickupLocation.Longitude = -181
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.PickupLocation: embedded message failed validation | caused by: invalid LatLng.Longitude: value must be inside range [-180, 180]`)
},
},
"Longitude too high": {
build: func() *v1beta1.GetNearestDriversRequest {
p := buildValid()
p.PickupLocation.Longitude = 181
return p
},
expect: func(t *testing.T, err error) {
require.EqualError(t, err, `invalid GetNearestDriversRequest.PickupLocation: embedded message failed validation | caused by: invalid LatLng.Longitude: value must be inside range [-180, 180]`)
},
},
}
for testName, tc := range cases {
t.Run(testName, func(t *testing.T) {
r := tc.build()
err := r.Validate()
tc.expect(t, err)
})
}
}