mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 11:11:20 +00:00
f32f7ba36c
* move log helper to internal package * move log helper * Add readme Former-commit-id: cc9eaa1e87415c031841f367c30dc3b20cd54858 [formerly 60a22abaff65803fbad00a089f842e6e23e9ec9f] Former-commit-id: 62769aedb094e51fb87757d174b7c6fc77464f96
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
)
|
|
|
|
var _ = log.Handler(&LogHandler{})
|
|
|
|
// LogHandler provides methods for testing ethereum logs.
|
|
type LogHandler struct {
|
|
records []*log.Record
|
|
t *testing.T
|
|
}
|
|
|
|
func NewLogHandler(t *testing.T) *LogHandler {
|
|
return &LogHandler{t: t}
|
|
}
|
|
|
|
// Log adds records to the record slice.
|
|
func (t *LogHandler) Log(r *log.Record) error {
|
|
t.records = append(t.records, r)
|
|
return nil
|
|
}
|
|
|
|
// Pop the record at index 0.
|
|
func (t *LogHandler) Pop() *log.Record {
|
|
var r *log.Record
|
|
r, t.records = t.records[0], t.records[1:]
|
|
return r
|
|
}
|
|
|
|
// Length of the records slice.
|
|
func (t *LogHandler) Len() int {
|
|
return len(t.records)
|
|
}
|
|
|
|
// VerifyLogMsg verfies that the log at index 0 matches the string exactly.
|
|
// This method removes the verified message from the slice.
|
|
func (h *LogHandler) VerifyLogMsg(str string) {
|
|
if h.Len() == 0 {
|
|
h.t.Error("Expected a log, but there were none!")
|
|
}
|
|
if l := h.Pop(); l.Msg != str {
|
|
h.t.Errorf("Unexpected log: %v. Wanted: %s", l, str)
|
|
}
|
|
}
|