Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyck committed Jul 17, 2020
1 parent 8e879ea commit 8da2327
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
4 changes: 1 addition & 3 deletions measurement/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ var measurement = `{
},
"AirPressure":{"value":1011.2,"unit":"hPa"},
"Humidity":{"value":51,"unit":"%RH"},
"Temperature":{"value":23.45,"unit":"C"},
"Custom1":"Hello world",
"Custom2": 1234
"Temperature":{"value":23.45,"unit":"C"}
}`

var measurementCollectionTemplate = `{
Expand Down
19 changes: 6 additions & 13 deletions measurement/measurementApi_find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,12 @@ func TestMeasurementApi_FindWithFilter(t *testing.T) {
t.Errorf("Find() = %v, want %v", cUrl.RawQuery, tt.expectedQuery)
}

if len(measurementCollection.Measurements) > 0 {
for _, measurement := range measurementCollection.Measurements {
custom1, ok1 := measurement.Metrics["Custom1"].(string)
custom2, ok2 := measurement.Metrics["Custom2"].(interface{})

if !(ok1 && custom1 == "Hello world") {
t.Errorf("GetForDevice() custom1 = %v, want %v", custom1, "Hello world")
}
if !(ok2 && custom2.(float64) == 1234) {
t.Errorf("GetForDevice() custom2 = %v, want %v", custom2, 1234)
}
}
if len(measurementCollection.Measurements) != 1 {
t.Fatalf("Find() measurements count = %v, want %v", len(measurementCollection.Measurements), 1)
}

measurement := measurementCollection.Measurements[0]
assertMetricsOfMeasurement(measurement.Metrics, t)
})
}
}
Expand Down Expand Up @@ -225,4 +218,4 @@ func TestMeasurementApi_FindReturnsError(t *testing.T) {
if err.Info != "https://www.cumulocity.com/guides/reference-guide/#error_reporting" {
t.Errorf("Find() = '%v', want '%v'", err.Info, "https://www.cumulocity.com/guides/reference-guide/#error_reporting")
}
}
}
14 changes: 1 addition & 13 deletions measurement/measurementApi_get_for_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,7 @@ func TestMeasurementApi_GetForDevice_ExistingId(t *testing.T) {
t.Errorf("GetForDevice() measurement id = %v, want %v", measurement.Id, measurementId)
}

if len(collection.Measurements) > 0 {
for _, measurement := range collection.Measurements {
custom1, ok1 := measurement.Metrics["Custom1"].(string)
custom2, ok2 := measurement.Metrics["Custom2"].(interface{})

if !(ok1 && custom1 == "Hello world") {
t.Errorf("GetForDevice() custom1 = %v, want %v", custom1, "Hello world")
}
if !(ok2 && custom2.(float64) == 1234) {
t.Errorf("GetForDevice() custom2 = %v, want %v", custom2, 1234)
}
}
}
assertMetricsOfMeasurement(measurement.Metrics, t)
}

func TestMeasurementApi_GetForDevice_HandlesPageSize(t *testing.T) {
Expand Down
10 changes: 1 addition & 9 deletions measurement/measurementApi_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ func TestMeasurementApi_Get_ExistingId(t *testing.T) {
t.Errorf("Get() measurement id = %v, want %v", measurement.Id, measurementId)
}

custom1, ok1 := measurement.Metrics["Custom1"].(string)
custom2, ok2 := measurement.Metrics["Custom2"].(interface{})

if !(ok1 && custom1 == "Hello world") {
t.Errorf("GetForDevice() custom1 = %v, want %v", custom1, "Hello world")
}
if !(ok2 && custom2.(float64) == 1234) {
t.Errorf("GetForDevice() custom2 = %v, want %v", custom2, 1234)
}
assertMetricsOfMeasurement(measurement.Metrics, t)
}

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

0 comments on commit 8da2327

Please sign in to comment.