mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
Improving gfile Code Coverage
This commit is contained in:
@ -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() {
|
||||
|
||||
@ -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, "")
|
||||
})
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user