Skip to content

Commit

Permalink
feat! deprecate single measurement get and delete options as Cumuloci…
Browse files Browse the repository at this point in the history
…ty IoT has removed support for them.
  • Loading branch information
reubenmiller committed Jan 24, 2024
1 parent 5d62834 commit d571c1d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
8 changes: 6 additions & 2 deletions pkg/c8y/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ func (s *MeasurementService) GetMeasurementSeries(ctx context.Context, opt *Meas
return data, resp, nil
}

// GetMeasurement returns a single measurement
// Deprecated: GetMeasurement returns a single measurement
// Note: Retieving single measurements is no longer supported in Cumulocity IoT
// when using the time series feature. Use GetMeasurements() instead
func (s *MeasurementService) GetMeasurement(ctx context.Context, ID string) (*Measurement, *Response, error) {
data := new(Measurement)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Expand All @@ -314,7 +316,9 @@ func (s *MeasurementService) GetMeasurement(ctx context.Context, ID string) (*Me
return data, resp, err
}

// Delete removed a measurement by ID
// Deprecated: Delete removed a measurement by ID
// Note: Deleting single measurements is no longer supported in Cumulocity IoT
// when using the time series feature. Use DeleteMeasurements() instead
func (s *MeasurementService) Delete(ctx context.Context, ID string) (*Response, error) {
return s.client.SendRequest(ctx, RequestOptions{
Method: "DELETE",
Expand Down
39 changes: 8 additions & 31 deletions test/c8y_test/measurement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ func TestMeasurementService_CreateWithDifferentTypes(t *testing.T) {
// createMeasurement(false)
}

func TestMeasurementService_GetMeasurement_DeleteMeasurement(t *testing.T) {
func TestMeasurementService_GetMeasurement(t *testing.T) {
// Note: Removing single measurements is no longer supported by Cumulocity IoT
client := createTestClient()
testDevice, err := createRandomTestDevice()
testingutils.Ok(t, err)
Expand Down Expand Up @@ -373,24 +374,6 @@ func TestMeasurementService_GetMeasurement_DeleteMeasurement(t *testing.T) {
testingutils.Ok(t, err)
testingutils.Equals(t, http.StatusOK, resp.StatusCode())
testingutils.Equals(t, meas.ID, meas2.ID)

// Remove measurement
resp, err = client.Measurement.Delete(
context.Background(),
meas2.ID,
)

testingutils.Ok(t, err)
testingutils.Equals(t, http.StatusNoContent, resp.StatusCode())

// Check if the measurement has been deleted
meas3, resp, err := client.Measurement.GetMeasurement(
context.Background(),
meas2.ID,
)
testingutils.Assert(t, err != nil, "Error should not be nil")
testingutils.Equals(t, http.StatusNotFound, resp.StatusCode())
testingutils.Assert(t, meas3.ID == "", "ID should be empty when the object is not found")
}

func TestMeasurementService_DeleteMeasurements(t *testing.T) {
Expand Down Expand Up @@ -435,22 +418,16 @@ func TestMeasurementService_DeleteMeasurements(t *testing.T) {
testingutils.Equals(t, http.StatusNoContent, resp.StatusCode())

// Check that the measurements have been removed
deletedMeas1, resp, err := client.Measurement.GetMeasurement(
// Check by requesting the new collection again as retrieving single measurements
// is no longer supported by Cumulocity IoT
measColAfter, resp, err := client.Measurement.GetMeasurements(
context.Background(),
meas1.ID,
searchOptions,
)
testingutils.Assert(t, err != nil, "Error should not be nil")
testingutils.Equals(t, http.StatusNotFound, resp.StatusCode())
testingutils.Equals(t, "", deletedMeas1.ID)

// Check that the measurements have been removed
deletedMeas2, resp, err := client.Measurement.GetMeasurement(
context.Background(),
meas1.ID,
)
testingutils.Assert(t, err != nil, "Error should not be nil")
testingutils.Equals(t, http.StatusNotFound, resp.StatusCode())
testingutils.Equals(t, "", deletedMeas2.ID)
testingutils.Equals(t, http.StatusOK, resp.StatusCode())
testingutils.Equals(t, 0, len(measColAfter.Measurements))
}

func TestMeasurementService_CreateMeasurements(t *testing.T) {
Expand Down

0 comments on commit d571c1d

Please sign in to comment.