Skip to content

Commit

Permalink
Merge pull request #760 from nyaruka/clog_attached_fix
Browse files Browse the repository at this point in the history
Fix unnecessarily writing send channel logs to the database
  • Loading branch information
rowanseymour authored Jul 23, 2024
2 parents 2e65d7e + 5278572 commit 205b3a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions channel_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func newChannelLog(t ChannelLogType, ch Channel, r *httpx.Recorder, attached boo
channel: ch,
recorder: r,
createdOn: dates.Now(),

redactor: stringsx.NewRedactor("**********", redactVals...),
attached: attached,
redactor: stringsx.NewRedactor("**********", redactVals...),
}
}

Expand Down
12 changes: 11 additions & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ func TestIncoming(t *testing.T) {
body, _ := io.ReadAll(resp.Body)
assert.Contains(t, string(body), "missing from or text")

assert.Len(t, mb.WrittenChannelLogs(), 1)
clog := mb.WrittenChannelLogs()[0]
assert.False(t, clog.Attached())
assert.Len(t, clog.HTTPLogs(), 1)

req, _ := http.NewRequest("GET", "http://localhost:8081/c/mck/e4bb1578-29da-4fa5-a214-9da19dd24230/receive?from=2065551212&text=hello", nil)
req.Header.Set("Cookie", "secret")
resp, err = http.DefaultClient.Do(req)
Expand All @@ -102,6 +107,11 @@ func TestIncoming(t *testing.T) {
defer resp.Body.Close()
body, _ = io.ReadAll(resp.Body)
assert.Contains(t, string(body), "ok")

assert.Len(t, mb.WrittenChannelLogs(), 2)
clog = mb.WrittenChannelLogs()[1]
assert.True(t, clog.Attached())
assert.Len(t, clog.HTTPLogs(), 1)
}

func TestOutgoing(t *testing.T) {
Expand Down Expand Up @@ -153,7 +163,7 @@ func TestOutgoing(t *testing.T) {
assert.Len(t, mb.WrittenChannelLogs(), 1)
clog := mb.WrittenChannelLogs()[0]
assert.Equal(t, []*courier.ChannelError{courier.NewChannelError("seeds", "", "contains ********** seeds")}, clog.Errors())

assert.True(t, clog.Attached())
assert.Len(t, clog.HTTPLogs(), 1)

hlog := clog.HTTPLogs()[0]
Expand Down

0 comments on commit 205b3a3

Please sign in to comment.