mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
TestDisplayJSONMessagesStreamInvalidJSON: fix error check
As pointed out by govet, > pkg/jsonmessage/jsonmessage_test.go:231:94: nilness: nil dereference in dynamic method call (govet) > if err := DisplayJSONMessagesStream(reader, data, inFd, false, nil); err == nil && err.Error()[:17] != "invalid character" { > ^ The nil deref never happened as err was always non-nil, and so the check for error message text was not performed. Fix this, and while at it, refactor the code a bit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
365a63a573
commit
d8f2b47432
1 changed files with 3 additions and 2 deletions
|
@ -228,8 +228,9 @@ func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) {
|
|||
reader := strings.NewReader("This is not a 'valid' JSON []")
|
||||
inFd, _ = term.GetFdInfo(reader)
|
||||
|
||||
if err := DisplayJSONMessagesStream(reader, data, inFd, false, nil); err == nil && err.Error()[:17] != "invalid character" {
|
||||
t.Fatalf("Should have thrown an error (invalid character in ..), got %q", err)
|
||||
exp := "invalid character "
|
||||
if err := DisplayJSONMessagesStream(reader, data, inFd, false, nil); err == nil || !strings.HasPrefix(err.Error(), exp) {
|
||||
t.Fatalf("Expected error (%s...), got %q", exp, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue