github.com/gogf/gf@v1.16.9/debug/gdebug/gdebug_testdata.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gdebug 8 9 import ( 10 "io/ioutil" 11 "path/filepath" 12 ) 13 14 // TestDataPath retrieves and returns the testdata path of current package, 15 // which is used for unit testing cases only. 16 // The optional parameter `names` specifies the sub-folders/sub-files, 17 // which will be joined with current system separator and returned with the path. 18 func TestDataPath(names ...string) string { 19 path := CallerDirectory() + string(filepath.Separator) + "testdata" 20 for _, name := range names { 21 path += string(filepath.Separator) + name 22 } 23 return path 24 } 25 26 // TestDataContent retrieves and returns the file content for specified testdata path of current package 27 func TestDataContent(names ...string) string { 28 path := TestDataPath(names...) 29 if path != "" { 30 data, err := ioutil.ReadFile(path) 31 if err == nil { 32 return string(data) 33 } 34 } 35 return "" 36 }