Skip to content

Commit

Permalink
Fix regression on journal filter results being serialized to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed Jul 15, 2020
1 parent c6f4ddc commit 9a0eee5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/journal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ func (this *Journal) GetEntries(offset int, limit int, from *time.Time, to *time
}

func (this *Journal) GetFilteredEntries(journalEntryFilterView v2.JournalEntryFilterView) ([]v2.JournalEntryView, error) {
var filteredEntries []v2.JournalEntryView
// init an empty slice to prevent serializing to a null value
filteredEntries := []v2.JournalEntryView{}
if this.EntryLimit == 0 {

return filteredEntries, fmt.Errorf("Journal disabled")
}

Expand Down
29 changes: 29 additions & 0 deletions core/journal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,35 @@ func Test_Journal_GetEntries_FilteredByTimeWindow(t *testing.T) {
Expect(entries[2].TimeStarted).To(Equal("2018-02-01T02:00:03.000Z"))
}

func Test_Journal_GetFilteredEntries_WillReturnEmptySliceIfNoJournalFound(t *testing.T) {
RegisterTestingT(t)

unit := journal.NewJournal()

request, _ := http.NewRequest("GET", "http://hoverfly.io/path/one?one=1&two=2", bytes.NewBufferString(`{"meta:{"field": "value"}}`))
request.Header.Add("Accept", "application/json")

unit.NewEntry(request, &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewBufferString("test body")),
}, "test-mode", time.Now())

// Body
entries, err := unit.GetFilteredEntries(v2.JournalEntryFilterView{
Request: &v2.RequestMatcherViewV5{
Body: []v2.MatcherViewV5{
{
Matcher: matchers.Exact,
Value: `{"meta:{"field": "other-value"}}`,
},
},
},
})
Expect(err).To(BeNil())
Expect(entries).ToNot(BeNil())
Expect(entries).To(HaveLen(0))
}

func Test_Journal_GetFilteredEntries_WillFilterOnRequestFields(t *testing.T) {
RegisterTestingT(t)

Expand Down

0 comments on commit 9a0eee5

Please sign in to comment.