Skip to content

Commit

Permalink
lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-mishra committed Jan 5, 2024
1 parent 965044c commit b434e2a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
6 changes: 4 additions & 2 deletions postprocess/postprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const (
RemoveCommand = "postprocess_remove"
// UndoCommand can be used to undo last postprocessing step.
UndoCommand = "postprocess_undo"
// PathCommand can be used to specify a pcd that has already been postprocessed.
PathCommand = "postprocess_path"
// FileCommand can be used to specify a pcd that has already been postprocessed.
FileCommand = "postprocess_file"
// Path is the expected path of any postprocessed map.
Path = "/usr/local/share"
)

var (
Expand Down
12 changes: 7 additions & 5 deletions viam_cartographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"bytes"
"context"
"os"
"path/filepath"
"strconv"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -689,20 +690,21 @@ func (cartoSvc *CartographerService) DoCommand(ctx context.Context, req map[stri
return map[string]interface{}{postprocess.UndoCommand: SuccessMessage}, nil
}

if val, ok := req[postprocess.PathCommand]; ok {
path, ok := val.(string)
if val, ok := req[postprocess.FileCommand]; ok {
file, ok := val.(string)
if !ok {
return nil, ErrBadPostprocessingPath
}

//nolint:all
bytes, err := os.ReadFile(path)
fullPath := postprocess.Path + file
fullPath = filepath.Clean(fullPath)
bytes, err := os.ReadFile(fullPath)
if err != nil {
return nil, err
}
cartoSvc.postprocessedPointCloud = &bytes
cartoSvc.postprocessed.Store(true)
return map[string]interface{}{postprocess.PathCommand: SuccessMessage}, nil
return map[string]interface{}{postprocess.FileCommand: SuccessMessage}, nil
}

return nil, viamgrpc.UnimplementedError
Expand Down
10 changes: 5 additions & 5 deletions viam_cartographer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,22 @@ func TestDoCommand(t *testing.T) {
t.Run(
"success if 'postprocess_path' is called correctly",
func(t *testing.T) {
path := artifact.MustPath("viam-cartographer/outputs/viam-office-02-22-3/pointcloud/pointcloud_1.pcd")
cmd := map[string]interface{}{postprocess.PathCommand: path}
file := artifact.MustPath("viam-cartographer/outputs/viam-office-02-22-3/pointcloud/pointcloud_1.pcd")
cmd := map[string]interface{}{postprocess.FileCommand: file}
resp, err := svc.DoCommand(context.Background(), cmd)
test.That(t, err, test.ShouldBeNil)
test.That(
t,
resp,
test.ShouldResemble,
map[string]interface{}{postprocess.PathCommand: viamcartographer.SuccessMessage},
map[string]interface{}{postprocess.FileCommand: viamcartographer.SuccessMessage},
)
})
t.Run(
"errors if 'postprocess_path' is called with incorrect format",
func(t *testing.T) {
point := map[string]interface{}{"X": float64(1), "Y": float64(1)}
cmd := map[string]interface{}{postprocess.PathCommand: point}
file := map[string]interface{}{"X": float64(1), "Y": float64(1)}
cmd := map[string]interface{}{postprocess.FileCommand: file}
resp, err := svc.DoCommand(context.Background(), cmd)
test.That(t, err.Error(), test.ShouldContainSubstring, viamcartographer.ErrBadPostprocessingPath.Error())
test.That(t, resp, test.ShouldBeNil)
Expand Down

0 comments on commit b434e2a

Please sign in to comment.