github.com/avfs/avfs@v0.33.1-0.20240303173310-c6ba67c33eb7/test/test_types.go (about) 1 // 2 // Copyright 2023 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 package test 18 19 import ( 20 "github.com/avfs/avfs" 21 ) 22 23 const ( 24 defaultDir = "defaultDir" 25 defaultFile = "defaultFile" 26 defaultNonExisting = "defaultNonExisting" 27 ) 28 29 // Suite is a test suite for virtual file systems and identity managers. 30 type Suite struct { 31 vfsSetup avfs.VFSBase // vfsSetup is the file system used to set up the tests (generally with read/write access). 32 vfsTest avfs.VFSBase // vfsTest is the file system used to run the tests. 33 idm avfs.IdentityMgr // idm is the identity manager to be tested. 34 initUser avfs.UserReader // initUser is the initial user running the test suite. 35 groups []avfs.GroupReader // groups contains the test groups created with the identity manager. 36 users []avfs.UserReader // users contains the test users created with the identity manager. 37 testDataDir string // testDataDir is the testdata directory of the test suite. 38 rootDir string // rootDir is the root directory for tests and benchmarks. 39 maxRace int // maxRace is the maximum number of concurrent goroutines used in race tests. 40 canTestPerm bool // canTestPerm indicates if permissions can be tested. 41 } 42 43 // PermTests regroups all tests for a specific function. 44 type PermTests struct { 45 ts *Suite // ts is a test suite for virtual file systems. 46 errors map[string]*permError // errors store the errors for each "User/Permission" combination. 47 errFileName string // errFileName is the json file storing the test results from Ots. 48 permDir string // permDir is the root directory of the test environment. 49 options PermOptions // PermOptions are options for running the tests. 50 errFileExists bool // errFileExists indicates if errFileName exits. 51 } 52 53 // PermOptions are options for running the tests. 54 type PermOptions struct { 55 IgnoreOp bool // IgnoreOp ignores the Op field comparison of fs.PathError or os.LinkError structs. 56 IgnorePath bool // IgnorePath ignores the Path, Old or New field comparison of fs.PathError or os.LinkError errors. 57 CreateFiles bool // CreateFiles creates files instead of directories. 58 } 59 60 // errType defines the error type. 61 type errType string 62 63 const ( 64 LinkError errType = "LinkError" 65 PathError errType = "PathError" 66 StringError errType = "StringError" 67 ) 68 69 // permError is the error returned by each test, to be stored as json. 70 type permError struct { 71 ErrType errType `json:"errType,omitempty"` 72 ErrOp string `json:"errOp,omitempty"` 73 ErrPath string `json:"errPath,omitempty"` 74 ErrOld string `json:"errOld,omitempty"` 75 ErrNew string `json:"errNew,omitempty"` 76 ErrErr string `json:"errErr,omitempty"` 77 }