Improving gfile Code Coverage

This commit is contained in:
huangqian
2022-02-28 22:57:53 +08:00
parent 436931b560
commit eb533f3344
5 changed files with 30 additions and 4 deletions

View File

@ -340,14 +340,17 @@ func ExampleIsReadable() {
func ExampleIsWritable() {
// init
var (
path = gfile.Pwd() + gfile.Separator + "testdata/readline/file.log"
path = gfile.Pwd() + gfile.Separator + "testdata/readline/"
file = "file.log"
)
// Checks whether given `path` is writable.
fmt.Println(gfile.IsWritable(path))
fmt.Println(gfile.IsWritable(path + file))
// Output:
// true
// true
}
func ExampleChmod() {

View File

@ -323,7 +323,7 @@ func Test_Home(t *testing.T) {
err error
)
reads, err = gfile.Home()
reads, err = gfile.Home("a", "b")
t.Assert(err, nil)
t.AssertNE(reads, "")
})

View File

@ -28,7 +28,8 @@ func Test_Copy(t *testing.T) {
defer delTestFiles(topath)
t.Assert(gfile.IsFile(testpath()+topath), true)
t.AssertNE(gfile.Copy("", ""), nil)
t.AssertNE(gfile.Copy(paths, ""), nil)
t.AssertNE(gfile.Copy("", topath), nil)
})
}
@ -46,7 +47,8 @@ func Test_CopyFile(t *testing.T) {
defer delTestFiles(topath)
t.Assert(gfile.IsFile(testpath()+topath), true)
t.AssertNE(gfile.CopyFile("", ""), nil)
t.AssertNE(gfile.CopyFile(paths, ""), nil)
t.AssertNE(gfile.CopyFile("", topath), nil)
})
// Content replacement.
gtest.C(t, func(t *gtest.T) {
@ -128,5 +130,8 @@ func Test_CopyDir(t *testing.T) {
t.Assert(err, nil)
t.Assert(gfile.GetContents(src), srcContent)
t.Assert(gfile.GetContents(dst), srcContent)
t.AssertNE(gfile.CopyDir(gfile.Dir(src), ""), nil)
t.AssertNE(gfile.CopyDir("", gfile.Dir(dst)), nil)
})
}

View File

@ -68,6 +68,11 @@ func Test_StrToSize(t *testing.T) {
t.Assert(gfile.StrToSize("8.53P"), gconv.Int64(8.53*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("8.53PB"), gconv.Int64(8.53*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("8.01EB"), gconv.Int64(8.01*1024*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("0.01ZB"), gconv.Int64(0.01*1024*1024*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("0.01YB"), gconv.Int64(0.01*1024*1024*1024*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("0.01BB"), gconv.Int64(0.01*1024*1024*1024*1024*1024*1024*1024*1024*1024))
t.Assert(gfile.StrToSize("0.01AB"), gconv.Int64(-1))
t.Assert(gfile.StrToSize("123456789"), 123456789)
})
}

View File

@ -571,6 +571,7 @@ func Test_Dir(t *testing.T) {
t.Assert(readlPath, testpath())
t.Assert(len(gfile.Dir(".")) > 0, true)
})
}
@ -667,3 +668,15 @@ func Test_MainPkgPath(t *testing.T) {
t.Assert(reads, "")
})
}
func Test_SelfName(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(len(gfile.SelfName()) > 0, true)
})
}
func Test_MTimestamp(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(gfile.MTimestamp(gfile.Temp()) > 0, true)
})
}