1- package statz_test
1+ package statz
22
33import (
44 "context"
5+ "errors"
56 "io"
67 "testing"
78
89 "google.golang.org/genproto/googleapis/rpc/errdetails"
910 "google.golang.org/grpc/codes"
11+ "google.golang.org/grpc/status"
1012
1113 errorz "github.com/kunitsucom/util.go/errors"
12- statz "github.com/kunitsucom/util.go/grpc/status"
1314)
1415
1516func TestNew (t * testing.T ) {
@@ -20,9 +21,21 @@ func TestNew(t *testing.T) {
2021
2122 ctx := context .Background ()
2223 before := errorz .Errorf ("err: %w" , io .ErrUnexpectedEOF )
23- err := statz . New (ctx , statz . ErrorLevel , codes .Internal , "my error message" , before , statz . WithDetails (& errdetails.DebugInfo {StackEntries : []string {"stack1" , "stack2" }}), statz . WithDetails (nil ), statz . WithLogger (statz . DefaultLogger ))
24+ err := New (ctx , ErrorLevel , codes .Internal , "my error message" , before , WithDetails (& errdetails.DebugInfo {StackEntries : []string {"stack1" , "stack2" }}), WithDetails (nil ), WithLogger (DefaultLogger ))
2425 t .Logf ("🪲: [%%v]:\n %v" , err )
2526 t .Logf ("🪲: [%%+v]:\n %+v" , err )
26- _ = statz .New (ctx , statz .ErrorLevel , codes .Internal , "my error message" , before , statz .WithLogger (statz .DiscardLogger ))
27+
28+ var e * statusError
29+ if ! errors .As (err , & e ) {
30+ t .Errorf ("❌: something wrong" )
31+ }
32+ e .error = io .ErrUnexpectedEOF
33+ t .Logf ("🪲: [%%v]:\n %v" , e )
34+
35+ s , ok := New (ctx , ErrorLevel , codes .Internal , "my error message" , io .ErrUnexpectedEOF , WithLogger (DiscardLogger )).(interface { GRPCStatus () * status.Status }) //nolint:errorlint
36+ if ! ok {
37+ t .Errorf ("❌: New: not implement interface{ GRPCStatus() *status.Status }" )
38+ }
39+ t .Logf ("🪲: [%%v]:\n %v" , s .GRPCStatus ())
2740 })
2841}
0 commit comments