Skip to content

Commit

Permalink
Test fix: TestImportFilterLogging improve assertions (#6589)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks authored Nov 29, 2023
1 parent 5c90fa7 commit 47cbbc8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions rest/importtest/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ func TestXattrImportFilterOptIn(t *testing.T) {
}

func TestImportFilterLogging(t *testing.T) {
importFilter := `function (doc) { console.error("Error"); return doc.type == "mobile"; }`
const errorMessage = `ImportFilterError`
importFilter := `function (doc) { console.error("` + errorMessage + `"); return doc.type == "mobile"; }`
rtConfig := rest.RestTesterConfig{
SyncFn: `function(doc, oldDoc) { channel(doc.channels) }`,
DatabaseConfig: &rest.DatabaseConfig{DbConfig: rest.DbConfig{
Expand All @@ -572,15 +573,17 @@ func TestImportFilterLogging(t *testing.T) {
assert.NoError(t, err)

// Attempt to get doc will trigger import
response := rt.SendAdminRequest("GET", "/db/"+key, "")
assert.Equal(t, http.StatusOK, response.Code)
base.AssertLogContains(t, errorMessage, func() {
response := rt.SendAdminRequest("GET", "/db/"+key, "")
assert.Equal(t, http.StatusOK, response.Code)
})

// Get number of errors after
numErrorsAfter, err := strconv.Atoi(base.SyncGatewayStats.GlobalStats.ResourceUtilizationStats().ErrorCount.String())
assert.NoError(t, err)

// Make sure an error was logged
assert.Equal(t, numErrors+1, numErrorsAfter)
// Make sure at least one error was logged
assert.GreaterOrEqual(t, numErrors+1, numErrorsAfter)

}

Expand Down

0 comments on commit 47cbbc8

Please sign in to comment.