oh-my-posh/segment_kubectl_test.go
Travis Illig 5844faa54d feat: dotnet segment for .NET SDK display
New segment for .NET SDK version (or unsupported version) display.

Includes update for handling command execution errors so segments
can act differently based on exit codes. Using a custom error
type to make it testable rather than passing the OS error directly
to the segment.
2020-10-16 11:39:01 -07:00

43 lines
886 B
Go
Executable file

package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
type kubectlArgs struct {
enabled bool
contextName string
}
func bootStrapKubectlTest(args *kubectlArgs) *kubectl {
env := new(MockedEnvironment)
env.On("hasCommand", "kubectl").Return(args.enabled)
env.On("runCommand", "kubectl", []string{"config", "current-context"}).Return(args.contextName, nil)
k := &kubectl{
env: env,
props: &properties{},
}
return k
}
func TestKubectlWriterDisabled(t *testing.T) {
args := &kubectlArgs{
enabled: false,
}
kubectl := bootStrapKubectlTest(args)
assert.False(t, kubectl.enabled())
}
func TestKubectlEnabled(t *testing.T) {
expected := "context-name"
args := &kubectlArgs{
enabled: true,
contextName: expected,
}
kubectl := bootStrapKubectlTest(args)
assert.True(t, kubectl.enabled())
assert.Equal(t, expected, kubectl.string())
}