From 175420594b999a5f6b93179c266f7f761fb729a0 Mon Sep 17 00:00:00 2001 From: equationzhao Date: Mon, 13 May 2024 22:01:21 +0800 Subject: [PATCH] test: :white_check_mark: add ut (#185) --- internal/content/name.go | 7 ++----- internal/content/name_test.go | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/content/name.go b/internal/content/name.go index 6875897..d5b9597 100644 --- a/internal/content/name.go +++ b/internal/content/name.go @@ -199,6 +199,7 @@ func checkIfEmpty(info *item.FileInfo) bool { if err == io.EOF { return true } + // meth Readdirnames contains nil check _, err = f.Readdirnames(1) return err == io.EOF } @@ -210,13 +211,9 @@ color: filetype->filename->fileext->file */ func (n *Name) Enable(renderer *render.Renderer) ContentOption { return func(info *item.FileInfo) (stringContent string, funcName string) { - name := info.Name() - color := "" - icon := "" - classify := "" + name, color, icon, classify, mounts := info.Name(), "", "", "", "" dereference := bytebufferpool.Get() defer bytebufferpool.Put(dereference) - mounts := "" mode := info.Mode() underline, bold, italics, faint, blink := false, false, false, false, false diff --git a/internal/content/name_test.go b/internal/content/name_test.go index 84f8f8f..7b8a174 100644 --- a/internal/content/name_test.go +++ b/internal/content/name_test.go @@ -2,9 +2,15 @@ package content import ( "errors" + "io" "io/fs" + "os" "reflect" "testing" + + "github.com/Equationzhao/g/internal/item" + "github.com/agiledragon/gomonkey/v2" + "github.com/zeebo/assert" ) func TestName_checkDereferenceErr(t *testing.T) { @@ -72,16 +78,15 @@ func TestName_checkDereferenceErr(t *testing.T) { // path string // want string // }{ -// // { // name: "root", // path: "/", -// want: "[/dev/disk3s1s1 (apfs)]", +// want: "[/dev/sda1 (apfs)]", // }, // { // name: "dev", // path: "/dev", -// want: "[devfs (devfs)]", +// want: "[/devfs (apfs)]", // }, // { // "not found", @@ -138,3 +143,16 @@ func TestStatistics_MarshalJSON(t *testing.T) { }) } } + +func Test_checkIfEmpty(t *testing.T) { + patch := gomonkey.ApplyFuncReturn(os.Open, nil, io.EOF) + defer patch.Reset() + + i := item.FileInfo{ + FullPath: "test", + } + assert.True(t, checkIfEmpty(&i)) + + patch.ApplyFuncReturn(os.Open, nil, io.ErrUnexpectedEOF) + assert.True(t, checkIfEmpty(&i)) +}