From 5a23459b23119d7e3fd7613cc0af3c3bfc16dad2 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 27 Jul 2019 11:41:12 +0800 Subject: [PATCH] update unit test cases for gfile --- g/os/gfile/gfile_z_scan_test.go | 23 ++++++++++++++++++++--- g/os/gfile/gfile_z_test.go | 30 ------------------------------ 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/g/os/gfile/gfile_z_scan_test.go b/g/os/gfile/gfile_z_scan_test.go index 119ac6614..0ca2c80b8 100644 --- a/g/os/gfile/gfile_z_scan_test.go +++ b/g/os/gfile/gfile_z_scan_test.go @@ -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) }) diff --git a/g/os/gfile/gfile_z_test.go b/g/os/gfile/gfile_z_test.go index 57fe1862e..63b12fa44 100644 --- a/g/os/gfile/gfile_z_test.go +++ b/g/os/gfile/gfile_z_test.go @@ -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() {