diff --git a/services/datamanager/datacapture/data_capture_file.go b/services/datamanager/datacapture/data_capture_file.go index 46d51af8981..931fd20112e 100644 --- a/services/datamanager/datacapture/data_capture_file.go +++ b/services/datamanager/datacapture/data_capture_file.go @@ -21,7 +21,7 @@ import ( // FileExt defines the file extension for Viam data capture files. const ( FileExt = ".capture" - next = "Next" + readImage = "ReadImage" nextPointCloud = "NextPointCloud" ) @@ -56,7 +56,7 @@ func BuildCaptureMetadata(compType resource.SubtypeName, compName, compModel, me return nil, err } - dataType := getDataType(string(compType), method) + dataType := getDataType(method) return &v1.DataCaptureMetadata{ ComponentType: string(compType), ComponentName: compName, @@ -112,9 +112,9 @@ func getFileTimestampName() string { // TODO DATA-246: Implement this in some more robust, programmatic way. // TODO: support GetImage. This is why image stuff isn't working. -func getDataType(_, methodName string) v1.DataType { +func getDataType(methodName string) v1.DataType { switch methodName { - case nextPointCloud, next: + case nextPointCloud, readImage: return v1.DataType_DATA_TYPE_BINARY_SENSOR default: return v1.DataType_DATA_TYPE_TABULAR_SENSOR @@ -133,7 +133,7 @@ func GetFileExt(dataType v1.DataType, methodName string, parameters map[string]s if methodName == nextPointCloud { return ".pcd" } - if methodName == next { + if methodName == readImage { // TODO: Add explicit file extensions for all mime types. switch parameters["mime_type"] { case utils.MimeTypeJPEG: diff --git a/services/datamanager/datacapture/data_capture_file_test.go b/services/datamanager/datacapture/data_capture_file_test.go index a346c114f6e..7353af30de9 100644 --- a/services/datamanager/datacapture/data_capture_file_test.go +++ b/services/datamanager/datacapture/data_capture_file_test.go @@ -39,7 +39,7 @@ func TestBuildCaptureMetadata(t *testing.T) { componentType: "camera", componentName: "cam1", componentModel: "webcam", - method: "Next", + method: readImage, additionalParams: map[string]string{"mime_type": utils.MimeTypeJPEG}, dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR, fileExtension: ".jpeg", @@ -50,7 +50,7 @@ func TestBuildCaptureMetadata(t *testing.T) { componentType: "camera", componentName: "cam1", componentModel: "velodyne", - method: "Next", + method: readImage, additionalParams: map[string]string{"mime_type": utils.MimeTypePCD}, dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR, fileExtension: ".pcd", @@ -61,7 +61,7 @@ func TestBuildCaptureMetadata(t *testing.T) { componentType: "camera", componentName: "cam1", componentModel: "velodyne", - method: "NextPointCloud", + method: nextPointCloud, additionalParams: make(map[string]string), dataType: v1.DataType_DATA_TYPE_BINARY_SENSOR, fileExtension: ".pcd", @@ -70,24 +70,25 @@ func TestBuildCaptureMetadata(t *testing.T) { } for _, tc := range tests { - t.Log(tc.name) - actualMetadata, err := BuildCaptureMetadata( - tc.componentType, tc.componentName, tc.componentModel, tc.method, tc.additionalParams, tc.tags) - test.That(t, err, test.ShouldEqual, nil) + t.Run(tc.name, func(t *testing.T) { + actualMetadata, err := BuildCaptureMetadata( + tc.componentType, tc.componentName, tc.componentModel, tc.method, tc.additionalParams, tc.tags) + test.That(t, err, test.ShouldEqual, nil) - methodParams, err := protoutils.ConvertStringMapToAnyPBMap(tc.additionalParams) - test.That(t, err, test.ShouldEqual, nil) + methodParams, err := protoutils.ConvertStringMapToAnyPBMap(tc.additionalParams) + test.That(t, err, test.ShouldEqual, nil) - expectedMetadata := v1.DataCaptureMetadata{ - ComponentType: string(tc.componentType), - ComponentName: tc.componentName, - ComponentModel: tc.componentModel, - MethodName: tc.method, - Type: tc.dataType, - MethodParameters: methodParams, - FileExtension: tc.fileExtension, - Tags: tc.tags, - } - test.That(t, actualMetadata.String(), test.ShouldEqual, expectedMetadata.String()) + expectedMetadata := v1.DataCaptureMetadata{ + ComponentType: string(tc.componentType), + ComponentName: tc.componentName, + ComponentModel: tc.componentModel, + MethodName: tc.method, + Type: tc.dataType, + MethodParameters: methodParams, + FileExtension: tc.fileExtension, + Tags: tc.tags, + } + test.That(t, actualMetadata.String(), test.ShouldEqual, expectedMetadata.String()) + }) } }