update unit test cases for gfile

This commit is contained in:
John
2019-07-27 11:41:12 +08:00
parent 538b282f43
commit 5a23459b23
2 changed files with 20 additions and 33 deletions

View File

@ -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)
})

View File

@ -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() {