fork/gdu
git clone https://git.julia.blue/fork/gdu
1eaa266
subvolume
1package tui 2 3import ( 4"bytes" 5"testing" 6 7"github.com/dundee/gdu/v5/internal/testapp" 8"github.com/dundee/gdu/v5/pkg/analyze" 9) 10 11func newSymlinkTestFile ()* analyze.File { 12dir := & analyze.Dir { 13File :& analyze.File { 14Name :"test_dir" , 15Usage :100 , 16 }, 17 } 18return & analyze.File { 19Name :"bin" , 20Parent :dir , 21Usage :4 , 22Size :7 , 23Flag :'@' , 24Symlink :"usr/bin" , 25 } 26} 27 28func TestFormatSymlinkRow (t * testing.T ) { 29simScreen := testapp .CreateSimScreen () 30defer simScreen .Fini () 31 32app := testapp .CreateMockedApp (true ) 33ui := CreateUI (app ,simScreen ,& bytes.Buffer {},true ,false ,false ,false ) 34ui .SetShowSymlinkTarget (true ) 35 36symlinkRow := ui .formatFileRow (newSymlinkTestFile (),100 ,100 ,false ,false ) 37 38if ! bytes .Contains ([]byte (symlinkRow ), []byte ("[aqua::b]" )) { 39t .Error ("symlink row should contain [aqua::b]" ) 40 } 41if ! bytes .Contains ([]byte (symlinkRow ), []byte ("-> usr/bin" )) { 42t .Error ("symlink row should contain '-> usr/bin'" ) 43 } 44} 45 46func TestFormatSymlinkRowDisabledByDefault (t * testing.T ) { 47simScreen := testapp .CreateSimScreen () 48defer simScreen .Fini () 49 50app := testapp .CreateMockedApp (true ) 51ui := CreateUI (app ,simScreen ,& bytes.Buffer {},true ,false ,false ,false ) 52 53symlinkRow := ui .formatFileRow (newSymlinkTestFile (),100 ,100 ,false ,false ) 54 55if bytes .Contains ([]byte (symlinkRow ), []byte ("-> usr/bin" )) { 56t .Error ("symlink target should not be shown when the option is disabled" ) 57 } 58if ! bytes .Contains ([]byte (symlinkRow ), []byte ("bin" )) { 59t .Error ("symlink row should still show the name" ) 60 } 61} 62 63func TestSymlinkTargetInfoLine (t * testing.T ) { 64simScreen := testapp .CreateSimScreen () 65defer simScreen .Fini () 66 67app := testapp .CreateMockedApp (true ) 68ui := CreateUI (app ,simScreen ,& bytes.Buffer {},true ,false ,false ,false ) 69ui .SetShowSymlinkTarget (true ) 70 71line := ui .symlinkTargetInfoLine (newSymlinkTestFile ()) 72if ! bytes .Contains ([]byte (line ), []byte ("Target:" )) { 73t .Errorf ("info line should contain 'Target:', got %q" ,line ) 74 } 75if ! bytes .Contains ([]byte (line ), []byte ("usr/bin" )) { 76t .Errorf ("info line should contain 'usr/bin', got %q" ,line ) 77 } 78} 79 80func TestSymlinkTargetInfoLineDisabledByDefault (t * testing.T ) { 81simScreen := testapp .CreateSimScreen () 82defer simScreen .Fini () 83 84app := testapp .CreateMockedApp (true ) 85ui := CreateUI (app ,simScreen ,& bytes.Buffer {},true ,false ,false ,false ) 86 87if line := ui .symlinkTargetInfoLine (newSymlinkTestFile ());line != "" { 88t .Errorf ("info line should be empty when the option is disabled, got %q" ,line ) 89 } 90} 91 92func TestSymlinkTargetInfoLineForNonSymlink (t * testing.T ) { 93simScreen := testapp .CreateSimScreen () 94defer simScreen .Fini () 95 96app := testapp .CreateMockedApp (true ) 97ui := CreateUI (app ,simScreen ,& bytes.Buffer {},true ,false ,false ,false ) 98ui .SetShowSymlinkTarget (true ) 99 100regular := & analyze.File {Name :"file" ,Size :5 } 101if line := ui .symlinkTargetInfoLine (regular );line != "" { 102t .Errorf ("non-symlink should produce empty info line, got %q" ,line ) 103 } 104}