google.golang.org/grpc@v1.72.2/internal/transport/grpchttp2/errors_test.go (about) 1 /* 2 * 3 * Copyright 2024 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package grpchttp2 20 21 import ( 22 "testing" 23 24 "google.golang.org/grpc/internal/grpctest" 25 ) 26 27 type s struct { 28 grpctest.Tester 29 } 30 31 func Test(t *testing.T) { 32 grpctest.RunSubTests(t, s{}) 33 } 34 35 func (s) TestErrorCodeString(t *testing.T) { 36 tests := []struct { 37 err ErrCode 38 want string 39 }{ 40 // Known error cases 41 {err: ErrCodeNoError, want: "NO_ERROR"}, 42 {err: ErrCodeProtocol, want: "PROTOCOL_ERROR"}, 43 {err: ErrCodeInternal, want: "INTERNAL_ERROR"}, 44 {err: ErrCodeFlowControl, want: "FLOW_CONTROL_ERROR"}, 45 {err: ErrCodeSettingsTimeout, want: "SETTINGS_TIMEOUT"}, 46 {err: ErrCodeStreamClosed, want: "STREAM_CLOSED"}, 47 {err: ErrCodeFrameSize, want: "FRAME_SIZE_ERROR"}, 48 {err: ErrCodeRefusedStream, want: "REFUSED_STREAM"}, 49 {err: ErrCodeCancel, want: "CANCEL"}, 50 {err: ErrCodeCompression, want: "COMPRESSION_ERROR"}, 51 {err: ErrCodeConnect, want: "CONNECT_ERROR"}, 52 {err: ErrCodeEnhanceYourCalm, want: "ENHANCE_YOUR_CALM"}, 53 {err: ErrCodeInadequateSecurity, want: "INADEQUATE_SECURITY"}, 54 {err: ErrCodeHTTP11Required, want: "HTTP_1_1_REQUIRED"}, 55 // Type casting known error case 56 {err: ErrCode(0x1), want: "PROTOCOL_ERROR"}, 57 // Unknown error case 58 {err: ErrCode(0xf), want: "unknown error code 0xf"}, 59 } 60 61 for _, test := range tests { 62 got := test.err.String() 63 if got != test.want { 64 t.Errorf("ErrCode.String(%#x) = %q, want %q", int(test.err), got, test.want) 65 } 66 } 67 }