forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
segment_kubectl_test.go
51 lines (44 loc) · 1.05 KB
/
segment_kubectl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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())
}
func TestKubectlNoContext(t *testing.T) {
args := &kubectlArgs{
enabled: true,
contextName: "",
}
kubectl := bootStrapKubectlTest(args)
assert.False(t, kubectl.enabled())
}