53176dcb0e
if your server is built to make drpc connections, clients can still connect with grpc. thus, your responses to grpc clients must still look the same, so we have to have all of our status wrapping include codes for both the drpc and grpc servers to return the right thing. Change-Id: If99fa0e674dec2e20ddd372a827f1c01b4d305b2
48 lines
889 B
Go
48 lines
889 B
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package rpcstatus
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"google.golang.org/grpc/status"
|
|
|
|
"storj.io/drpc/drpcerr"
|
|
)
|
|
|
|
var allCodes = []StatusCode{
|
|
Unknown,
|
|
OK,
|
|
Canceled,
|
|
InvalidArgument,
|
|
DeadlineExceeded,
|
|
NotFound,
|
|
AlreadyExists,
|
|
PermissionDenied,
|
|
ResourceExhausted,
|
|
FailedPrecondition,
|
|
Aborted,
|
|
OutOfRange,
|
|
Unimplemented,
|
|
Internal,
|
|
Unavailable,
|
|
DataLoss,
|
|
Unauthenticated,
|
|
}
|
|
|
|
func TestStatus(t *testing.T) {
|
|
for _, code := range allCodes {
|
|
err := Error(code, "")
|
|
assert.Equal(t, Code(err), code)
|
|
assert.Equal(t, status.Code(err), code.toGRPC())
|
|
assert.Equal(t, drpcerr.Code(err), uint64(code))
|
|
}
|
|
|
|
assert.Equal(t, Code(nil), OK)
|
|
assert.Equal(t, Code(context.Canceled), Canceled)
|
|
assert.Equal(t, Code(context.DeadlineExceeded), DeadlineExceeded)
|
|
}
|