mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
* explicitly assert panic as error log
* Revert "[MM-18150] plugin panic trace should not be lost (#13559)"
This reverts commit 5d928b4f94, while leaving the unit tests intact
and now asserting debug logs instead.
* missing license header
33 lines
682 B
Go
33 lines
682 B
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)
|
|
}
|