-
Notifications
You must be signed in to change notification settings - Fork 110
/
robot_utils.go
53 lines (47 loc) · 1.3 KB
/
robot_utils.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
// Package robottestutils provides helper functions in testing
package robottestutils
import (
"context"
"net"
"testing"
"time"
"go.uber.org/zap"
"go.viam.com/test"
"go.viam.com/rdk/config"
"go.viam.com/rdk/grpc/client"
"go.viam.com/rdk/robot"
robotimpl "go.viam.com/rdk/robot/impl"
weboptions "go.viam.com/rdk/robot/web/options"
)
// StartBaseRobot creates a new local robot with a listener attached.
func StartBaseRobot(ctx context.Context,
t *testing.T,
logger *zap.SugaredLogger,
listener net.Listener,
cfg *config.Config,
) (robot.LocalRobot, weboptions.Options) {
t.Helper()
options := weboptions.New()
options.Network.BindAddress = ""
options.Network.Listener = listener
// start robot
robot, err := robotimpl.New(ctx, cfg, logger)
test.That(t, err, test.ShouldBeNil)
test.That(t, robot, test.ShouldNotBeNil)
return robot, options
}
// NewRobotClient creates a new robot client with a certain address.
func NewRobotClient(t *testing.T, logger *zap.SugaredLogger, addr string, dur time.Duration) *client.RobotClient {
t.Helper()
// start robot client
robotClient, err := client.New(
context.Background(),
addr,
logger,
client.WithRefreshEvery(dur),
client.WithCheckConnectedEvery(5*dur),
client.WithReconnectEvery(dur),
)
test.That(t, err, test.ShouldBeNil)
return robotClient
}