mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
42
vendor/google.golang.org/grpc/status/go16.go
generated
vendored
Normal file
42
vendor/google.golang.org/grpc/status/go16.go
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// +build go1.6,!go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package status
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
// FromContextError converts a context error into a Status. It returns a
|
||||
// Status with codes.OK if err is nil, or a Status with codes.Unknown if err is
|
||||
// non-nil and not a context error.
|
||||
func FromContextError(err error) *Status {
|
||||
switch err {
|
||||
case nil:
|
||||
return New(codes.OK, "")
|
||||
case context.DeadlineExceeded:
|
||||
return New(codes.DeadlineExceeded, err.Error())
|
||||
case context.Canceled:
|
||||
return New(codes.Canceled, err.Error())
|
||||
default:
|
||||
return New(codes.Unknown, err.Error())
|
||||
}
|
||||
}
|
44
vendor/google.golang.org/grpc/status/go17.go
generated
vendored
Normal file
44
vendor/google.golang.org/grpc/status/go17.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
// +build go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package status
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
netctx "golang.org/x/net/context"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
// FromContextError converts a context error into a Status. It returns a
|
||||
// Status with codes.OK if err is nil, or a Status with codes.Unknown if err is
|
||||
// non-nil and not a context error.
|
||||
func FromContextError(err error) *Status {
|
||||
switch err {
|
||||
case nil:
|
||||
return New(codes.OK, "")
|
||||
case context.DeadlineExceeded, netctx.DeadlineExceeded:
|
||||
return New(codes.DeadlineExceeded, err.Error())
|
||||
case context.Canceled, netctx.Canceled:
|
||||
return New(codes.Canceled, err.Error())
|
||||
default:
|
||||
return New(codes.Unknown, err.Error())
|
||||
}
|
||||
}
|
44
vendor/google.golang.org/grpc/status/go17_test.go
generated
vendored
Normal file
44
vendor/google.golang.org/grpc/status/go17_test.go
generated
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
// +build go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package status
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
||||
func TestFromStdContextError(t *testing.T) {
|
||||
testCases := []struct {
|
||||
in error
|
||||
want *Status
|
||||
}{
|
||||
{in: context.DeadlineExceeded, want: New(codes.DeadlineExceeded, context.DeadlineExceeded.Error())},
|
||||
{in: context.Canceled, want: New(codes.Canceled, context.Canceled.Error())},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
got := FromContextError(tc.in)
|
||||
if got.Code() != tc.want.Code() || got.Message() != tc.want.Message() {
|
||||
t.Errorf("FromContextError(%v) = %v; want %v", tc.in, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
14
vendor/google.golang.org/grpc/status/status.go
generated
vendored
14
vendor/google.golang.org/grpc/status/status.go
generated
vendored
@ -46,7 +46,7 @@ func (se *statusError) Error() string {
|
||||
return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(p.GetCode()), p.GetMessage())
|
||||
}
|
||||
|
||||
func (se *statusError) status() *Status {
|
||||
func (se *statusError) GRPCStatus() *Status {
|
||||
return &Status{s: (*spb.Status)(se)}
|
||||
}
|
||||
|
||||
@ -120,14 +120,14 @@ func FromProto(s *spb.Status) *Status {
|
||||
}
|
||||
|
||||
// FromError returns a Status representing err if it was produced from this
|
||||
// package. Otherwise, ok is false and a Status is returned with codes.Unknown
|
||||
// and the original error message.
|
||||
// package or has a method `GRPCStatus() *Status`. Otherwise, ok is false and a
|
||||
// Status is returned with codes.Unknown and the original error message.
|
||||
func FromError(err error) (s *Status, ok bool) {
|
||||
if err == nil {
|
||||
return &Status{s: &spb.Status{Code: int32(codes.OK)}}, true
|
||||
}
|
||||
if se, ok := err.(*statusError); ok {
|
||||
return se.status(), true
|
||||
if se, ok := err.(interface{ GRPCStatus() *Status }); ok {
|
||||
return se.GRPCStatus(), true
|
||||
}
|
||||
return New(codes.Unknown, err.Error()), false
|
||||
}
|
||||
@ -182,8 +182,8 @@ func Code(err error) codes.Code {
|
||||
if err == nil {
|
||||
return codes.OK
|
||||
}
|
||||
if se, ok := err.(*statusError); ok {
|
||||
return se.status().Code()
|
||||
if se, ok := err.(interface{ GRPCStatus() *Status }); ok {
|
||||
return se.GRPCStatus().Code()
|
||||
}
|
||||
return codes.Unknown
|
||||
}
|
||||
|
60
vendor/google.golang.org/grpc/status/status_test.go
generated
vendored
60
vendor/google.golang.org/grpc/status/status_test.go
generated
vendored
@ -28,6 +28,7 @@ import (
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
apb "github.com/golang/protobuf/ptypes/any"
|
||||
dpb "github.com/golang/protobuf/ptypes/duration"
|
||||
"golang.org/x/net/context"
|
||||
cpb "google.golang.org/genproto/googleapis/rpc/code"
|
||||
epb "google.golang.org/genproto/googleapis/rpc/errdetails"
|
||||
spb "google.golang.org/genproto/googleapis/rpc/status"
|
||||
@ -119,6 +120,47 @@ func TestFromErrorOK(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type customError struct {
|
||||
Code codes.Code
|
||||
Message string
|
||||
Details []*apb.Any
|
||||
}
|
||||
|
||||
func (c customError) Error() string {
|
||||
return fmt.Sprintf("rpc error: code = %s desc = %s", c.Code, c.Message)
|
||||
}
|
||||
|
||||
func (c customError) GRPCStatus() *Status {
|
||||
return &Status{
|
||||
s: &spb.Status{
|
||||
Code: int32(c.Code),
|
||||
Message: c.Message,
|
||||
Details: c.Details,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromErrorImplementsInterface(t *testing.T) {
|
||||
code, message := codes.Internal, "test description"
|
||||
details := []*apb.Any{{
|
||||
TypeUrl: "testUrl",
|
||||
Value: []byte("testValue"),
|
||||
}}
|
||||
err := customError{
|
||||
Code: code,
|
||||
Message: message,
|
||||
Details: details,
|
||||
}
|
||||
s, ok := FromError(err)
|
||||
if !ok || s.Code() != code || s.Message() != message || s.Err() == nil {
|
||||
t.Fatalf("FromError(%v) = %v, %v; want <Code()=%s, Message()=%q, Err()!=nil>, true", err, s, ok, code, message)
|
||||
}
|
||||
pd := s.Proto().GetDetails()
|
||||
if len(pd) != 1 || !reflect.DeepEqual(pd[0], details[0]) {
|
||||
t.Fatalf("s.Proto.GetDetails() = %v; want <Details()=%s>", pd, details)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromErrorUnknownError(t *testing.T) {
|
||||
code, message := codes.Unknown, "unknown error"
|
||||
err := errors.New("unknown error")
|
||||
@ -286,3 +328,21 @@ func mustMarshalAny(msg proto.Message) *apb.Any {
|
||||
}
|
||||
return any
|
||||
}
|
||||
|
||||
func TestFromContextError(t *testing.T) {
|
||||
testCases := []struct {
|
||||
in error
|
||||
want *Status
|
||||
}{
|
||||
{in: nil, want: New(codes.OK, "")},
|
||||
{in: context.DeadlineExceeded, want: New(codes.DeadlineExceeded, context.DeadlineExceeded.Error())},
|
||||
{in: context.Canceled, want: New(codes.Canceled, context.Canceled.Error())},
|
||||
{in: errors.New("other"), want: New(codes.Unknown, "other")},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
got := FromContextError(tc.in)
|
||||
if got.Code() != tc.want.Code() || got.Message() != tc.want.Message() {
|
||||
t.Errorf("FromContextError(%v) = %v; want %v", tc.in, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user