Skip to content

Commit

Permalink
Powershell instead that's installed right?
Browse files Browse the repository at this point in the history
  • Loading branch information
arran4 committed Aug 3, 2023
1 parent dee54db commit 2518e2e
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/chezmoi/lookpathin_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build !windows

package chezmoi

import "testing"

func TestLookPathIn(t *testing.T) {
tests := []struct {
name string
file string
paths string
want string
wantErr bool
}{
{
name: "Finds first",
file: "sh",
paths: "/usr/bin:/bin",
want: "/usr/bin/sh",
wantErr: false,
},
{
name: "Finds first 2",
file: "sh",
paths: "/bin:/usr/bin",
want: "/bin/sh",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := LookPathIn(tt.args.file, tt.args.paths)
if (err != nil) != tt.wantErr {
t.Errorf("LookPathIn() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("LookPathIn() got = %v, want %v", got, tt.want)
}
})
}
}
59 changes: 59 additions & 0 deletions internal/chezmoi/lookpathin_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//go:build windows

package chezmoi

import (
"strings"
"testing"
)

func TestLookPathIn(t *testing.T) {
tests := []struct {
name string
file string
paths string
want string
wantErr bool
}{
{
name: "Finds with extension",
file: "powershell.exe",
paths: "c:\\windows\\system32;c:\\windows\\system64;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0",
want: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
wantErr: false,
},
{
name: "Finds without extension",
file: "powershell",
paths: "c:\\windows\\system32;c:\\windows\\system64;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0",
want: "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
wantErr: false,
},
{
name: "Fails to find with extension",
file: "weakshell.exe",
paths: "c:\\windows\\system32;c:\\windows\\system64;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0",
want: "",
wantErr: false,
},
{
name: "Fails to find without extension",
file: "weakshell",
paths: "c:\\windows\\system32;c:\\windows\\system64;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0",
want: "",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := LookPathIn(tt.file, tt.paths)
if (err != nil) != tt.wantErr {
t.Errorf("LookPathIn() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !strings.EqualFold(got, tt.want) {
t.Errorf("LookPathIn() got = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 2518e2e

Please sign in to comment.