mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-16 00:58:36 -05:00
The current code path for `CreatePostAsUser` tries to update the `LastViewedAt` for bots, which logs a warning message if the bot isn't actually in the channel. This pull request changes the semantics of bot posting to not update the bot's `LastViewedAt` timestamp, avoiding this log altogether. It matches the semantics of `from_webhook`, but notably makes bots slightly less like users in that they no longer "read" channels when they post. This seems reasonable, but I'm both looking for validation of this semantic change in addition to the code review. Fixes: https://mattermost.atlassian.net/browse/MM-23926 Co-authored-by: mattermod <mattermod@users.noreply.github.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package testlib
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"io"
|
|
"testing"
|
|
)
|
|
|
|
// AssertLog asserts that a JSON-encoded buffer of logs contains one with the given level and message.
|
|
func AssertLog(t *testing.T, logs *bytes.Buffer, level, message string) {
|
|
dec := json.NewDecoder(logs)
|
|
for {
|
|
var log struct {
|
|
Level string
|
|
Msg string
|
|
}
|
|
if err := dec.Decode(&log); err == io.EOF {
|
|
break
|
|
} else if err != nil {
|
|
continue
|
|
}
|
|
|
|
if log.Level == level && log.Msg == message {
|
|
return
|
|
}
|
|
}
|
|
|
|
t.Fatalf("failed to find %s log message: %s", level, message)
|
|
}
|
|
|
|
// AssertNoLog asserts that a JSON-encoded buffer of logs does not contains one with the given level and message.
|
|
func AssertNoLog(t *testing.T, logs *bytes.Buffer, level, message string) {
|
|
dec := json.NewDecoder(logs)
|
|
for {
|
|
var log struct {
|
|
Level string
|
|
Msg string
|
|
}
|
|
if err := dec.Decode(&log); err == io.EOF {
|
|
break
|
|
} else if err != nil {
|
|
continue
|
|
}
|
|
|
|
if log.Level == level && log.Msg == message {
|
|
t.Fatalf("found %s log message: %s", level, message)
|
|
return
|
|
}
|
|
}
|
|
}
|