Akash Soni | d36d23b | 2023-08-18 12:51:40 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 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 | |
| 16 | // Package vpagent Common Logger initialization |
| 17 | package vpagent |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
| 22 | "testing" |
| 23 | ) |
| 24 | |
| 25 | func Test_isConnCanceled(t *testing.T) { |
| 26 | type args struct { |
| 27 | err error |
| 28 | } |
| 29 | tests := []struct { |
| 30 | name string |
| 31 | args args |
| 32 | want bool |
| 33 | }{ |
| 34 | { |
| 35 | name: "isConnCanceled", |
| 36 | args: args{ |
| 37 | err: context.Canceled, |
| 38 | }, |
| 39 | want: true, |
| 40 | }, |
| 41 | { |
| 42 | name: "error_nil", |
| 43 | args: args{ |
| 44 | err: nil, |
| 45 | }, |
| 46 | want: false, |
| 47 | }, |
| 48 | { |
| 49 | name: "the client connection is closing", |
| 50 | args: args{ |
| 51 | err: errors.New("Not Found"), |
| 52 | }, |
| 53 | want: false, |
| 54 | }, |
| 55 | } |
| 56 | for _, tt := range tests { |
| 57 | t.Run(tt.name, func(t *testing.T) { |
| 58 | switch tt.name { |
| 59 | case "isConnCanceled": |
| 60 | if got := isConnCanceled(tt.args.err); got != tt.want { |
| 61 | t.Errorf("isConnCanceled() = %v, want %v", got, tt.want) |
| 62 | } |
| 63 | case "error_nil": |
| 64 | if got := isConnCanceled(tt.args.err); got != tt.want { |
| 65 | t.Errorf("isConnCanceled() = %v, want %v", got, tt.want) |
| 66 | } |
| 67 | case "the client connection is closing": |
| 68 | if got := isConnCanceled(tt.args.err); got != tt.want { |
| 69 | t.Errorf("isConnCanceled() = %v, want %v", got, tt.want) |
| 70 | } |
| 71 | } |
| 72 | }) |
| 73 | } |
| 74 | } |