-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcloud_deploy_exec_test.go
88 lines (68 loc) · 2.24 KB
/
cloud_deploy_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package commands
import (
"errors"
"kool-dev/kool/core/builder"
"kool-dev/kool/core/environment"
"kool-dev/kool/services/cloud/k8s"
"strings"
"testing"
)
func newFakeKoolDeployExec() *KoolDeployExec {
return &KoolDeployExec{
*(newDefaultKoolService().Fake()),
&KoolDeployExecFlags{},
environment.NewFakeEnvStorage(),
&fakeK8S{},
}
}
func TestNewKoolDeployExec(t *testing.T) {
e := NewKoolDeployExec()
if _, ok := e.env.(*environment.DefaultEnvStorage); !ok {
t.Errorf("unexpected type for env storage")
}
if _, ok := e.cloud.(*k8s.DefaultK8S); !ok {
t.Errorf("unexpected type for apiExec endpoint")
}
}
func TestKoolDeployExec(t *testing.T) {
e := newFakeKoolDeployExec()
err := e.Execute([]string{})
if err == nil || !strings.Contains(err.Error(), "required at least one argument") {
t.Errorf("expected: missing required parameter; got something else")
}
var args = []string{"my-service"}
if err = e.Execute(args); err == nil || !strings.Contains(err.Error(), "missing deploy domain") {
t.Errorf("expected: missing deploy domain; got something else")
}
var domain string = "example.com"
e.env.Set("KOOL_DEPLOY_DOMAIN", domain)
mock := e.cloud.(*fakeK8S)
mock.MockAuthenticateErr = errors.New("auth error")
if err = e.Execute(args); !errors.Is(err, mock.MockAuthenticateErr) {
t.Error("should return auth error")
}
mock.MockAuthenticateErr = nil
mock.MockAuthenticateCloudService = "cloud-service"
mock.MockKubectlErr = errors.New("kube error")
if err = e.Execute(args); !errors.Is(err, mock.MockKubectlErr) {
t.Error("should return kube error")
}
fakeKubectl := &builder.FakeCommand{}
mock.MockKubectlErr = nil
mock.MockKubectlKube = fakeKubectl
fakeKubectl.MockInteractiveError = errors.New("interactive error")
if err = e.Execute(args); !errors.Is(err, fakeKubectl.MockInteractiveError) {
t.Error("should return interactive error")
}
fakeKubectl = &builder.FakeCommand{}
mock.MockKubectlKube = fakeKubectl
fakeKubectl.MockInteractiveError = nil
e.Flags.Container = "foo"
if err = e.Execute(args); err != nil {
t.Error("unexpected error")
}
str := strings.Join(fakeKubectl.ArgsAppend, " ")
if !strings.Contains(str, "exec -i -t cloud-service -c foo -- bash") {
t.Error("bad kubectl command args")
}
}