Skip to content

Commit

Permalink
some fixes (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhii Zakharov authored Oct 1, 2020
1 parent ec936e8 commit eb9b4e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 13 additions & 1 deletion tests/helpers/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ func checkResponseHeaders(t testing.TB, expectedHeaders map[string]string, actua

// AssertReportResponsesEqual checks if reports in answer are the same
func AssertReportResponsesEqual(t testing.TB, expected, got []byte) {
AssertReportResponsesEqualCustomElementsChecker(t, expected, got, func(t testing.TB, expected []types.RuleOnReport, got []types.RuleOnReport) {
assert.ElementsMatch(t, expected, got)
})
}

// AssertReportResponsesEqualCustomElementsChecker checks if reports in answer are the same using custom checker
// for elements
func AssertReportResponsesEqualCustomElementsChecker(
t testing.TB, expected, got []byte, elementsChecker func(testing.TB, []types.RuleOnReport, []types.RuleOnReport),
) {
var expectedResponse, gotResponse struct {
Status string `json:"status"`
Report types.ReportResponse `json:"report"`
Expand Down Expand Up @@ -239,7 +249,9 @@ func AssertReportResponsesEqual(t testing.TB, expected, got []byte) {
len(gotResponse.Report.Report),
"length of reports should be equal",
)
assert.ElementsMatch(t, expectedResponse.Report.Report, gotResponse.Report.Report)
if elementsChecker != nil {
elementsChecker(t, expectedResponse.Report.Report, gotResponse.Report.Report)
}
}

// AssertRuleResponsesEqual checks if rules in answer are the same
Expand Down
12 changes: 7 additions & 5 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ type RuleID string

// RuleOnReport represents a single (hit) rule of the string encoded report
type RuleOnReport struct {
Module RuleID `json:"component"`
ErrorKey ErrorKey `json:"key"`
UserVote UserVote `json:"user_vote"`
Disabled bool `json:"disabled"`
TemplateData interface{} `json:"details"`
Module RuleID `json:"component"`
ErrorKey ErrorKey `json:"key"`
UserVote UserVote `json:"user_vote"`
Disabled bool `json:"disabled"`
DisableFeedback string `json:"disable_feedback"`
DisabledAt Timestamp `json:"disabled_at"`
TemplateData interface{} `json:"details"`
}

// ReportRules is a helper struct for easy JSON unmarshalling of string encoded report
Expand Down

0 comments on commit eb9b4e3

Please sign in to comment.