github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/errors_test.go (about) 1 // 2 // Copyright 2020 The AVFS authors 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 //go:build !avfs_race 18 19 package avfs_test 20 21 import ( 22 "reflect" 23 "strconv" 24 "testing" 25 26 "github.com/avfs/avfs" 27 ) 28 29 func TestErrors(t *testing.T) { 30 groupName := "groupName" 31 aegErr := avfs.AlreadyExistsGroupError(groupName) 32 33 wantErrStr := "group: group " + groupName + " already exists" 34 if aegErr.Error() != wantErrStr { 35 t.Errorf("AlreadyExistsGroupError : want error to be %s, got %s", wantErrStr, aegErr.Error()) 36 } 37 38 userName := "userName" 39 wantErrStr = "user: user " + userName + " already exists" 40 41 aeuErr := avfs.AlreadyExistsUserError(userName) 42 if aeuErr.Error() != wantErrStr { 43 t.Errorf("AlreadyExistsUserError : want error to be %s, got %s", wantErrStr, aeuErr.Error()) 44 } 45 46 errStr := "whatever error" 47 uErr := avfs.UnknownError(errStr) 48 49 wantErrStr = "unknown error " + reflect.TypeOf(uErr).String() + " : '" + errStr + "'" 50 if uErr.Error() != wantErrStr { 51 t.Errorf("UnknownError : want error to be %s, got %s", wantErrStr, uErr.Error()) 52 } 53 54 wantErrStr = "group: unknown group " + groupName 55 56 ugErr := avfs.UnknownGroupError(groupName) 57 if ugErr.Error() != wantErrStr { 58 t.Errorf("UnknownGroupError : want error to be %s, got %s", wantErrStr, ugErr.Error()) 59 } 60 61 gid := -1 62 wantErrStr = "group: unknown groupid " + strconv.Itoa(gid) 63 64 ugiErr := avfs.UnknownGroupIdError(gid) 65 if ugiErr.Error() != wantErrStr { 66 t.Errorf("UnknownGroupIdError : want error to be %s, got %s", wantErrStr, ugiErr.Error()) 67 } 68 69 wantErrStr = "user: unknown user " + userName 70 71 uuErr := avfs.UnknownUserError(userName) 72 if uuErr.Error() != wantErrStr { 73 t.Errorf("UnknownUserError : want error to be %s, got %s", wantErrStr, uuErr.Error()) 74 } 75 76 uid := -1 77 wantErrStr = "user: unknown userid " + strconv.Itoa(uid) 78 79 uuiErr := avfs.UnknownUserIdError(uid) 80 if uuiErr.Error() != wantErrStr { 81 t.Errorf("UnknownUserIdError : want error to be %s, got %s", wantErrStr, uuiErr.Error()) 82 } 83 }