Debian Codegraph @

api/v3rpc/rpctypes/error_test.go

raw symbols SCIP
1 // Copyright 2016 The etcd Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package rpctypes
16
17 import (
18 "testing"
19
20 "google.golang.org/grpc/codes"
21 "google.golang.org/grpc/status"
22 )
23
24 func TestConvert(t *testing.T) {
25 e1 := status.New(codes.InvalidArgument, "etcdserver: key is not provided").Err()
26 e2 := ErrGRPCEmptyKey
27 e3 := ErrEmptyKey
28
29 if e1.Error() != e2.Error() {
30 t.Fatalf("expected %q == %q", e1.Error(), e2.Error())
31 }
32 if ev1, ok := status.FromError(e1); ok && ev1.Code() != e3.(EtcdError).Code() {
33 t.Fatalf("expected them to be equal, got %v / %v", ev1.Code(), e3.(EtcdError).Code())
34 }
35
36 if e1.Error() == e3.Error() {
37 t.Fatalf("expected %q != %q", e1.Error(), e3.Error())
38 }
39 if ev2, ok := status.FromError(e2); ok && ev2.Code() != e3.(EtcdError).Code() {
40 t.Fatalf("expected them to be equal, got %v / %v", ev2.Code(), e3.(EtcdError).Code())
41 }
42 }