Skip to content

Commit

Permalink
test: ✅ add ut (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
Equationzhao committed May 13, 2024
1 parent 85f8f8a commit 1754205
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 2 additions & 5 deletions internal/content/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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

Expand Down
24 changes: 21 additions & 3 deletions internal/content/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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))
}

0 comments on commit 1754205

Please sign in to comment.