mirror of
https://gitee.com/johng/gf
synced 2026-07-06 13:42:46 +08:00
update unit test cases for gfile
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
)
|
||||
|
||||
func Test_Scan(t *testing.T) {
|
||||
func Test_ScanDir(t *testing.T) {
|
||||
teatPath := gfile.Dir(gfile.SourcePath()) + gfile.Separator + "testdata"
|
||||
gtest.Case(t, func() {
|
||||
files, err := gfile.ScanDir(teatPath, "*", false)
|
||||
@ -20,8 +20,25 @@ func Test_Scan(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
files, err := gfile.ScanDir(teatPath, "*", true)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNE(teatPath+gfile.Separator+"dir1", files)
|
||||
gtest.AssertNE(teatPath+gfile.Separator+"dir2", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir1", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir2", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ScanDirFile(t *testing.T) {
|
||||
teatPath := gfile.Dir(gfile.SourcePath()) + gfile.Separator + "testdata"
|
||||
gtest.Case(t, func() {
|
||||
files, err := gfile.ScanDirFile(teatPath, "*", false)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(len(files), 0)
|
||||
})
|
||||
gtest.Case(t, func() {
|
||||
files, err := gfile.ScanDirFile(teatPath, "*", true)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNI(teatPath+gfile.Separator+"dir1", files)
|
||||
gtest.AssertNI(teatPath+gfile.Separator+"dir2", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
|
||||
gtest.AssertIN(teatPath+gfile.Separator+"dir2"+gfile.Separator+"file2", files)
|
||||
})
|
||||
|
||||
@ -474,36 +474,6 @@ func Test_Chmod(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ScanDir(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "/testfiledirs"
|
||||
files []string
|
||||
err error
|
||||
)
|
||||
|
||||
createDir(paths1)
|
||||
createTestFile(paths1+"/t1.txt", "")
|
||||
createTestFile(paths1+"/t2.txt", "")
|
||||
defer delTestFiles(paths1)
|
||||
|
||||
files, err = gfile.ScanDir(testpath()+paths1, "t*")
|
||||
|
||||
result := []string{
|
||||
testpath() + paths1 + "/t1.txt",
|
||||
testpath() + paths1 + "/t2.txt",
|
||||
}
|
||||
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
gtest.Assert(formatpaths(files), formatpaths(result))
|
||||
|
||||
_, err = gfile.ScanDir("", "t*")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// 获取绝对目录地址
|
||||
func Test_RealPath(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
|
||||
Reference in New Issue
Block a user