mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package alias
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestDetectShell(t *testing.T) {
|
||
|
|
cases := []struct {
|
||
|
|
name string
|
||
|
|
shellEnvValue string
|
||
|
|
want string
|
||
|
|
wantErr error
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "bash full path",
|
||
|
|
shellEnvValue: "/bin/bash",
|
||
|
|
want: "bash",
|
||
|
|
wantErr: nil,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "zsh full path",
|
||
|
|
shellEnvValue: "/bin/zsh",
|
||
|
|
want: "zsh",
|
||
|
|
wantErr: nil,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "bash only name",
|
||
|
|
shellEnvValue: "bash",
|
||
|
|
want: "bash",
|
||
|
|
wantErr: nil,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "when shell env is not set",
|
||
|
|
shellEnvValue: "",
|
||
|
|
want: "",
|
||
|
|
wantErr: fmt.Errorf("SHELL environment variable not set"),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tc := range cases {
|
||
|
|
t.Run(tc.name, func(t *testing.T) {
|
||
|
|
t.Setenv("SHELL", tc.shellEnvValue)
|
||
|
|
got, err := DetectShell()
|
||
|
|
|
||
|
|
if tc.wantErr != nil {
|
||
|
|
assert.ErrorContains(t, err, tc.wantErr.Error())
|
||
|
|
} else {
|
||
|
|
assert.NoError(t, err)
|
||
|
|
assert.Equal(t, tc.want, got)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|