测试覆盖率达到63.1%

This commit is contained in:
jroam 2019-04-10 17:54:28 +08:00
parent e9ca1eb538
commit a9b7d56d0b
6 changed files with 118 additions and 18 deletions

View File

@ -15,6 +15,7 @@ func TestGetContents(t *testing.T) {
)
gtest.Assert(GetContents(filepaths),"abcdefghijkmln")
gtest.Assert(GetContents(""),"")
})
}
@ -32,7 +33,8 @@ func TestGetBinContents(t *testing.T) {
readcontent=GetBinContents(filepaths2)
//文件不存在时@todo:等断言功能优化后,再来修改这里
gtest.Assert(readcontent,nil)
//if readcontent!=nil{
// t.Error("文件应不存在")
//}
@ -53,6 +55,9 @@ func TestTruncate(t *testing.T) {
err=Truncate(filepaths1,200)
gtest.Assert(err,nil)
err=Truncate("",200)
gtest.AssertNE(err,nil)
})
}
@ -71,11 +76,20 @@ func TestPutContents(t *testing.T) {
readcontent, err=ioutil.ReadFile(filepaths)
gtest.Assert(err,nil)
gtest.Assert(string(readcontent),"test!")
err=PutContents("","test!")
gtest.AssertNE(err,nil)
})
}
func TestPutContentsAppend(t *testing.T) {
gtest.Case(t , func() {
var(
@ -91,6 +105,13 @@ func TestPutContentsAppend(t *testing.T) {
readcontent, err=ioutil.ReadFile(filepaths)
gtest.Assert(err,nil)
gtest.Assert(string(readcontent),"test!hello")
err=PutContentsAppend("","hello")
gtest.AssertNE(err,nil)
})
@ -112,6 +133,13 @@ func TestPutBinContents(t *testing.T){
readcontent, err=ioutil.ReadFile(filepaths)
gtest.Assert(err,nil)
gtest.Assert(string(readcontent),"test!!")
err=PutBinContents("",[]byte("test!!"))
gtest.AssertNE(err,nil)
})
}
@ -131,6 +159,12 @@ func TestPutBinContentsAppend(t *testing.T) {
readcontent, err=ioutil.ReadFile(filepaths)
gtest.Assert(err,nil)
gtest.Assert(string(readcontent),"test!!word")
err=PutBinContentsAppend("",[]byte("word"))
gtest.AssertNE(err,nil)
})
}
@ -144,6 +178,10 @@ func TestGetBinContentsByTwoOffsetsByPath(t *testing.T) {
readcontent = GetBinContentsByTwoOffsetsByPath(filepaths, 2, 5)
gtest.Assert(string(readcontent), "cde")
readcontent = GetBinContentsByTwoOffsetsByPath("", 2, 5)
gtest.Assert(len(readcontent),0)
})
}
@ -159,6 +197,10 @@ func TestGetNextCharOffsetByPath(t *testing.T) {
localindex = GetNextCharOffsetByPath(filepaths,'d', 1)
gtest.Assert(localindex, 3)
localindex = GetNextCharOffsetByPath("",'d', 1)
gtest.Assert(localindex, -1)
})
}

View File

@ -12,6 +12,7 @@ func TestSearch(t *testing.T) {
var(
paths1 string ="./testfile/dirfiles"
tpath string
tpath2 string
tempstr string
err error
)
@ -22,16 +23,32 @@ func TestSearch(t *testing.T) {
tpath=filepath.ToSlash(tpath)
//==================自定义优先路径
tpath2,err=Search(paths1,"./")
gtest.Assert(err,nil)
tpath2=filepath.ToSlash(tpath2)
tempstr,_=filepath.Abs("./")
paths1=tempstr+paths1
paths1=filepath.ToSlash(paths1)
paths1=strings.Replace(paths1,"./","/",1)
gtest.Assert(tpath,paths1)
gtest.Assert(tpath2,paths1)
})
}

View File

@ -1,3 +1,5 @@
//test 100%
package gfile
import (
@ -14,6 +16,9 @@ func TestSize(t *testing.T){
sizes=Size(paths1)
gtest.Assert(sizes,16)
sizes=Size("")
gtest.Assert(sizes,0)
})
}
@ -21,7 +26,7 @@ func TestSize(t *testing.T){
func TestFormatSize(t *testing.T){
gtest.Case(t, func(){
gtest.Assert(FormatSize(0),"0.00B")
gtest.Assert(FormatSize(16),"16.00B")
gtest.Assert(FormatSize(1024),"1.00K")
@ -30,6 +35,11 @@ func TestFormatSize(t *testing.T){
gtest.Assert(FormatSize(1600000000),"1.49G")
gtest.Assert(FormatSize(9600000000000),"8.73T")
gtest.Assert(FormatSize(9600000000000000),"8.53P")
gtest.Assert(FormatSize(9600000000000000000),"TooLarge")
})
}
@ -40,6 +50,7 @@ func TestReadableSize(t *testing.T){
gtest.Case(t, func(){
gtest.Assert(ReadableSize("./testfile/dirfiles/t1.txt"),"16.00B")
gtest.Assert(ReadableSize(""),"0.00B")
})
}

View File

@ -2,6 +2,8 @@ package gfile
import (
"github.com/gogf/gf/g/test/gtest"
"github.com/gogf/gf/g/os/gtime"
"github.com/gogf/gf/g/util/gconv"
"os"
"path/filepath"
"strings"
@ -17,6 +19,7 @@ func TestIsDir(t *testing.T){
gtest.Assert(IsDir("./testfile"), true)
gtest.Assert(IsDir("./testfile2"), false)
gtest.Assert(IsDir("./testfile/tt.txt"), false)
gtest.Assert(IsDir(""), false)
})
}
@ -28,7 +31,7 @@ func TestCreate(t *testing.T){
filepaths []string
)
filepaths=append(filepaths,"./testfile/file/c1.txt")
filepaths=append(filepaths,"./testfile/createfile/c1.txt")
filepaths=append(filepaths,"./testfile/file1/c2.txt")
@ -37,6 +40,10 @@ func TestCreate(t *testing.T){
gtest.Assert(err,nil)
}
stname:=gconv.String(gtime.Now().Second())
_,err=Create("./testfile/createfile/c"+stname+".txt")
gtest.Assert(err,nil)
})
@ -116,12 +123,12 @@ func TestOpenWithFlag(t *testing.T) {
flags []bool
)
files=append(files,"./testfile/file1/nc1.txt")
flags=append(flags,false)
files=append(files,"./testfile/tt.txt")
files=append(files,"./testfile/dirfiles/t1.txt")
flags=append(flags,true)
files=append(files,"./testfile/dirfiles/t1_no.txt")
flags=append(flags,false)
for k,v:=range files{
_,err=OpenWithFlag(v,os.O_RDWR)
@ -179,12 +186,12 @@ func TestExists(t *testing.T) {
flags []bool
)
files=append(files,"./testfile/file1/nc1.txt")
flags=append(flags,false)
files=append(files,"./testfile/tt.txt")
files=append(files,"./testfile/havefile1/GetContents.txt")
flags=append(flags,true)
files=append(files,"./testfile/havefile1/tt_no.txt")
flags=append(flags,false)
for k,v:=range files{
flag=Exists(v)
@ -218,10 +225,10 @@ func TestIsFile(t *testing.T) {
flags []bool
)
files=append(files,"./testfile/file1/nc1.txt")
files=append(files,"./testfile/havefile1/nc1.txt")
flags=append(flags,false)
files=append(files,"./testfile/tt.txt")
files=append(files,"./testfile/havefile1/GetContents.txt")
flags=append(flags,true)
files=append(files,"./testfile")
@ -287,7 +294,9 @@ func TestMove(t *testing.T) {
)
gtest.Assert(Rename(paths,topath),nil)
gtest.Assert(IsFile(topath),true)
gtest.Assert(IsFile(topath),true)
gtest.AssertNE(Rename("",""),nil)
})
@ -305,6 +314,8 @@ func TestCopy(t *testing.T) {
gtest.Assert(Copy(paths,topath),nil)
gtest.Assert(IsFile(topath),true)
gtest.AssertNE(Copy("",""),nil)
})
}
@ -326,6 +337,9 @@ func TestDirNames(t *testing.T) {
gtest.Assert(err,nil)
gtest.Assert(havelist,readlist)
_,err=DirNames("")
gtest.AssertNE(err,nil)
})
@ -365,6 +379,14 @@ func TestGlob(t *testing.T) {
gtest.Assert(err,nil)
gtest.Assert(resultlist,havelist2)
_,err=Glob("",true)
gtest.Assert(err,nil)
_,err=Glob("",false)
gtest.Assert(err,nil)
})
}
@ -377,7 +399,6 @@ func TestRemove(t *testing.T) {
gtest.Assert(Remove(paths),nil)
})
}
@ -443,6 +464,9 @@ func TestScanDir(t *testing.T){
gtest.Assert(files,result)
_,err=ScanDir("","t*")
gtest.AssertNE(err,nil)
})
}
@ -467,6 +491,8 @@ func TestRealPath(t *testing.T){
gtest.Assert(readlPath,paths1)
gtest.Assert(RealPath("./nodirs"),"")
})
}
@ -573,3 +599,4 @@ func TestTempDir(t *testing.T){

View File

@ -1,3 +1,4 @@
//have test 100%
package gfile
import (
@ -9,11 +10,13 @@ import (
func TestMTime(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(MTime("./testfile/dirfiles/t1.txt"),1554883732)
gtest.Assert(MTime(""),0)
})
}
func TestMTimeMillisecond(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(MTimeMillisecond("./testfile/dirfiles/t1.txt"),129)
gtest.Assert(MTimeMillisecond(""),0)
})
}

View File