-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
62 lines (58 loc) · 1.43 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"context"
"os"
"testing"
"connectrpc.com/connect"
geov2 "git.fiblab.net/sim/protos/go/city/geo/v2"
routingv2 "git.fiblab.net/sim/protos/go/city/routing/v2"
"github.com/stretchr/testify/assert"
)
func FuzzRouter(f *testing.F) {
mapPath, err := NewPath(os.Getenv("MAP_PATH"))
assert.NoError(f, err)
server := NewRoutingServer(
os.Getenv("MONGO_URI"),
mapPath, nil, "./data",
)
// 构造随机请求
f.Fuzz(func(t *testing.T, driving bool, startAoi bool, startID uint16, startS float64, endAoi bool, endID uint16, endS float64) {
req := &routingv2.GetRouteRequest{}
if driving {
req.Type = routingv2.RouteType_ROUTE_TYPE_DRIVING
} else {
req.Type = routingv2.RouteType_ROUTE_TYPE_WALKING
}
if startAoi {
req.Start = &geov2.Position{
AoiPosition: &geov2.AoiPosition{
AoiId: 5_0000_0000 + int32(startID),
},
}
} else {
req.Start = &geov2.Position{
LanePosition: &geov2.LanePosition{
LaneId: int32(startID),
S: startS,
},
}
}
if endAoi {
req.End = &geov2.Position{
AoiPosition: &geov2.AoiPosition{
AoiId: 5_0000_0000 + int32(endID),
},
}
} else {
req.End = &geov2.Position{
LanePosition: &geov2.LanePosition{
LaneId: int32(endID),
S: endS,
},
}
}
res, err := server.GetRoute(context.Background(), connect.NewRequest(req))
// 有且只有一个是nil
assert.True(f, (res == nil) != (err == nil))
})
}