-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexec_test.go
52 lines (43 loc) · 1.13 KB
/
exec_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
52
package kube
import (
"context"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const (
_defaultTestNamespace = "ingress-nginx"
_defaultTestPod = "nginx"
)
func TestClientExec(t *testing.T) {
podName, containerName, podNamespace := getResourceNames(t)
t.Log("exec:", podName, containerName)
stdout, _, err := mockcli.Exec(podName, containerName, podNamespace, "echo", "hello")
require.NoError(t, err)
t.Log(stdout)
assert.Equal(t, "hello", stdout)
}
func getResourceNames(t *testing.T) (podName, containerName, podNamespace string) {
podNamespace = _defaultTestNamespace
podName = _defaultTestPod
if namespace != "" {
podNamespace = namespace
}
if podname != "" && containername != "" {
podName = podname
containerName = containername
} else {
list, err := mockcli.GetPods(context.TODO(), podNamespace)
require.NoError(t, err)
require.NotEqual(t, len(list.Items), 0)
for _, v := range list.Items {
if strings.Contains(strings.ToLower(v.Name), podName) {
podName = v.Name
containerName = v.Spec.Containers[0].Name
break
}
}
}
return
}