File: grpcstatus1.13%2B_test.go

package info (click to toggle)
golang-github-grpc-ecosystem-go-grpc-prometheus 1.2.0%2Bgit20191002.6af20e3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 264 kB
  • sloc: makefile: 34; sh: 11
file content (26 lines) | stat: -rw-r--r-- 610 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// +build go1.13

package grpcstatus

import (
	"fmt"
	"github.com/stretchr/testify/require"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"testing"
)

func TestNativeErrorUnwrapping(t *testing.T) {
	gRPCCode := codes.FailedPrecondition
	gRPCError := status.Errorf(gRPCCode, "Userspace error.")
	expectedGRPCStatus, _ := status.FromError(gRPCError)
	testedErrors := []error{
		fmt.Errorf("go native wrapped error: %w", gRPCError),
	}

	for _, e := range testedErrors {
		resultingStatus, ok := FromError(e)
		require.True(t, ok)
		require.Equal(t, expectedGRPCStatus, resultingStatus)
	}
}