Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
platinummonkey committed Jul 22, 2019
1 parent 72bcc1a commit ab6e70f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
14 changes: 12 additions & 2 deletions service_level_objectives.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,23 @@ func (s ServiceLevelObjectiveThresholds) Equal(o interface{}) bool {
return false
}

if len(s) != len(other) {
// easy case
return false
}

// compare one set from another
sSet := make(map[string]*ServiceLevelObjectiveThreshold, 0)
for _, t := range s {
sSet[t.GetTimeFrame()] = t
}
oSet := make(map[string]*ServiceLevelObjectiveThreshold, 0)
for _, t := range other {
threshold, ok := sSet[t.GetTimeFrame()]
oSet[t.GetTimeFrame()] = t
}

for timeframe, t := range oSet {
threshold, ok := sSet[timeframe]
if !ok {
// other contains more
return false
Expand All @@ -123,7 +133,7 @@ func (s ServiceLevelObjectiveThresholds) Equal(o interface{}) bool {
return false
}
// drop from sSet for efficiency
delete(sSet, t.GetTimeFrame())
delete(sSet, timeframe)
}
// if there are any remaining then they differ
if len(sSet) > 0 {
Expand Down
66 changes: 32 additions & 34 deletions tests/fixtures/service_level_objectives/get_by_id_response.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
{
"data": [
{
"id": "12345678901234567890123456789012",
"name": "Test SLO",
"tags": ["product:foo"],
"monitor_tags": ["service:bar", "team:a"],
"type": "monitor",
"type_id": 0,
"description": "test slo description",
"monitor_ids": [1],
"thresholds": [
{
"timeframe": "7d",
"slo": 99.0,
"slo_display": "99.0",
"warning": 99.5,
"warning_display": "99.5"
},
{
"timeframe": "30d",
"slo": 98,
"slo_display": "98.0",
"warning": 99,
"warning_display": "99.0"
}
],
"creator": {
"handle": "jane.doe@example.com",
"email": "jane.doe@example.com",
"name": "Jane Doe"
"data": {
"id": "12345678901234567890123456789012",
"name": "Test SLO",
"tags": ["product:foo"],
"monitor_tags": ["service:bar", "team:a"],
"type": "monitor",
"type_id": 0,
"description": "test slo description",
"monitor_ids": [1],
"thresholds": [
{
"timeframe": "7d",
"slo": 99.0,
"slo_display": "99.0",
"warning": 99.5,
"warning_display": "99.5"
},
"created_at": 1563283800,
"modified_at": 1563283800
}
],
{
"timeframe": "30d",
"slo": 98,
"slo_display": "98.0",
"warning": 99,
"warning_display": "99.0"
}
],
"creator": {
"handle": "jane.doe@example.com",
"email": "jane.doe@example.com",
"name": "Jane Doe"
},
"created_at": 1563283800,
"modified_at": 1563283800
},
"error": null
}

0 comments on commit ab6e70f

Please sign in to comment.