diff --git a/app/data_client.go b/app/data_client.go index b8db3b99de5..806e9e6bb09 100644 --- a/app/data_client.go +++ b/app/data_client.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "io" "os" "path/filepath" "time" @@ -203,21 +204,6 @@ type ExportTabularDataResponse struct { Payload map[string]interface{} } -// ExportTabularDataStream is a stream that returns ExportTabularDataResponses. -type ExportTabularDataStream struct { - Stream pb.DataService_ExportTabularDataClient -} - -// Next gets the next ExportTabularDataResponse. -func (e *ExportTabularDataStream) Next() (*ExportTabularDataResponse, error) { - streamResp, err := e.Stream.Recv() - if err != nil { - return nil, err - } - - return exportTabularDataResponseFromProto(streamResp), nil -} - // DataSyncClient structs // SensorMetadata contains the time the sensor data was requested and was received. @@ -503,7 +489,7 @@ func (d *DataClient) GetLatestTabularData(ctx context.Context, partID, resourceN // ExportTabularData returns a stream of ExportTabularDataResponses. func (d *DataClient) ExportTabularData( ctx context.Context, partID, resourceName, resourceSubtype, method string, interval CaptureInterval, -) (*ExportTabularDataStream, error) { +) ([]*ExportTabularDataResponse, error) { stream, err := d.dataClient.ExportTabularData(ctx, &pb.ExportTabularDataRequest{ PartId: partID, ResourceName: resourceName, @@ -514,9 +500,22 @@ func (d *DataClient) ExportTabularData( if err != nil { return nil, err } - return &ExportTabularDataStream{ - Stream: stream, - }, nil + + var responses []*ExportTabularDataResponse + + for { + response, err := stream.Recv() + if errors.Is(err, io.EOF) { + break + } + if err != nil { + return nil, err + } + + responses = append(responses, exportTabularDataResponseFromProto(response)) + } + + return responses, nil } // BinaryDataByFilter queries binary data and metadata based on given filters. diff --git a/app/data_client_test.go b/app/data_client_test.go index da278bba92a..d2f2ec2b7b9 100644 --- a/app/data_client_test.go +++ b/app/data_client_test.go @@ -2,6 +2,7 @@ package app import ( "context" + "io" "os" "testing" "time" @@ -392,8 +393,14 @@ func TestDataClient(t *testing.T) { }) t.Run("ExportTabularData", func(t *testing.T) { + sentOnce := false mockStream := &inject.DataServiceExportTabularDataClient{ RecvFunc: func() (*pb.ExportTabularDataResponse, error) { + if sentOnce { + return nil, io.EOF + } + + sentOnce = true return exportTabularResponse, nil }, } @@ -409,11 +416,9 @@ func TestDataClient(t *testing.T) { return mockStream, nil } - stream, err := client.ExportTabularData(context.Background(), partID, componentName, componentType, method, captureInterval) - test.That(t, err, test.ShouldBeNil) - resp, err := stream.Next() + responses, err := client.ExportTabularData(context.Background(), partID, componentName, componentType, method, captureInterval) test.That(t, err, test.ShouldBeNil) - test.That(t, resp, test.ShouldResemble, exportTabularDataResponseFromProto(exportTabularResponse)) + test.That(t, responses[0], test.ShouldResemble, exportTabularDataResponseFromProto(exportTabularResponse)) }) t.Run("BinaryDataByFilter", func(t *testing.T) {