Skip to content

Commit

Permalink
FAB-1311 errors unit test fails on z/p architectures
Browse files Browse the repository at this point in the history
Update test case to only test for presence of part of the stack trace.

Change-Id: Ica3e4752f20d61436986bb4397fd44207eb1366d
Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
  • Loading branch information
wlahti committed Dec 12, 2016
1 parent 3ef851e commit 37a662f
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions core/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package errors

import (
"fmt"
"strings"
"testing"

"github.com/hyperledger/fabric/flogging"
Expand Down Expand Up @@ -58,6 +59,27 @@ func TestErrorWithCallstackAndArg(t *testing.T) {
}
}

// TestErrorWithCallstackMessage tests the output for a logging error where
// and an invalid log level has been provided and the stack trace should be
// displayed with the error message
func TestErrorWithCallstackMessage(t *testing.T) {
// when the 'error' module is set to debug, the callstack will be appended
// to the error message
flogging.SetModuleLogLevel("error", "debug")

e := ErrorWithCallstack(Utility, UtilityUnknownError)
s := e.GetStack()
if s == "" {
t.Fatalf("No error stack was recorded.")
}

// check that the error message contains this part of the stack trace, which
// is non-platform specific
if !strings.Contains(e.Error(), "github.com/hyperledger/fabric/core/errors.TestErrorWithCallstackMessage") {
t.Fatalf("Error message does not have stack trace appended.")
}
}

func ExampleError() {
// when the 'error' module is set to anything but debug, the callstack will
// not be appended to the error message
Expand Down Expand Up @@ -133,44 +155,3 @@ func ExampleLoggingInvalidLogLevel() {
// Invalid log level provided - invalid
}
}

// ExampleLoggingInvalidLogLevel tests the output for a logging error where
// and an invalid log level has been provided and the stack trace should be
// displayed with the error message
func ExampleLoggingInvalidLogLevel_withCallstack() {
// when the 'error' module is set to debug, the callstack will be appended
// to the error message
flogging.SetModuleLogLevel("error", "debug")

err := ErrorWithCallstack(Logging, LoggingInvalidLogLevel, "invalid")

if err != nil {
fmt.Printf("%s", err.Error())
fmt.Printf("%s\n", err.GetErrorCode())
fmt.Printf("%s\n", err.GetComponentCode())
fmt.Printf("%s\n", err.GetReasonCode())
fmt.Printf("%s", err.Message())
fmt.Printf("%s\n", err.MessageIn("en"))
// Output:
// Invalid log level provided - invalid
// /opt/gopath/src/github.com/hyperledger/fabric/core/errors/errors_test.go:145 github.com/hyperledger/fabric/core/errors.ExampleLoggingInvalidLogLevel_withCallstack
// /opt/go/src/testing/example.go:115 testing.runExample
// /opt/go/src/testing/example.go:38 testing.RunExamples
// /opt/go/src/testing/testing.go:744 testing.(*M).Run
// github.com/hyperledger/fabric/core/errors/_test/_testmain.go:116 main.main
// /opt/go/src/runtime/proc.go:192 runtime.main
// /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit
// Logging-LoggingInvalidLogLevel
// Logging
// LoggingInvalidLogLevel
// Invalid log level provided - invalid
// /opt/gopath/src/github.com/hyperledger/fabric/core/errors/errors_test.go:145 github.com/hyperledger/fabric/core/errors.ExampleLoggingInvalidLogLevel_withCallstack
// /opt/go/src/testing/example.go:115 testing.runExample
// /opt/go/src/testing/example.go:38 testing.RunExamples
// /opt/go/src/testing/testing.go:744 testing.(*M).Run
// github.com/hyperledger/fabric/core/errors/_test/_testmain.go:116 main.main
// /opt/go/src/runtime/proc.go:192 runtime.main
// /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit
// Invalid log level provided - invalid
}
}

0 comments on commit 37a662f

Please sign in to comment.