2020-09-15 04:44:53 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestWriteCurrentShell(t *testing.T) {
|
|
|
|
expected := "zsh"
|
|
|
|
env := new(MockedEnvironment)
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("Shell").Return(expected, nil)
|
2020-09-15 04:44:53 -07:00
|
|
|
s := &shell{
|
2022-01-01 11:08:08 -08:00
|
|
|
env: env,
|
|
|
|
props: properties{},
|
2020-09-15 04:44:53 -07:00
|
|
|
}
|
2022-01-22 10:46:56 -08:00
|
|
|
_ = s.enabled()
|
2022-01-23 12:37:51 -08:00
|
|
|
assert.Equal(t, expected, renderTemplate(env, s.template(), s))
|
2020-09-20 10:13:37 -07:00
|
|
|
}
|
2021-09-17 12:48:00 -07:00
|
|
|
|
|
|
|
func TestUseMappedShellNames(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Shell string
|
|
|
|
Expected string
|
|
|
|
}{
|
|
|
|
{Shell: "zsh", Expected: "zsh"},
|
|
|
|
{Shell: "pwsh", Expected: "PS"},
|
|
|
|
{Shell: "PWSH", Expected: "PS"},
|
|
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
|
|
env := new(MockedEnvironment)
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("Shell").Return(tc.Expected, nil)
|
2021-09-17 12:48:00 -07:00
|
|
|
s := &shell{
|
|
|
|
env: env,
|
2022-01-01 11:08:08 -08:00
|
|
|
props: properties{
|
2021-11-26 01:37:33 -08:00
|
|
|
MappedShellNames: map[string]string{"pwsh": "PS"},
|
2021-09-17 12:48:00 -07:00
|
|
|
},
|
|
|
|
}
|
2022-01-22 10:46:56 -08:00
|
|
|
_ = s.enabled()
|
2022-01-23 12:37:51 -08:00
|
|
|
got := renderTemplate(env, s.template(), s)
|
2021-09-17 12:48:00 -07:00
|
|
|
assert.Equal(t, tc.Expected, got)
|
|
|
|
}
|
|
|
|
}
|