fork/gdu
git clone https://git.julia.blue/fork/gdu
34f3996
master
1package webui 2 3import ( 4"path/filepath" 5"testing" 6 7"github.com/dundee/gdu/v5/pkg/analyze" 8"github.com/dundee/gdu/v5/pkg/fs" 9) 10 11func TestAnalyzePathsGroupsRootsUnderVirtualDir (t * testing.T ) { 12ui := newTestUI () 13first := makeTree (t ) 14second := makeTree (t ) 15 16if err := ui .AnalyzePaths ([]string {first ,second });err != nil { 17t .Fatalf ("AnalyzePaths: %v" ,err ) 18 } 19waitDone (t ,ui ) 20 21if ! analyze .IsVirtualRootDir (ui .topDir ) { 22t .Fatalf ("expected virtual root, got %T named %q" ,ui .topDir ,ui .topDir .GetName ()) 23 } 24if ui .topDirPath != analyze .VirtualRootName { 25t .Errorf ("topDirPath = %q, want %q" ,ui .topDirPath ,analyze .VirtualRootName ) 26 } 27 28// both roots are reachable and keep their real paths 29for _ ,path := range []string {first ,second } { 30if _ ,err := ui .findNode (path );err != nil { 31t .Errorf ("findNode(%q): %v" ,path ,err ) 32 } 33 } 34 35// so is a directory inside one of them 36if _ ,err := ui .findNode (filepath .Join (first ,"sub" ));err != nil { 37t .Errorf ("findNode(sub of first root): %v" ,err ) 38 } 39 40// and the virtual root itself, as reached from a breadcrumb 41node ,err := ui .findNode (analyze .VirtualRootName ) 42if err != nil { 43t .Fatalf ("findNode(virtual root): %v" ,err ) 44 } 45resp := buildNodeResponse (node ,fs .SortBySize ,fs .SortDesc ) 46if len (resp .Children )!= 2 { 47t .Fatalf ("virtual root has %d children, want 2" ,len (resp .Children )) 48 } 49 50// roots are labelled by absolute path, as their base names can collide 51for _ ,child := range resp .Children { 52if child .Name != child .Path { 53t .Errorf ("root labelled %q, want its path %q" ,child .Name ,child .Path ) 54 } 55 } 56} 57 58func TestFindNodeRejectsPathOutsideEveryRoot (t * testing.T ) { 59ui := newTestUI () 60 61if err := ui .AnalyzePaths ([]string {makeTree (t ),makeTree (t )});err != nil { 62t .Fatalf ("AnalyzePaths: %v" ,err ) 63 } 64waitDone (t ,ui ) 65 66if _ ,err := ui .findNode (filepath .Join (t .TempDir (),"elsewhere" ));err == nil { 67t .Error ("expected an error for a path outside every scanned root" ) 68 } 69} 70 71func TestAnalyzePathsWithSinglePathHasNoVirtualDir (t * testing.T ) { 72ui := newTestUI () 73root := makeTree (t ) 74 75if err := ui .AnalyzePaths ([]string {root });err != nil { 76t .Fatalf ("AnalyzePaths: %v" ,err ) 77 } 78waitDone (t ,ui ) 79 80if analyze .IsVirtualRootDir (ui .topDir ) { 81t .Error ("single path must not be wrapped in a virtual root" ) 82 } 83if ui .topDirPath != root { 84t .Errorf ("topDirPath = %q, want %q" ,ui .topDirPath ,root ) 85 } 86}