prysm-pulse/shared/testutil/log.go
Raul Jordan bc16fa9f50
Accounts V2: Derived Keymanager, Wallet & Account Creation (#6624)
* initialize derived wallet
* derived wallet + account creation
* initialize wallet seed
* encrypted seed file creation
* generate next acct
* create seed from pass
* properly creating derived accounts
* fix up formatting
* prep for review
* start tests for derived create account
* add derived test
* linter
* gaz
* derived keymanager create account test complete
* Merge branch 'master' into derived-keymanager
* tests pass
* gaz
* fix list test
* Merge refs/heads/master into derived-keymanager
* ivan feedback
* skip mnemonic confirm
* Merge branch 'derived-keymanager' of github.com:prysmaticlabs/prysm into derived-keymanager
* comment
* tidy
* fmt
* organize
* test interface conformity
* Update validator/accounts/v2/iface/wallet.go
* ivan comments
* Merge branch 'derived-keymanager' of github.com:prysmaticlabs/prysm into derived-keymanager
* Merge refs/heads/master into derived-keymanager
* Merge branch 'master' of github.com:prysmaticlabs/prysm into derived-keymanager
* Fix
* Fix test
* Merge refs/heads/master into derived-keymanager
* fix errs
* imports
* Gaz
2020-07-21 02:05:23 +00:00

52 lines
1.3 KiB
Go

// Package testutil defines common unit test utils such as asserting logs.
package testutil
import (
"strings"
"testing"
"github.com/sirupsen/logrus/hooks/test"
)
// AssertLogsContain checks that the desired string is a subset of the current log output.
// Set exitOnFail to true to immediately exit the test on failure
func AssertLogsContain(t *testing.T, hook *test.Hook, want string) {
assertLogs(t, hook, want, true)
}
// AssertLogsDoNotContain is the inverse check of AssertLogsContain
func AssertLogsDoNotContain(t *testing.T, hook *test.Hook, want string) {
assertLogs(t, hook, want, false)
}
func assertLogs(t *testing.T, hook *test.Hook, want string, flag bool) {
t.Logf("scanning for: %s", want)
entries := hook.AllEntries()
match := false
for _, e := range entries {
msg, err := e.String()
if err != nil {
t.Fatalf("Failed to format log entry to string: %v", err)
}
if strings.Contains(msg, want) {
match = true
}
for _, field := range e.Data {
fieldStr, ok := field.(string)
if !ok {
continue
}
if strings.Contains(fieldStr, want) {
match = true
}
}
t.Logf("log: %s", msg)
}
if flag && !match {
t.Fatalf("log not found: %s", want)
} else if !flag && match {
t.Fatalf("unwanted log found: %s", want)
}
}