mattermost/testlib/assertions.go
Jesse Hallam f149ada16a
MM-23261 plugin stderr debug logs (#14166)
* 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
2020-03-30 15:00:45 -03:00

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)
}