Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix(cli): remove returned error from getHomeUserDirs function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtagscherer committed Jan 19, 2024
1 parent 0db96b6 commit 510c6a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
10 changes: 3 additions & 7 deletions pkg/shared/families/infofinder/sshtopology/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
defer cleanup()

var errs []error
homeUserDirs, err := getHomeUserDirs(fsPath)
if err != nil {
// Collect the error and continue.
errs = append(errs, fmt.Errorf("failed to get home user dirs: %w", err))
}
homeUserDirs := getHomeUserDirs(fsPath)
s.logger.Debugf("Found home user dirs %+v", homeUserDirs)

errorsChan := make(chan error)
Expand Down Expand Up @@ -172,7 +168,7 @@ func (s *Scanner) Run(sourceType utils.SourceType, userInput string) error {
return nil
}

func getHomeUserDirs(rootDir string) ([]string, error) {
func getHomeUserDirs(rootDir string) []string {
var dirs []string

// Set root home if exists.
Expand All @@ -190,7 +186,7 @@ func getHomeUserDirs(rootDir string) ([]string, error) {
}
}

return dirs, nil
return dirs
}

func (s *Scanner) getSSHDaemonKeysFingerprints(rootPath string) ([]types.Info, error) {
Expand Down
26 changes: 6 additions & 20 deletions pkg/shared/families/infofinder/sshtopology/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,28 @@ func Test_getHomeUserDirs(t *testing.T) {
rootDir string
}
tests := []struct {
name string
args args
want []string
wantErr bool
name string
args args
want []string
}{
{
name: "sanity",
args: args{
rootDir: "../testdata/rootfolder",
},
want: []string{"../testdata/rootfolder/home/dir1", "../testdata/rootfolder/home/dir2"},
wantErr: false,
want: []string{"../testdata/rootfolder/home/dir1", "../testdata/rootfolder/home/dir2"},
},
{
name: "root folder with root home folder",
args: args{
rootDir: "../testdata/rootfolderwithroothome",
},
want: []string{"../testdata/rootfolderwithroothome/root", "../testdata/rootfolderwithroothome/home/dir1", "../testdata/rootfolderwithroothome/home/dir2"},
wantErr: false,
},
{
name: "missing dir",
args: args{
rootDir: "../testdata/missingrootfolder",
},
wantErr: true,
want: []string{"../testdata/rootfolderwithroothome/root", "../testdata/rootfolderwithroothome/home/dir1", "../testdata/rootfolderwithroothome/home/dir2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := getHomeUserDirs(tt.args.rootDir)
if (err != nil) != tt.wantErr {
t.Errorf("getHomeUserDirs() error = %v, wantErr %v", err, tt.wantErr)
return
}
got := getHomeUserDirs(tt.args.rootDir)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("getHomeUserDirs() got = %v, want %v", got, tt.want)
}
Expand Down

0 comments on commit 510c6a4

Please sign in to comment.