Skip to content

Commit

Permalink
Rules: fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
  • Loading branch information
hanjm committed Nov 17, 2021
1 parent c0a3531 commit a42d4c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/rules/rulespb/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) {
Interval: 2442,
LastEvaluation: now,
EvaluationDurationSeconds: 2.1,
Limit: 0,
PartialResponseStrategy: storepb.PartialResponseStrategy_ABORT,
Rules: []*Rule{},
},
Expand All @@ -78,7 +79,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) {
},
},
// Different than input due to default enum fields.
expectedJSONOutput: `{"groups":[{"name":"","file":"","rules":[],"interval":0,"evaluationTime":0,"lastEvaluation":"0001-01-01T00:00:00Z","partialResponseStrategy":"ABORT"}]}`,
expectedJSONOutput: `{"groups":[{"name":"","file":"","rules":[],"interval":0,"evaluationTime":0,"lastEvaluation":"0001-01-01T00:00:00Z","limit":0,"partialResponseStrategy":"ABORT"}]}`,
},
{
name: "one valid group, with 1 with no rule type",
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestJSONUnmarshalMarshal(t *testing.T) {
},
},
// Different than input due to the alerts slice being initialized to a zero-length slice instead of nil.
expectedJSONOutput: `{"groups":[{"name":"group1","file":"file1.yml","rules":[{"state":"pending","name":"alert1","query":"up == 0","duration":60,"labels":{"a2":"b2","c2":"d2"},"annotations":{"ann1":"ann44","ann2":"ann33"},"alerts":[],"health":"health2","lastError":"1","evaluationTime":1.1,"lastEvaluation":"0001-01-01T00:00:00Z","type":"alerting"}],"interval":2442,"evaluationTime":2.1,"lastEvaluation":"0001-01-01T00:00:00Z","partialResponseStrategy":"ABORT"}]}`,
expectedJSONOutput: `{"groups":[{"name":"group1","file":"file1.yml","rules":[{"state":"pending","name":"alert1","query":"up == 0","duration":60,"labels":{"a2":"b2","c2":"d2"},"annotations":{"ann1":"ann44","ann2":"ann33"},"alerts":[],"health":"health2","lastError":"1","evaluationTime":1.1,"lastEvaluation":"0001-01-01T00:00:00Z","type":"alerting"}],"interval":2442,"evaluationTime":2.1,"lastEvaluation":"0001-01-01T00:00:00Z","limit":0,"partialResponseStrategy":"ABORT"}]}`,
},
{
name: "one valid group, with 1 rule and alert each and second empty group.",
Expand Down
1 change: 1 addition & 0 deletions pkg/testutil/testpromcompatibility/api_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RuleGroup struct {
Interval float64 `json:"interval"`
EvaluationTime float64 `json:"evaluationTime"`
LastEvaluation time.Time `json:"lastEvaluation"`
Limit int `json:"limit"`

PartialResponseStrategy string `json:"partialResponseStrategy"`
}
Expand Down

0 comments on commit a42d4c4

Please sign in to comment.