mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
用fmt格式化代码
This commit is contained in:
@ -28,7 +28,7 @@ install:
|
||||
- cat /etc/hosts
|
||||
|
||||
script:
|
||||
- cd g/os/gfile
|
||||
- cd g
|
||||
- GOARCH=386 go test -v ./...
|
||||
- GOARCH=amd64 go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
|
||||
@ -7,163 +7,140 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
func TestGetContents(t *testing.T) {
|
||||
gtest.Case(t,func(){
|
||||
var(
|
||||
filepaths string= "./testfile/dirfiles/t1.txt"
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/dirfiles/t1.txt"
|
||||
)
|
||||
|
||||
gtest.Assert(GetContents(filepaths),"my name is jroam")
|
||||
gtest.Assert(GetContents(""),"")
|
||||
gtest.Assert(GetContents(filepaths), "my name is jroam")
|
||||
gtest.Assert(GetContents(""), "")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestGetBinContents(t *testing.T) {
|
||||
gtest.Case(t , func() {
|
||||
var(
|
||||
filepaths1 string="./testfile/dirfiles/t1.txt" //存在文件
|
||||
filepaths2 string="./testfile/dirfiles/t1_no.txt" //不存大文件
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths1 string = "./testfile/dirfiles/t1.txt" //存在文件
|
||||
filepaths2 string = "./testfile/dirfiles/t1_no.txt" //不存大文件
|
||||
readcontent []byte
|
||||
)
|
||||
readcontent=GetBinContents(filepaths1)
|
||||
gtest.Assert(readcontent,[]byte("my name is jroam"))
|
||||
readcontent = GetBinContents(filepaths1)
|
||||
gtest.Assert(readcontent, []byte("my name is jroam"))
|
||||
|
||||
|
||||
readcontent=GetBinContents(filepaths2)
|
||||
gtest.Assert(readcontent,nil)
|
||||
readcontent = GetBinContents(filepaths2)
|
||||
gtest.Assert(readcontent, nil)
|
||||
|
||||
//if readcontent!=nil{
|
||||
// t.Error("文件应不存在")
|
||||
//}
|
||||
gtest.Assert(GetBinContents(filepaths2),nil)
|
||||
|
||||
|
||||
gtest.Assert(GetBinContents(filepaths2), nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//截断文件为指定的大小
|
||||
func TestTruncate(t *testing.T) {
|
||||
gtest.Case(t , func() {
|
||||
var(
|
||||
filepaths1 string="./testfile/havefile1/GetContents.txt" //存在文件
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths1 string = "./testfile/havefile1/GetContents.txt" //存在文件
|
||||
err error
|
||||
)
|
||||
err=Truncate(filepaths1,200)
|
||||
gtest.Assert(err,nil)
|
||||
err = Truncate(filepaths1, 200)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
err=Truncate("",200)
|
||||
gtest.AssertNE(err,nil)
|
||||
err = Truncate("", 200)
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestPutContents(t *testing.T) {
|
||||
gtest.Case(t , func() {
|
||||
var(
|
||||
filepaths string="./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
readcontent []byte
|
||||
)
|
||||
|
||||
err=PutContents(filepaths,"test!")
|
||||
gtest.Assert(err,nil)
|
||||
err = PutContents(filepaths, "test!")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
//==================判断是否真正写入
|
||||
readcontent, err=ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(string(readcontent),"test!")
|
||||
|
||||
|
||||
err=PutContents("","test!")
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
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(
|
||||
filepaths string="./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
readcontent []byte
|
||||
)
|
||||
|
||||
err=PutContentsAppend(filepaths,"hello")
|
||||
gtest.Assert(err,nil)
|
||||
err = PutContentsAppend(filepaths, "hello")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
//==================判断是否真正写入
|
||||
readcontent, err=ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(string(readcontent),"test!hello")
|
||||
|
||||
|
||||
err=PutContentsAppend("","hello")
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(string(readcontent), "test!hello")
|
||||
|
||||
err = PutContentsAppend("", "hello")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
func TestPutBinContents(t *testing.T){
|
||||
gtest.Case(t , func() {
|
||||
var(
|
||||
filepaths string="./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
func TestPutBinContents(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/havefile1/PutContents.txt"
|
||||
err error
|
||||
readcontent []byte
|
||||
)
|
||||
|
||||
err=PutBinContents(filepaths,[]byte("test!!"))
|
||||
gtest.Assert(err,nil)
|
||||
err = PutBinContents(filepaths, []byte("test!!"))
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
//==================判断是否真正写入
|
||||
readcontent, err=ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(string(readcontent),"test!!")
|
||||
|
||||
|
||||
err=PutBinContents("",[]byte("test!!"))
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(string(readcontent), "test!!")
|
||||
|
||||
err = PutBinContents("", []byte("test!!"))
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestPutBinContentsAppend(t *testing.T) {
|
||||
gtest.Case(t , func() {
|
||||
var(
|
||||
filepaths string="./testfile/havefile1/PutContents.txt" //原文件内容: yy
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/havefile1/PutContents.txt" //原文件内容: yy
|
||||
err error
|
||||
readcontent []byte
|
||||
)
|
||||
|
||||
err=PutBinContentsAppend(filepaths,[]byte("word"))
|
||||
gtest.Assert(err,nil)
|
||||
err = PutBinContentsAppend(filepaths, []byte("word"))
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
//==================判断是否真正写入
|
||||
readcontent, err=ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(string(readcontent),"test!!word")
|
||||
|
||||
|
||||
err=PutBinContentsAppend("",[]byte("word"))
|
||||
gtest.AssertNE(err,nil)
|
||||
readcontent, err = ioutil.ReadFile(filepaths)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(string(readcontent), "test!!word")
|
||||
|
||||
err = PutBinContentsAppend("", []byte("word"))
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
@ -180,45 +157,40 @@ func TestGetBinContentsByTwoOffsetsByPath(t *testing.T) {
|
||||
gtest.Assert(string(readcontent), "cde")
|
||||
|
||||
readcontent = GetBinContentsByTwoOffsetsByPath("", 2, 5)
|
||||
gtest.Assert(len(readcontent),0)
|
||||
gtest.Assert(len(readcontent), 0)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
func TestGetNextCharOffsetByPath(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
filepaths string = "./testfile/havefile1/GetContents.txt" //原文件内容: abcdefghijk
|
||||
filepaths string = "./testfile/havefile1/GetContents.txt" //原文件内容: abcdefghijk
|
||||
localindex int64
|
||||
|
||||
)
|
||||
|
||||
localindex = GetNextCharOffsetByPath(filepaths,'d', 1)
|
||||
localindex = GetNextCharOffsetByPath(filepaths, 'd', 1)
|
||||
gtest.Assert(localindex, 3)
|
||||
|
||||
localindex = GetNextCharOffsetByPath("",'d', 1)
|
||||
localindex = GetNextCharOffsetByPath("", 'd', 1)
|
||||
gtest.Assert(localindex, -1)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestGetNextCharOffset(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
localindex int64
|
||||
|
||||
)
|
||||
reader:=strings.NewReader("helloword")
|
||||
reader := strings.NewReader("helloword")
|
||||
|
||||
localindex = GetNextCharOffset(reader,'w', 1)
|
||||
gtest.Assert(localindex,5)
|
||||
|
||||
localindex = GetNextCharOffset(reader,'j', 1)
|
||||
gtest.Assert(localindex,-1)
|
||||
localindex = GetNextCharOffset(reader, 'w', 1)
|
||||
gtest.Assert(localindex, 5)
|
||||
|
||||
localindex = GetNextCharOffset(reader, 'j', 1)
|
||||
gtest.Assert(localindex, -1)
|
||||
|
||||
})
|
||||
}
|
||||
@ -227,15 +199,14 @@ func TestGetBinContentsByTwoOffsets(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
reads []byte
|
||||
|
||||
)
|
||||
reader:=strings.NewReader("helloword")
|
||||
reader := strings.NewReader("helloword")
|
||||
|
||||
reads = GetBinContentsByTwoOffsets(reader,1, 3)
|
||||
gtest.Assert(string(reads),"el")
|
||||
reads = GetBinContentsByTwoOffsets(reader, 1, 3)
|
||||
gtest.Assert(string(reads), "el")
|
||||
|
||||
reads = GetBinContentsByTwoOffsets(reader,10, 30)
|
||||
gtest.Assert(string(reads),"")
|
||||
reads = GetBinContentsByTwoOffsets(reader, 10, 30)
|
||||
gtest.Assert(string(reads), "")
|
||||
|
||||
})
|
||||
}
|
||||
@ -243,17 +214,16 @@ func TestGetBinContentsByTwoOffsets(t *testing.T) {
|
||||
func TestGetBinContentsTilChar(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
reads []byte
|
||||
reads []byte
|
||||
indexs int64
|
||||
|
||||
)
|
||||
reader:=strings.NewReader("helloword")
|
||||
reader := strings.NewReader("helloword")
|
||||
|
||||
reads,_ = GetBinContentsTilChar(reader,'w', 2)
|
||||
gtest.Assert(string(reads),"llow")
|
||||
reads, _ = GetBinContentsTilChar(reader, 'w', 2)
|
||||
gtest.Assert(string(reads), "llow")
|
||||
|
||||
_,indexs = GetBinContentsTilChar(reader,'w', 20)
|
||||
gtest.Assert(indexs,-1)
|
||||
_, indexs = GetBinContentsTilChar(reader, 'w', 20)
|
||||
gtest.Assert(indexs, -1)
|
||||
|
||||
})
|
||||
}
|
||||
@ -261,24 +231,19 @@ func TestGetBinContentsTilChar(t *testing.T) {
|
||||
func TestGetBinContentsTilCharByPath(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
reads []byte
|
||||
indexs int64
|
||||
filepaths string = "./testfile/havefile1/GetContents.txt"
|
||||
|
||||
reads []byte
|
||||
indexs int64
|
||||
filepaths string = "./testfile/havefile1/GetContents.txt"
|
||||
)
|
||||
|
||||
reads, _ = GetBinContentsTilCharByPath(filepaths, 'c', 2)
|
||||
gtest.Assert(string(reads), "c")
|
||||
|
||||
reads,_ = GetBinContentsTilCharByPath(filepaths,'c',2)
|
||||
gtest.Assert(string(reads),"c")
|
||||
|
||||
reads,_ = GetBinContentsTilCharByPath(filepaths,'y',1)
|
||||
gtest.Assert(string(reads),"")
|
||||
|
||||
|
||||
_,indexs = GetBinContentsTilCharByPath(filepaths,'x',1)
|
||||
gtest.Assert(indexs,-1)
|
||||
|
||||
reads, _ = GetBinContentsTilCharByPath(filepaths, 'y', 1)
|
||||
gtest.Assert(string(reads), "")
|
||||
|
||||
_, indexs = GetBinContentsTilCharByPath(filepaths, 'x', 1)
|
||||
gtest.Assert(indexs, -1)
|
||||
|
||||
})
|
||||
}
|
||||
@ -287,26 +252,13 @@ func TestHome(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
reads string
|
||||
err error
|
||||
|
||||
err error
|
||||
)
|
||||
|
||||
reads,err=Home()
|
||||
|
||||
gtest.Assert(err,nil)
|
||||
gtest.AssertNE(reads,"")
|
||||
reads, err = Home()
|
||||
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNE(reads, "")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,50 +8,40 @@ import (
|
||||
)
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/dirfiles"
|
||||
paths2 string ="./testfile/dirfiles_no"
|
||||
tpath string
|
||||
tpath2 string
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/dirfiles"
|
||||
paths2 string = "./testfile/dirfiles_no"
|
||||
tpath string
|
||||
tpath2 string
|
||||
tempstr string
|
||||
err error
|
||||
err error
|
||||
)
|
||||
|
||||
tpath,err=Search(paths1)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
tpath=filepath.ToSlash(tpath)
|
||||
tpath, err = Search(paths1)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
tpath = filepath.ToSlash(tpath)
|
||||
|
||||
//==================自定义优先路径
|
||||
|
||||
tpath2,err=Search(paths1,"./")
|
||||
gtest.Assert(err,nil)
|
||||
tpath2=filepath.ToSlash(tpath2)
|
||||
|
||||
|
||||
|
||||
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)
|
||||
tempstr, _ = filepath.Abs("./")
|
||||
paths1 = tempstr + paths1
|
||||
paths1 = filepath.ToSlash(paths1)
|
||||
paths1 = strings.Replace(paths1, "./", "/", 1)
|
||||
|
||||
gtest.Assert(tpath,paths1)
|
||||
|
||||
gtest.Assert(tpath2,paths1)
|
||||
gtest.Assert(tpath, paths1)
|
||||
|
||||
gtest.Assert(tpath2, paths1)
|
||||
|
||||
//测试目录不存在时
|
||||
_,err=Search(paths2)
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_, err = Search(paths2)
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -7,50 +7,45 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSize(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/dirfiles/t1.txt"
|
||||
sizes int64
|
||||
func TestSize(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/dirfiles/t1.txt"
|
||||
sizes int64
|
||||
)
|
||||
sizes=Size(paths1)
|
||||
gtest.Assert(sizes,16)
|
||||
|
||||
sizes=Size("")
|
||||
gtest.Assert(sizes,0)
|
||||
sizes = Size(paths1)
|
||||
gtest.Assert(sizes, 16)
|
||||
|
||||
sizes = Size("")
|
||||
gtest.Assert(sizes, 0)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestFormatSize(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
gtest.Assert(FormatSize(0), "0.00B")
|
||||
gtest.Assert(FormatSize(16), "16.00B")
|
||||
|
||||
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")
|
||||
|
||||
gtest.Assert(FormatSize(1024),"1.00K")
|
||||
gtest.Assert(FormatSize(16000000), "15.26M")
|
||||
|
||||
gtest.Assert(FormatSize(16000000),"15.26M")
|
||||
gtest.Assert(FormatSize(1600000000), "1.49G")
|
||||
|
||||
gtest.Assert(FormatSize(1600000000),"1.49G")
|
||||
|
||||
gtest.Assert(FormatSize(9600000000000),"8.73T")
|
||||
gtest.Assert(FormatSize(9600000000000000),"8.53P")
|
||||
|
||||
gtest.Assert(FormatSize(9600000000000000000),"TooLarge")
|
||||
gtest.Assert(FormatSize(9600000000000), "8.73T")
|
||||
gtest.Assert(FormatSize(9600000000000000), "8.53P")
|
||||
|
||||
gtest.Assert(FormatSize(9600000000000000000), "TooLarge")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestReadableSize(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
|
||||
|
||||
func TestReadableSize(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
|
||||
gtest.Assert(ReadableSize("./testfile/dirfiles/t1.txt"),"16.00B")
|
||||
gtest.Assert(ReadableSize(""),"0.00B")
|
||||
gtest.Assert(ReadableSize("./testfile/dirfiles/t1.txt"), "16.00B")
|
||||
gtest.Assert(ReadableSize(""), "0.00B")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package gfile
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
"github.com/gogf/gf/g/os/gtime"
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
"github.com/gogf/gf/g/util/gconv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -10,10 +10,7 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestIsDir(t *testing.T){
|
||||
|
||||
func TestIsDir(t *testing.T) {
|
||||
|
||||
gtest.Case(t, func() {
|
||||
gtest.Assert(IsDir("./testfile"), true)
|
||||
@ -24,254 +21,226 @@ func TestIsDir(t *testing.T){
|
||||
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T){
|
||||
func TestCreate(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
err error
|
||||
filepaths []string
|
||||
)
|
||||
|
||||
filepaths=append(filepaths,"./testfile/createfile/c1.txt")
|
||||
filepaths=append(filepaths,"./testfile/file1/c2.txt")
|
||||
filepaths = append(filepaths, "./testfile/createfile/c1.txt")
|
||||
filepaths = append(filepaths, "./testfile/file1/c2.txt")
|
||||
|
||||
for _, v := range filepaths {
|
||||
_, err = Create(v)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for _,v:=range filepaths{
|
||||
_,err=Create(v)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
}
|
||||
stname:=gconv.String(gtime.Now().Second())
|
||||
|
||||
_,err=Create("./testfile/createfile/c"+stname+".txt")
|
||||
gtest.Assert(err,nil)
|
||||
}
|
||||
stname := gconv.String(gtime.Now().Second())
|
||||
|
||||
_, err = Create("./testfile/createfile/c" + stname + ".txt")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
func TestOpen(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
err error
|
||||
func TestOpen(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/file1/nc1.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/file1/nc1.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
files=append(files,"./testfile/file1/c1.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/file1/c1.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
for k, v := range files {
|
||||
_, err = Open(v)
|
||||
|
||||
for k,v:=range files{
|
||||
_,err=Open(v)
|
||||
|
||||
|
||||
if flags[k]{
|
||||
gtest.Assert(err,nil)
|
||||
}else{
|
||||
gtest.AssertNE(err,nil)
|
||||
if flags[k] {
|
||||
gtest.Assert(err, nil)
|
||||
} else {
|
||||
gtest.AssertNE(err, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestOpenFile(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
err error
|
||||
func TestOpenFile(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/file1/nc1.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/file1/nc1.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
files=append(files,"./testfile/tt.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/tt.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
|
||||
for k,v:=range files{
|
||||
_,err=OpenFile(v,os.O_RDWR,0666)
|
||||
if flags[k]{
|
||||
gtest.Assert(err,nil)
|
||||
}else{
|
||||
gtest.AssertNE(err,nil)
|
||||
for k, v := range files {
|
||||
_, err = OpenFile(v, os.O_RDWR, 0666)
|
||||
if flags[k] {
|
||||
gtest.Assert(err, nil)
|
||||
} else {
|
||||
gtest.AssertNE(err, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
func TestOpenWithFlag(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/dirfiles/t1.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/dirfiles/t1.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
files=append(files,"./testfile/dirfiles/t1_no.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/dirfiles/t1_no.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
|
||||
for k,v:=range files{
|
||||
_,err=OpenWithFlag(v,os.O_RDWR)
|
||||
if flags[k]{
|
||||
gtest.Assert(err,nil)
|
||||
}else{
|
||||
gtest.AssertNE(err,nil)
|
||||
for k, v := range files {
|
||||
_, err = OpenWithFlag(v, os.O_RDWR)
|
||||
if flags[k] {
|
||||
gtest.Assert(err, nil)
|
||||
} else {
|
||||
gtest.AssertNE(err, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestOpenWithFlagPerm(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/file1/nc1.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/file1/nc1.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
files=append(files,"./testfile/tt.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/tt.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
|
||||
for k,v:=range files{
|
||||
_,err=OpenWithFlagPerm(v,os.O_RDWR,666)
|
||||
if flags[k]{
|
||||
gtest.Assert(err,nil)
|
||||
}else{
|
||||
gtest.AssertNE(err,nil)
|
||||
for k, v := range files {
|
||||
_, err = OpenWithFlagPerm(v, os.O_RDWR, 666)
|
||||
if flags[k] {
|
||||
gtest.Assert(err, nil)
|
||||
} else {
|
||||
gtest.AssertNE(err, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
flag bool
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
flag bool
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/havefile1/GetContents.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/havefile1/GetContents.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
files=append(files,"./testfile/havefile1/tt_no.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/havefile1/tt_no.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
|
||||
for k,v:=range files{
|
||||
flag=Exists(v)
|
||||
if flags[k]{
|
||||
gtest.Assert(flag,true)
|
||||
}else{
|
||||
gtest.Assert(flag,false)
|
||||
for k, v := range files {
|
||||
flag = Exists(v)
|
||||
if flags[k] {
|
||||
gtest.Assert(flag, true)
|
||||
} else {
|
||||
gtest.Assert(flag, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestPwd(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
paths,err:=os.Getwd()
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(Pwd(),paths)
|
||||
gtest.Case(t, func() {
|
||||
paths, err := os.Getwd()
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(Pwd(), paths)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsFile(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
flag bool
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
flag bool
|
||||
files []string
|
||||
flags []bool
|
||||
)
|
||||
|
||||
files=append(files,"./testfile/havefile1/nc1.txt")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile/havefile1/nc1.txt")
|
||||
flags = append(flags, false)
|
||||
|
||||
files=append(files,"./testfile/havefile1/GetContents.txt")
|
||||
flags=append(flags,true)
|
||||
files = append(files, "./testfile/havefile1/GetContents.txt")
|
||||
flags = append(flags, true)
|
||||
|
||||
files=append(files,"./testfile")
|
||||
flags=append(flags,false)
|
||||
files = append(files, "./testfile")
|
||||
flags = append(flags, false)
|
||||
|
||||
|
||||
for k,v:=range files{
|
||||
flag=IsFile(v)
|
||||
if flags[k]{
|
||||
gtest.Assert(flag,true)
|
||||
}else{
|
||||
gtest.Assert(flag,false)
|
||||
for k, v := range files {
|
||||
flag = IsFile(v)
|
||||
if flags[k] {
|
||||
gtest.Assert(flag, true)
|
||||
} else {
|
||||
gtest.Assert(flag, false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
err error
|
||||
paths string ="./testfile/tt.txt"
|
||||
files os.FileInfo
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
err error
|
||||
paths string = "./testfile/tt.txt"
|
||||
files os.FileInfo
|
||||
files2 os.FileInfo
|
||||
)
|
||||
|
||||
files,err=Info(paths)
|
||||
gtest.Assert(err,nil)
|
||||
files, err = Info(paths)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
files2, err = os.Stat(paths)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
files2,err=os.Stat(paths)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
gtest.Assert(files,files2)
|
||||
gtest.Assert(files, files2)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//func TestMove(t *testing.T) {
|
||||
// gtest.Case(t, func(){
|
||||
// var(
|
||||
@ -305,360 +274,316 @@ func TestInfo(t *testing.T) {
|
||||
// }
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths string ="./testfile/havefile1/copyfile1.txt"
|
||||
topath string ="./testfile/havefile1/copyfile2.txt"
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths string = "./testfile/havefile1/copyfile1.txt"
|
||||
topath string = "./testfile/havefile1/copyfile2.txt"
|
||||
)
|
||||
|
||||
gtest.Assert(Copy(paths,topath),nil)
|
||||
gtest.Assert(IsFile(topath),true)
|
||||
|
||||
gtest.AssertNE(Copy("",""),nil)
|
||||
gtest.Assert(Copy(paths, topath), nil)
|
||||
gtest.Assert(IsFile(topath), true)
|
||||
|
||||
gtest.AssertNE(Copy("", ""), nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestDirNames(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths string ="./testfile/dirfiles"
|
||||
err error
|
||||
func TestDirNames(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths string = "./testfile/dirfiles"
|
||||
err error
|
||||
readlist []string
|
||||
|
||||
)
|
||||
havelist:=[]string{
|
||||
havelist := []string{
|
||||
"t1.txt",
|
||||
"t2.txt",
|
||||
}
|
||||
readlist,err=DirNames(paths)
|
||||
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(havelist,readlist)
|
||||
|
||||
_,err=DirNames("")
|
||||
gtest.AssertNE(err,nil)
|
||||
readlist, err = DirNames(paths)
|
||||
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(havelist, readlist)
|
||||
|
||||
_, err = DirNames("")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestGlob(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths string ="./testfile/dirfiles/*.txt"
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths string = "./testfile/dirfiles/*.txt"
|
||||
err error
|
||||
resultlist []string
|
||||
|
||||
)
|
||||
|
||||
havelist1:=[]string{
|
||||
havelist1 := []string{
|
||||
"t1.txt",
|
||||
"t2.txt",
|
||||
}
|
||||
|
||||
havelist2:=[]string{
|
||||
havelist2 := []string{
|
||||
"testfile/dirfiles/t1.txt",
|
||||
"testfile/dirfiles/t2.txt",
|
||||
}
|
||||
|
||||
resultlist,err=Glob(paths,true)
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(resultlist,havelist1)
|
||||
resultlist, err = Glob(paths, true)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(resultlist, havelist1)
|
||||
|
||||
|
||||
resultlist,err=Glob(paths,false)
|
||||
resultlist, err = Glob(paths, false)
|
||||
|
||||
//转换成统一的目录分隔符
|
||||
for k,v:=range resultlist{
|
||||
resultlist[k]=filepath.ToSlash(v)
|
||||
for k, v := range resultlist {
|
||||
resultlist[k] = filepath.ToSlash(v)
|
||||
}
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(resultlist,havelist2)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.Assert(resultlist, havelist2)
|
||||
|
||||
_, err = Glob("", true)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
_,err=Glob("",true)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
_,err=Glob("",false)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
_, err = Glob("", false)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths string ="./testfile/delfile/t1.txt"
|
||||
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths string = "./testfile/delfile/t1.txt"
|
||||
)
|
||||
|
||||
gtest.Assert(Remove(paths),nil)
|
||||
gtest.Assert(Remove(paths), nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsReadable(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1/GetContents.txt"
|
||||
paths2 string ="./testfile/havefile1/GetContents_no.txt"
|
||||
func TestIsReadable(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1/GetContents.txt"
|
||||
paths2 string = "./testfile/havefile1/GetContents_no.txt"
|
||||
)
|
||||
gtest.Assert(IsReadable(paths1),true)
|
||||
gtest.Assert(IsReadable(paths2),false)
|
||||
gtest.Assert(IsReadable(paths1), true)
|
||||
gtest.Assert(IsReadable(paths2), false)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsWritable(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1/GetContents.txt"
|
||||
paths2 string ="./testfile/havefile1/GetContents_no.txt"
|
||||
func TestIsWritable(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1/GetContents.txt"
|
||||
paths2 string = "./testfile/havefile1/GetContents_no.txt"
|
||||
)
|
||||
gtest.Assert(IsWritable(paths1),true)
|
||||
gtest.Assert(IsWritable(paths2),false)
|
||||
gtest.Assert(IsWritable(paths1), true)
|
||||
gtest.Assert(IsWritable(paths2), false)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestChmod(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1/GetContents.txt"
|
||||
paths2 string ="./testfile/havefile1/GetContents_no.txt"
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1/GetContents.txt"
|
||||
paths2 string = "./testfile/havefile1/GetContents_no.txt"
|
||||
)
|
||||
|
||||
|
||||
gtest.Assert(Chmod(paths1,0777),nil)
|
||||
gtest.AssertNE(Chmod(paths2,0777),nil)
|
||||
gtest.Assert(Chmod(paths1, 0777), nil)
|
||||
gtest.AssertNE(Chmod(paths2, 0777), nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestScanDir(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/dirfiles"
|
||||
files []string
|
||||
err error
|
||||
func TestScanDir(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/dirfiles"
|
||||
files []string
|
||||
err error
|
||||
)
|
||||
files,err=ScanDir(paths1,"t*")
|
||||
files, err = ScanDir(paths1, "t*")
|
||||
|
||||
result:=[]string{
|
||||
result := []string{
|
||||
"./testfile/dirfiles/t1.txt",
|
||||
"./testfile/dirfiles/t2.txt",
|
||||
}
|
||||
|
||||
gtest.Assert(err,nil)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
for k,v:=range files{
|
||||
files[k]=filepath.ToSlash(v)
|
||||
for k, v := range files {
|
||||
files[k] = filepath.ToSlash(v)
|
||||
}
|
||||
|
||||
gtest.Assert(files,result)
|
||||
|
||||
_,err=ScanDir("","t*")
|
||||
gtest.AssertNE(err,nil)
|
||||
gtest.Assert(files, result)
|
||||
|
||||
_, err = ScanDir("", "t*")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//获取绝对目录地址
|
||||
func TestRealPath(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/dirfiles"
|
||||
func TestRealPath(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/dirfiles"
|
||||
readlPath string
|
||||
|
||||
tempstr string
|
||||
)
|
||||
readlPath=RealPath(paths1)
|
||||
readlPath=filepath.ToSlash(readlPath)
|
||||
readlPath = RealPath(paths1)
|
||||
readlPath = filepath.ToSlash(readlPath)
|
||||
|
||||
tempstr,_=filepath.Abs("./")
|
||||
paths1=tempstr+paths1
|
||||
paths1=filepath.ToSlash(paths1)
|
||||
paths1=strings.Replace(paths1,"./","/",1)
|
||||
tempstr, _ = filepath.Abs("./")
|
||||
paths1 = tempstr + paths1
|
||||
paths1 = filepath.ToSlash(paths1)
|
||||
paths1 = strings.Replace(paths1, "./", "/", 1)
|
||||
|
||||
gtest.Assert(readlPath, paths1)
|
||||
|
||||
gtest.Assert(readlPath,paths1)
|
||||
|
||||
gtest.Assert(RealPath("./nodirs"),"")
|
||||
|
||||
gtest.Assert(RealPath("./nodirs"), "")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//获取当前执行文件的目录
|
||||
//注意:当用go test运行测试时,会产生临时的目录文件
|
||||
func TestSelfPath(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string
|
||||
func TestSelfPath(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string
|
||||
readlPath string
|
||||
tempstr string
|
||||
tempstr string
|
||||
)
|
||||
readlPath=SelfPath()
|
||||
readlPath=filepath.ToSlash(readlPath)
|
||||
readlPath = SelfPath()
|
||||
readlPath = filepath.ToSlash(readlPath)
|
||||
|
||||
//
|
||||
tempstr,_=filepath.Abs(os.Args[0])
|
||||
paths1=filepath.ToSlash(tempstr)
|
||||
paths1=strings.Replace(paths1,"./","/",1)
|
||||
tempstr, _ = filepath.Abs(os.Args[0])
|
||||
paths1 = filepath.ToSlash(tempstr)
|
||||
paths1 = strings.Replace(paths1, "./", "/", 1)
|
||||
|
||||
|
||||
gtest.Assert(readlPath,paths1)
|
||||
gtest.Assert(readlPath, paths1)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestSelfDir(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string
|
||||
func TestSelfDir(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string
|
||||
readlPath string
|
||||
tempstr string
|
||||
tempstr string
|
||||
)
|
||||
readlPath=SelfDir()
|
||||
readlPath = SelfDir()
|
||||
|
||||
tempstr, _ = filepath.Abs(os.Args[0])
|
||||
paths1 = filepath.Dir(tempstr)
|
||||
|
||||
tempstr,_=filepath.Abs(os.Args[0])
|
||||
paths1=filepath.Dir(tempstr)
|
||||
|
||||
gtest.Assert(readlPath,paths1)
|
||||
gtest.Assert(readlPath, paths1)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestBasename(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1/GetContents.txt"
|
||||
readlPath string
|
||||
|
||||
)
|
||||
readlPath=Basename(paths1)
|
||||
gtest.Assert(readlPath,"GetContents.txt")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestDir(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1"
|
||||
func TestBasename(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1/GetContents.txt"
|
||||
readlPath string
|
||||
)
|
||||
readlPath=Dir(paths1)
|
||||
|
||||
gtest.Assert(readlPath,"testfile")
|
||||
readlPath = Basename(paths1)
|
||||
gtest.Assert(readlPath, "GetContents.txt")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestDir(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1"
|
||||
readlPath string
|
||||
)
|
||||
readlPath = Dir(paths1)
|
||||
|
||||
gtest.Assert(readlPath, "testfile")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//获取文件名
|
||||
func TestExt(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
paths1 string ="./testfile/havefile1/GetContents.txt"
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
paths1 string = "./testfile/havefile1/GetContents.txt"
|
||||
)
|
||||
|
||||
gtest.Assert(Ext(paths1),".txt")
|
||||
gtest.Assert(Ext(paths1), ".txt")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestTempDir(t *testing.T){
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
func TestTempDir(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
tpath string
|
||||
)
|
||||
|
||||
tpath=TempDir()
|
||||
gtest.Assert(tpath,os.TempDir())
|
||||
tpath = TempDir()
|
||||
gtest.Assert(tpath, os.TempDir())
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestMkdir(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
tpath string ="./testfile/createdir"
|
||||
err error
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
tpath string = "./testfile/createdir"
|
||||
err error
|
||||
)
|
||||
|
||||
err=Mkdir(tpath)
|
||||
gtest.Assert(err,nil)
|
||||
err = Mkdir(tpath)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
err=Mkdir("")
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
err=Mkdir(tpath+"2/t1")
|
||||
gtest.Assert(err,nil)
|
||||
err = Mkdir("")
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
err = Mkdir(tpath + "2/t1")
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestStat(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
tpath1 string ="./testfile/dirfiles/t1.txt"
|
||||
tpath2 string ="./testfile/dirfiles/t1_no.txt"
|
||||
err error
|
||||
func TestStat(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
tpath1 string = "./testfile/dirfiles/t1.txt"
|
||||
tpath2 string = "./testfile/dirfiles/t1_no.txt"
|
||||
err error
|
||||
)
|
||||
|
||||
_,err=Stat(tpath1)
|
||||
gtest.Assert(err,nil)
|
||||
|
||||
|
||||
_,err=Stat(tpath2)
|
||||
gtest.AssertNE(err,nil)
|
||||
|
||||
_, err = Stat(tpath1)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
_, err = Stat(tpath2)
|
||||
gtest.AssertNE(err, nil)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestMainPkgPath(t *testing.T) {
|
||||
gtest.Case(t, func(){
|
||||
var(
|
||||
gtest.Case(t, func() {
|
||||
var (
|
||||
//tpath1 string ="./testfile/dirfiles/t1.txt"
|
||||
reads string
|
||||
//err error
|
||||
)
|
||||
|
||||
reads=MainPkgPath()
|
||||
gtest.Assert(reads,"")
|
||||
|
||||
reads = MainPkgPath()
|
||||
gtest.Assert(reads, "")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,23 +2,22 @@
|
||||
package gfile
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/gogf/gf/g/test/gtest"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMTime(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
//拷贝到其它地方,再测试的时候,这个文件的修改值会变,所以用大于来断言
|
||||
gtest.AssertGT(MTime("./testfile/dirfiles/t1.txt"),1454883732)
|
||||
gtest.Assert(MTime(""),0)
|
||||
gtest.AssertGT(MTime("./testfile/dirfiles/t1.txt"), 1454883732)
|
||||
gtest.Assert(MTime(""), 0)
|
||||
})
|
||||
}
|
||||
|
||||
func TestMTimeMillisecond(t *testing.T) {
|
||||
gtest.Case(t, func() {
|
||||
//这里本不为0,但github中的ci测试时,值为0
|
||||
gtest.AssertGTE(MTimeMillisecond("./testfile/dirfiles/t1.txt"),0)
|
||||
gtest.Assert(MTimeMillisecond(""),0)
|
||||
gtest.AssertGTE(MTimeMillisecond("./testfile/dirfiles/t1.txt"), 0)
|
||||
gtest.Assert(MTimeMillisecond(""), 0)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user