From 1868465319219f6a2d46df8cc890431a9cd7e278 Mon Sep 17 00:00:00 2001 From: "yybjroam@qq.com" Date: Mon, 15 Apr 2019 22:47:09 +0800 Subject: [PATCH] edit TestTruncate fun --- TODO.MD | 2 +- g/os/gfile/gfile_contents_test.go | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/TODO.MD b/TODO.MD index dee349def..e456a8c6c 100644 --- a/TODO.MD +++ b/TODO.MD @@ -1,4 +1,4 @@ -# ON THE WAY go go go +# ON THE WAY 1. 增加图形验证码支持,至少支持数字和英文字母; 1. Cookie&Session数据池化处理; 1. ghttp.Client增加proxy特性; diff --git a/g/os/gfile/gfile_contents_test.go b/g/os/gfile/gfile_contents_test.go index 2a352a1bc..9a11ec929 100644 --- a/g/os/gfile/gfile_contents_test.go +++ b/g/os/gfile/gfile_contents_test.go @@ -72,8 +72,8 @@ func TestGetContents(t *testing.T) { func TestGetBinContents(t *testing.T) { gtest.Case(t, func() { var ( - filepaths1 string = "/testfile_t1.txt" //存在文件 - filepaths2 string = Testpath() + "/testfile_t1_no.txt" //不存大文件 + filepaths1 string = "/testfile_t1.txt" //文件存在时 + filepaths2 string = Testpath() + "/testfile_t1_no.txt" //文件不存在时 readcontent []byte str1 string = "my name is jroam" ) @@ -85,9 +85,6 @@ func TestGetBinContents(t *testing.T) { readcontent = GetBinContents(filepaths2) gtest.Assert(string(readcontent), "") - //if readcontent!=nil{ - // t.Error("文件应不存在") - //} gtest.Assert(string(GetBinContents(filepaths2)), "") }) @@ -97,15 +94,25 @@ func TestGetBinContents(t *testing.T) { func TestTruncate(t *testing.T) { gtest.Case(t, func() { var ( - filepaths1 string = "/testfile_GetContents.txt" //存在文件 + filepaths1 string = "/testfile_GetContentsyyui.txt" //文件存在时 err error + files *os.File ) CreateTestFile(filepaths1, "abcdefghijkmln") defer DelTestFiles(filepaths1) - err = Truncate(Testpath()+filepaths1, 200) + err = Truncate(Testpath()+filepaths1, 10) gtest.Assert(err, nil) - err = Truncate("", 200) + //=========================检查修改文后的大小,是否与期望一致 + files, err = os.Open(Testpath() + filepaths1) + defer files.Close() + gtest.Assert(err, nil) + fileinfo, err2 := files.Stat() + gtest.Assert(err2, nil) + gtest.Assert(fileinfo.Size(), 10) + + //====测试当为空时,是否报错 + err = Truncate("", 10) gtest.AssertNE(err, nil) })