Skip to content

Commit 37a662f

Browse files
committed
FAB-1311 errors unit test fails on z/p architectures
Update test case to only test for presence of part of the stack trace. Change-Id: Ica3e4752f20d61436986bb4397fd44207eb1366d Signed-off-by: Will Lahti <[email protected]>
1 parent 3ef851e commit 37a662f

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

core/errors/errors_test.go

+22-41
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package errors
1818

1919
import (
2020
"fmt"
21+
"strings"
2122
"testing"
2223

2324
"github.com/hyperledger/fabric/flogging"
@@ -58,6 +59,27 @@ func TestErrorWithCallstackAndArg(t *testing.T) {
5859
}
5960
}
6061

62+
// TestErrorWithCallstackMessage tests the output for a logging error where
63+
// and an invalid log level has been provided and the stack trace should be
64+
// displayed with the error message
65+
func TestErrorWithCallstackMessage(t *testing.T) {
66+
// when the 'error' module is set to debug, the callstack will be appended
67+
// to the error message
68+
flogging.SetModuleLogLevel("error", "debug")
69+
70+
e := ErrorWithCallstack(Utility, UtilityUnknownError)
71+
s := e.GetStack()
72+
if s == "" {
73+
t.Fatalf("No error stack was recorded.")
74+
}
75+
76+
// check that the error message contains this part of the stack trace, which
77+
// is non-platform specific
78+
if !strings.Contains(e.Error(), "github.com/hyperledger/fabric/core/errors.TestErrorWithCallstackMessage") {
79+
t.Fatalf("Error message does not have stack trace appended.")
80+
}
81+
}
82+
6183
func ExampleError() {
6284
// when the 'error' module is set to anything but debug, the callstack will
6385
// not be appended to the error message
@@ -133,44 +155,3 @@ func ExampleLoggingInvalidLogLevel() {
133155
// Invalid log level provided - invalid
134156
}
135157
}
136-
137-
// ExampleLoggingInvalidLogLevel tests the output for a logging error where
138-
// and an invalid log level has been provided and the stack trace should be
139-
// displayed with the error message
140-
func ExampleLoggingInvalidLogLevel_withCallstack() {
141-
// when the 'error' module is set to debug, the callstack will be appended
142-
// to the error message
143-
flogging.SetModuleLogLevel("error", "debug")
144-
145-
err := ErrorWithCallstack(Logging, LoggingInvalidLogLevel, "invalid")
146-
147-
if err != nil {
148-
fmt.Printf("%s", err.Error())
149-
fmt.Printf("%s\n", err.GetErrorCode())
150-
fmt.Printf("%s\n", err.GetComponentCode())
151-
fmt.Printf("%s\n", err.GetReasonCode())
152-
fmt.Printf("%s", err.Message())
153-
fmt.Printf("%s\n", err.MessageIn("en"))
154-
// Output:
155-
// Invalid log level provided - invalid
156-
// /opt/gopath/src/github.com/hyperledger/fabric/core/errors/errors_test.go:145 github.com/hyperledger/fabric/core/errors.ExampleLoggingInvalidLogLevel_withCallstack
157-
// /opt/go/src/testing/example.go:115 testing.runExample
158-
// /opt/go/src/testing/example.go:38 testing.RunExamples
159-
// /opt/go/src/testing/testing.go:744 testing.(*M).Run
160-
// github.com/hyperledger/fabric/core/errors/_test/_testmain.go:116 main.main
161-
// /opt/go/src/runtime/proc.go:192 runtime.main
162-
// /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit
163-
// Logging-LoggingInvalidLogLevel
164-
// Logging
165-
// LoggingInvalidLogLevel
166-
// Invalid log level provided - invalid
167-
// /opt/gopath/src/github.com/hyperledger/fabric/core/errors/errors_test.go:145 github.com/hyperledger/fabric/core/errors.ExampleLoggingInvalidLogLevel_withCallstack
168-
// /opt/go/src/testing/example.go:115 testing.runExample
169-
// /opt/go/src/testing/example.go:38 testing.RunExamples
170-
// /opt/go/src/testing/testing.go:744 testing.(*M).Run
171-
// github.com/hyperledger/fabric/core/errors/_test/_testmain.go:116 main.main
172-
// /opt/go/src/runtime/proc.go:192 runtime.main
173-
// /opt/go/src/runtime/asm_amd64.s:2087 runtime.goexit
174-
// Invalid log level provided - invalid
175-
}
176-
}

0 commit comments

Comments
 (0)