gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/tcpip/link/rawfile/errors_test.go (about) 1 // Copyright 2020 The gVisor 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 //go:build linux 16 // +build linux 17 18 package rawfile 19 20 import ( 21 "testing" 22 23 "github.com/google/go-cmp/cmp" 24 "golang.org/x/sys/unix" 25 "gvisor.dev/gvisor/pkg/tcpip" 26 ) 27 28 func TestTranslateErrno(t *testing.T) { 29 for _, test := range []struct { 30 errno unix.Errno 31 translated tcpip.Error 32 }{ 33 { 34 errno: unix.Errno(0), 35 translated: &tcpip.ErrInvalidEndpointState{}, 36 }, 37 { 38 errno: unix.Errno(maxErrno), 39 translated: &tcpip.ErrInvalidEndpointState{}, 40 }, 41 { 42 errno: unix.Errno(514), 43 translated: &tcpip.ErrInvalidEndpointState{}, 44 }, 45 { 46 errno: unix.EEXIST, 47 translated: &tcpip.ErrDuplicateAddress{}, 48 }, 49 } { 50 got := TranslateErrno(test.errno) 51 if diff := cmp.Diff(test.translated, got); diff != "" { 52 t.Errorf("unexpected result from TranslateErrno(%q), (-want, +got):\n%s", test.errno, diff) 53 } 54 } 55 }