Skip to content

Commit

Permalink
more rdk changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jckras committed Sep 20, 2024
1 parent c9aad8a commit 938cc63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions components/camera/camera_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
depthCameraName = "camera_depth"
failCameraName = "camera2"
missingCameraName = "camera3"
noFrameRateName = "camera4"
)

type simpleSource struct {
Expand Down
2 changes: 1 addition & 1 deletion components/camera/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func TestClientProperties(t *testing.T) {
FrameRate: fakeFrameRate,
},
}, {
name: "nil frame rate parameters",
name: "no frame rate parameters",
props: camera.Properties{
SupportsPCD: true,
ImageType: camera.UnspecifiedStream,
Expand Down
22 changes: 18 additions & 4 deletions components/camera/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ var (
errCameraUnimplemented = errors.New("not found")
)

func newServer() (pb.CameraServiceServer, *inject.Camera, *inject.Camera, *inject.Camera, error) {
func newServer() (pb.CameraServiceServer, *inject.Camera, *inject.Camera, *inject.Camera, *inject.Camera, error) {
injectCamera := &inject.Camera{}
injectCameraDepth := &inject.Camera{}
injectCamera2 := &inject.Camera{}
injectCamera3 := &inject.Camera{}
cameras := map[resource.Name]camera.Camera{
camera.Named(testCameraName): injectCamera,
camera.Named(depthCameraName): injectCameraDepth,
camera.Named(failCameraName): injectCamera2,
camera.Named(noFrameRateName): injectCamera3,
}
cameraSvc, err := resource.NewAPIResourceCollection(camera.API, cameras)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, err
}
return camera.NewRPCServiceServer(cameraSvc).(pb.CameraServiceServer), injectCamera, injectCameraDepth, injectCamera2, nil
return camera.NewRPCServiceServer(cameraSvc).(pb.CameraServiceServer), injectCamera, injectCameraDepth, injectCamera2, injectCamera3, nil
}

func TestServer(t *testing.T) {
cameraServer, injectCamera, injectCameraDepth, injectCamera2, err := newServer()
cameraServer, injectCamera, injectCameraDepth, injectCamera2, injectCamera3, err := newServer()
test.That(t, err, test.ShouldBeNil)

img := image.NewRGBA(image.Rect(0, 0, 4, 4))
Expand Down Expand Up @@ -176,6 +178,14 @@ func TestServer(t *testing.T) {
injectCamera2.StreamFunc = func(ctx context.Context, errHandlers ...gostream.ErrorHandler) (gostream.VideoStream, error) {
return nil, errStreamFailed
}
// no frame rate camera
injectCamera3.PropertiesFunc = func(ctx context.Context) (camera.Properties, error) {
return camera.Properties{
SupportsPCD: true,
IntrinsicParams: intrinsics,
MimeTypes: []string{utils.MimeTypeJPEG, utils.MimeTypePNG, utils.MimeTypeH264},
}, nil
}
// does a depth camera transfer its depth image properly
t.Run("GetImage", func(t *testing.T) {
_, err := cameraServer.GetImage(context.Background(), &pb.GetImageRequest{Name: missingCameraName})
Expand Down Expand Up @@ -426,6 +436,10 @@ func TestServer(t *testing.T) {
test.That(t, resp.MimeTypes, test.ShouldContain, utils.MimeTypeH264)
test.That(t, resp.FrameRate, test.ShouldNotBeNil)
test.That(t, *resp.FrameRate, test.ShouldEqual, 10.0)

resp2, err := cameraServer.GetProperties(context.Background(), &pb.GetPropertiesRequest{Name: noFrameRateName})
test.That(t, resp2.FrameRate, test.ShouldBeNil)

})

t.Run("GetImage with extra", func(t *testing.T) {
Expand Down

0 comments on commit 938cc63

Please sign in to comment.