Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Kt Connect
Commits
21a4a484
Commit
21a4a484
authored
3 years ago
by
LiHui
Browse files
Options
Download
Email Patches
Plain Diff
Update test
parent
38f568e3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
pkg/kt/cluster/helper_test.go
+2
-1
pkg/kt/cluster/helper_test.go
pkg/kt/cluster/kubernetes_test.go
+5
-4
pkg/kt/cluster/kubernetes_test.go
pkg/kt/cluster/mock.go
+57
-56
pkg/kt/cluster/mock.go
pkg/kt/command/connect_test.go
+9
-8
pkg/kt/command/connect_test.go
pkg/kt/command/provide_test.go
+7
-6
pkg/kt/command/provide_test.go
with
80 additions
and
75 deletions
+80
-75
pkg/kt/cluster/helper_test.go
+
2
-
1
View file @
21a4a484
package
cluster
import
(
"context"
"reflect"
"testing"
...
...
@@ -44,7 +45,7 @@ func Test_getPodCidrs(t *testing.T) {
client
:=
testclient
.
NewSimpleClientset
(
tt
.
objs
...
)
gotCidrs
,
err
:=
getPodCidrs
(
client
,
""
)
gotCidrs
,
err
:=
getPodCidrs
(
context
.
TODO
(),
client
,
""
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"getPodCidrs() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
This diff is collapsed.
Click to expand it.
pkg/kt/cluster/kubernetes_test.go
+
5
-
4
View file @
21a4a484
package
cluster
import
(
"context"
"github.com/alibaba/kt-connect/pkg/common"
"github.com/alibaba/kt-connect/pkg/kt/options"
"github.com/alibaba/kt-connect/pkg/kt/util"
...
...
@@ -70,7 +71,7 @@ func TestKubernetes_CreateShadow(t *testing.T) {
envs
:=
make
(
map
[
string
]
string
)
annotations
:=
make
(
map
[
string
]
string
)
option
:=
options
.
DaemonOptions
{
Namespace
:
tt
.
args
.
namespace
,
Image
:
tt
.
args
.
image
,
Debug
:
tt
.
args
.
debug
}
gotPodIP
,
gotPodName
,
gotSshcm
,
_
,
err
:=
k
.
GetOrCreateShadow
(
tt
.
args
.
name
,
&
option
,
tt
.
args
.
labels
,
annotations
,
envs
)
gotPodIP
,
gotPodName
,
gotSshcm
,
_
,
err
:=
k
.
GetOrCreateShadow
(
context
.
TODO
(),
tt
.
args
.
name
,
&
option
,
tt
.
args
.
labels
,
annotations
,
envs
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Kubernetes.GetOrCreateShadow() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
@@ -126,7 +127,7 @@ func TestKubernetes_ClusterCidrs(t *testing.T) {
ops
:=
&
options
.
ConnectOptions
{
CIDR
:
tt
.
args
.
podCIDR
,
}
gotCidrs
,
err
:=
k
.
ClusterCidrs
(
"default"
,
ops
)
gotCidrs
,
err
:=
k
.
ClusterCidrs
(
context
.
TODO
(),
"default"
,
ops
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Kubernetes.ClusterCidrs() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
@@ -168,7 +169,7 @@ func TestKubernetes_CreateService(t *testing.T) {
k
:=
&
Kubernetes
{
Clientset
:
testclient
.
NewSimpleClientset
(),
}
_
,
err
:=
k
.
CreateService
(
tt
.
args
.
name
,
tt
.
args
.
namespace
,
false
,
tt
.
args
.
port
,
tt
.
args
.
labels
)
_
,
err
:=
k
.
CreateService
(
context
.
TODO
(),
tt
.
args
.
name
,
tt
.
args
.
namespace
,
false
,
tt
.
args
.
port
,
tt
.
args
.
labels
)
if
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Kubernetes.CreateService() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
return
...
...
@@ -212,7 +213,7 @@ func TestKubernetes_ScaleTo(t *testing.T) {
k
:=
&
Kubernetes
{
Clientset
:
testclient
.
NewSimpleClientset
(
tt
.
objs
...
),
}
if
err
:=
k
.
ScaleTo
(
tt
.
args
.
deployment
,
tt
.
args
.
namespace
,
&
tt
.
args
.
replicas
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
if
err
:=
k
.
ScaleTo
(
context
.
TODO
(),
tt
.
args
.
deployment
,
tt
.
args
.
namespace
,
&
tt
.
args
.
replicas
);
(
err
!=
nil
)
!=
tt
.
wantErr
{
t
.
Errorf
(
"Kubernetes.ScaleTo() error = %v, wantErr %v"
,
err
,
tt
.
wantErr
)
}
})
...
...
This diff is collapsed.
Click to expand it.
pkg/kt/cluster/mock.go
+
57
-
56
View file @
21a4a484
...
...
@@ -5,6 +5,7 @@
package
cluster
import
(
context
"context"
reflect
"reflect"
options
"github.com/alibaba/kt-connect/pkg/kt/options"
...
...
@@ -38,99 +39,99 @@ func (m *MockKubernetesInterface) EXPECT() *MockKubernetesInterfaceMockRecorder
}
// ClusterCidrs mocks base method.
func
(
m
*
MockKubernetesInterface
)
ClusterCidrs
(
namespace
string
,
connectOptions
*
options
.
ConnectOptions
)
([]
string
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
ClusterCidrs
(
ctx
context
.
Context
,
namespace
string
,
connectOptions
*
options
.
ConnectOptions
)
([]
string
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"ClusterCidrs"
,
namespace
,
connectOptions
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"ClusterCidrs"
,
ctx
,
namespace
,
connectOptions
)
ret0
,
_
:=
ret
[
0
]
.
([]
string
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// ClusterCidrs indicates an expected call of ClusterCidrs.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ClusterCidrs
(
namespace
,
connectOptions
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ClusterCidrs
(
ctx
,
namespace
,
connectOptions
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ClusterCidrs"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ClusterCidrs
),
namespace
,
connectOptions
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ClusterCidrs"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ClusterCidrs
),
ctx
,
namespace
,
connectOptions
)
}
// CreateService mocks base method.
func
(
m
*
MockKubernetesInterface
)
CreateService
(
name
,
namespace
string
,
external
bool
,
port
int
,
labels
map
[
string
]
string
)
(
*
v10
.
Service
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
CreateService
(
ctx
context
.
Context
,
name
,
namespace
string
,
external
bool
,
port
int
,
labels
map
[
string
]
string
)
(
*
v10
.
Service
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"CreateService"
,
name
,
namespace
,
external
,
port
,
labels
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"CreateService"
,
ctx
,
name
,
namespace
,
external
,
port
,
labels
)
ret0
,
_
:=
ret
[
0
]
.
(
*
v10
.
Service
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// CreateService indicates an expected call of CreateService.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
CreateService
(
name
,
namespace
,
external
,
port
,
labels
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
CreateService
(
ctx
,
name
,
namespace
,
external
,
port
,
labels
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"CreateService"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
CreateService
),
name
,
namespace
,
external
,
port
,
labels
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"CreateService"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
CreateService
),
ctx
,
name
,
namespace
,
external
,
port
,
labels
)
}
// DecreaseRef mocks base method.
func
(
m
*
MockKubernetesInterface
)
DecreaseRef
(
namespace
,
deployment
string
)
(
bool
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
DecreaseRef
(
ctx
context
.
Context
,
namespace
,
deployment
string
)
(
bool
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"DecreaseRef"
,
namespace
,
deployment
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"DecreaseRef"
,
ctx
,
namespace
,
deployment
)
ret0
,
_
:=
ret
[
0
]
.
(
bool
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// DecreaseRef indicates an expected call of DecreaseRef.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
DecreaseRef
(
namespace
,
deployment
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
DecreaseRef
(
ctx
,
namespace
,
deployment
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"DecreaseRef"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
DecreaseRef
),
namespace
,
deployment
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"DecreaseRef"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
DecreaseRef
),
ctx
,
namespace
,
deployment
)
}
// Deployment mocks base method.
func
(
m
*
MockKubernetesInterface
)
Deployment
(
name
,
namespace
string
)
(
*
v1
.
Deployment
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
Deployment
(
ctx
context
.
Context
,
name
,
namespace
string
)
(
*
v1
.
Deployment
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"Deployment"
,
name
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"Deployment"
,
ctx
,
name
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
*
v1
.
Deployment
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// Deployment indicates an expected call of Deployment.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
Deployment
(
name
,
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
Deployment
(
ctx
,
name
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Deployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
Deployment
),
name
,
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Deployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
Deployment
),
ctx
,
name
,
namespace
)
}
// GetAllExistingShadowDeployments mocks base method.
func
(
m
*
MockKubernetesInterface
)
GetAllExistingShadowDeployments
(
namespace
string
)
([]
v1
.
Deployment
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
GetAllExistingShadowDeployments
(
ctx
context
.
Context
,
namespace
string
)
([]
v1
.
Deployment
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetAllExistingShadowDeployments"
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetAllExistingShadowDeployments"
,
ctx
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
([]
v1
.
Deployment
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// GetAllExistingShadowDeployments indicates an expected call of GetAllExistingShadowDeployments.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetAllExistingShadowDeployments
(
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetAllExistingShadowDeployments
(
ctx
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetAllExistingShadowDeployments"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetAllExistingShadowDeployments
),
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetAllExistingShadowDeployments"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetAllExistingShadowDeployments
),
ctx
,
namespace
)
}
// GetDeployment mocks base method.
func
(
m
*
MockKubernetesInterface
)
GetDeployment
(
name
,
namespace
string
)
(
*
v1
.
Deployment
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
GetDeployment
(
ctx
context
.
Context
,
name
,
namespace
string
)
(
*
v1
.
Deployment
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetDeployment"
,
name
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetDeployment"
,
ctx
,
name
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
*
v1
.
Deployment
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// GetDeployment indicates an expected call of GetDeployment.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetDeployment
(
name
,
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetDeployment
(
ctx
,
name
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetDeployment
),
name
,
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetDeployment
),
ctx
,
name
,
namespace
)
}
// GetOrCreateShadow mocks base method.
func
(
m
*
MockKubernetesInterface
)
GetOrCreateShadow
(
name
string
,
options
*
options
.
DaemonOptions
,
labels
,
annotations
,
envs
map
[
string
]
string
)
(
string
,
string
,
string
,
*
util
.
SSHCredential
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
GetOrCreateShadow
(
ctx
context
.
Context
,
name
string
,
options
*
options
.
DaemonOptions
,
labels
,
annotations
,
envs
map
[
string
]
string
)
(
string
,
string
,
string
,
*
util
.
SSHCredential
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetOrCreateShadow"
,
name
,
options
,
labels
,
annotations
,
envs
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"GetOrCreateShadow"
,
ctx
,
name
,
options
,
labels
,
annotations
,
envs
)
ret0
,
_
:=
ret
[
0
]
.
(
string
)
ret1
,
_
:=
ret
[
1
]
.
(
string
)
ret2
,
_
:=
ret
[
2
]
.
(
string
)
...
...
@@ -140,106 +141,106 @@ func (m *MockKubernetesInterface) GetOrCreateShadow(name string, options *option
}
// GetOrCreateShadow indicates an expected call of GetOrCreateShadow.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetOrCreateShadow
(
name
,
options
,
labels
,
annotations
,
envs
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
GetOrCreateShadow
(
ctx
,
name
,
options
,
labels
,
annotations
,
envs
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetOrCreateShadow"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetOrCreateShadow
),
name
,
options
,
labels
,
annotations
,
envs
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"GetOrCreateShadow"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
GetOrCreateShadow
),
ctx
,
name
,
options
,
labels
,
annotations
,
envs
)
}
// RemoveConfigMap mocks base method.
func
(
m
*
MockKubernetesInterface
)
RemoveConfigMap
(
name
,
namespace
string
)
error
{
func
(
m
*
MockKubernetesInterface
)
RemoveConfigMap
(
ctx
context
.
Context
,
name
,
namespace
string
)
error
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveConfigMap"
,
name
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveConfigMap"
,
ctx
,
name
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
}
// RemoveConfigMap indicates an expected call of RemoveConfigMap.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveConfigMap
(
name
,
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveConfigMap
(
ctx
,
name
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveConfigMap"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveConfigMap
),
name
,
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveConfigMap"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveConfigMap
),
ctx
,
name
,
namespace
)
}
// RemoveDeployment mocks base method.
func
(
m
*
MockKubernetesInterface
)
RemoveDeployment
(
name
,
namespace
string
)
error
{
func
(
m
*
MockKubernetesInterface
)
RemoveDeployment
(
ctx
context
.
Context
,
name
,
namespace
string
)
error
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveDeployment"
,
name
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveDeployment"
,
ctx
,
name
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
}
// RemoveDeployment indicates an expected call of RemoveDeployment.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveDeployment
(
name
,
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveDeployment
(
ctx
,
name
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveDeployment
),
name
,
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveDeployment
),
ctx
,
name
,
namespace
)
}
// RemoveService mocks base method.
func
(
m
*
MockKubernetesInterface
)
RemoveService
(
name
,
namespace
string
)
error
{
func
(
m
*
MockKubernetesInterface
)
RemoveService
(
ctx
context
.
Context
,
name
,
namespace
string
)
error
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveService"
,
name
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"RemoveService"
,
ctx
,
name
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
}
// RemoveService indicates an expected call of RemoveService.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveService
(
name
,
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
RemoveService
(
ctx
,
name
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveService"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveService
),
name
,
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"RemoveService"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
RemoveService
),
ctx
,
name
,
namespace
)
}
// Scale mocks base method.
func
(
m
*
MockKubernetesInterface
)
Scale
(
deployment
*
v1
.
Deployment
,
replicas
*
int32
)
error
{
func
(
m
*
MockKubernetesInterface
)
Scale
(
ctx
context
.
Context
,
deployment
*
v1
.
Deployment
,
replicas
*
int32
)
error
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"Scale"
,
deployment
,
replicas
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"Scale"
,
ctx
,
deployment
,
replicas
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
}
// Scale indicates an expected call of Scale.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
Scale
(
deployment
,
replicas
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
Scale
(
ctx
,
deployment
,
replicas
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Scale"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
Scale
),
deployment
,
replicas
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"Scale"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
Scale
),
ctx
,
deployment
,
replicas
)
}
// ScaleTo mocks base method.
func
(
m
*
MockKubernetesInterface
)
ScaleTo
(
deployment
,
namespace
string
,
replicas
*
int32
)
error
{
func
(
m
*
MockKubernetesInterface
)
ScaleTo
(
ctx
context
.
Context
,
deployment
,
namespace
string
,
replicas
*
int32
)
error
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"ScaleTo"
,
deployment
,
namespace
,
replicas
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"ScaleTo"
,
ctx
,
deployment
,
namespace
,
replicas
)
ret0
,
_
:=
ret
[
0
]
.
(
error
)
return
ret0
}
// ScaleTo indicates an expected call of ScaleTo.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ScaleTo
(
deployment
,
namespace
,
replicas
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ScaleTo
(
ctx
,
deployment
,
namespace
,
replicas
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ScaleTo"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ScaleTo
),
deployment
,
namespace
,
replicas
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ScaleTo"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ScaleTo
),
ctx
,
deployment
,
namespace
,
replicas
)
}
// ServiceHosts mocks base method.
func
(
m
*
MockKubernetesInterface
)
ServiceHosts
(
namespace
string
)
map
[
string
]
string
{
func
(
m
*
MockKubernetesInterface
)
ServiceHosts
(
ctx
context
.
Context
,
namespace
string
)
map
[
string
]
string
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"ServiceHosts"
,
namespace
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"ServiceHosts"
,
ctx
,
namespace
)
ret0
,
_
:=
ret
[
0
]
.
(
map
[
string
]
string
)
return
ret0
}
// ServiceHosts indicates an expected call of ServiceHosts.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ServiceHosts
(
namespace
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
ServiceHosts
(
ctx
,
namespace
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ServiceHosts"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ServiceHosts
),
namespace
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"ServiceHosts"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
ServiceHosts
),
ctx
,
namespace
)
}
// UpdateDeployment mocks base method.
func
(
m
*
MockKubernetesInterface
)
UpdateDeployment
(
namespace
string
,
deployment
*
v1
.
Deployment
)
(
*
v1
.
Deployment
,
error
)
{
func
(
m
*
MockKubernetesInterface
)
UpdateDeployment
(
ctx
context
.
Context
,
namespace
string
,
deployment
*
v1
.
Deployment
)
(
*
v1
.
Deployment
,
error
)
{
m
.
ctrl
.
T
.
Helper
()
ret
:=
m
.
ctrl
.
Call
(
m
,
"UpdateDeployment"
,
namespace
,
deployment
)
ret
:=
m
.
ctrl
.
Call
(
m
,
"UpdateDeployment"
,
ctx
,
namespace
,
deployment
)
ret0
,
_
:=
ret
[
0
]
.
(
*
v1
.
Deployment
)
ret1
,
_
:=
ret
[
1
]
.
(
error
)
return
ret0
,
ret1
}
// UpdateDeployment indicates an expected call of UpdateDeployment.
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
UpdateDeployment
(
namespace
,
deployment
interface
{})
*
gomock
.
Call
{
func
(
mr
*
MockKubernetesInterfaceMockRecorder
)
UpdateDeployment
(
ctx
,
namespace
,
deployment
interface
{})
*
gomock
.
Call
{
mr
.
mock
.
ctrl
.
T
.
Helper
()
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"UpdateDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
UpdateDeployment
),
namespace
,
deployment
)
return
mr
.
mock
.
ctrl
.
RecordCallWithMethodType
(
mr
.
mock
,
"UpdateDeployment"
,
reflect
.
TypeOf
((
*
MockKubernetesInterface
)(
nil
)
.
UpdateDeployment
),
ctx
,
namespace
,
deployment
)
}
This diff is collapsed.
Click to expand it.
pkg/kt/command/connect_test.go
+
9
-
8
View file @
21a4a484
package
command
import
(
"context"
"errors"
"flag"
"io/ioutil"
...
...
@@ -70,9 +71,9 @@ func Test_shouldConnectToCluster(t *testing.T) {
kubernetes
:=
cluster
.
NewMockKubernetesInterface
(
ctl
)
exec
:=
exec
.
NewMockCliInterface
(
ctl
)
shadow
:=
connect
.
NewMockShadowInterface
(
ctl
)
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
"172.168.0.2"
,
"shadowName"
,
"sshcm"
,
nil
,
nil
)
.
AnyTimes
()
kubernetes
.
EXPECT
()
.
ClusterCidrs
(
gomock
.
Any
(),
gomock
.
Any
())
.
Return
([]
string
{
"10.10.10.0/24"
},
nil
)
kubernetes
.
EXPECT
()
.
ClusterCidrs
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
([]
string
{
"10.10.10.0/24"
},
nil
)
shadow
.
EXPECT
()
.
Outbound
(
"shadowName"
,
"172.168.0.2"
,
gomock
.
Any
(),
[]
string
{
"10.10.10.0/24"
},
gomock
.
Any
())
.
Return
(
nil
)
ktctl
.
EXPECT
()
.
Shadow
()
.
AnyTimes
()
.
Return
(
shadow
)
...
...
@@ -82,7 +83,7 @@ func Test_shouldConnectToCluster(t *testing.T) {
opts
:=
options
.
NewDaemonOptions
()
opts
.
Labels
=
"a:b"
if
err
:=
connectToCluster
(
ktctl
,
opts
);
err
!=
nil
{
if
err
:=
connectToCluster
(
context
.
TODO
(),
ktctl
,
opts
);
err
!=
nil
{
t
.
Errorf
(
"connectToCluster() error = %v, wantErr %v"
,
err
,
false
)
}
...
...
@@ -95,13 +96,13 @@ func Test_shouldConnectClusterFailWhenFailCreateShadow(t *testing.T) {
kubernetes
:=
cluster
.
NewMockKubernetesInterface
(
ctl
)
shadow
:=
connect
.
NewMockShadowInterface
(
ctl
)
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
""
,
""
,
""
,
nil
,
errors
.
New
(
""
))
.
AnyTimes
()
ktctl
.
EXPECT
()
.
Shadow
()
.
AnyTimes
()
.
Return
(
shadow
)
ktctl
.
EXPECT
()
.
Kubernetes
()
.
AnyTimes
()
.
Return
(
kubernetes
,
nil
)
if
err
:=
connectToCluster
(
ktctl
,
options
.
NewDaemonOptions
());
err
==
nil
{
if
err
:=
connectToCluster
(
context
.
TODO
(),
ktctl
,
options
.
NewDaemonOptions
());
err
==
nil
{
t
.
Errorf
(
"connectToCluster() error = %v, wantErr %v"
,
err
,
true
)
}
...
...
@@ -115,9 +116,9 @@ func Test_shouldConnectClusterFailWhenFailGetCrids(t *testing.T) {
kubernetes
:=
cluster
.
NewMockKubernetesInterface
(
ctl
)
shadow
:=
connect
.
NewMockShadowInterface
(
ctl
)
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
(
"172.168.0.2"
,
"shadowName"
,
"sshcm"
,
nil
,
nil
)
.
AnyTimes
()
kubernetes
.
EXPECT
()
.
ClusterCidrs
(
gomock
.
Any
(),
gomock
.
Any
())
.
Return
([]
string
{},
errors
.
New
(
"fail to get cidr"
))
kubernetes
.
EXPECT
()
.
ClusterCidrs
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Return
([]
string
{},
errors
.
New
(
"fail to get cidr"
))
ktctl
.
EXPECT
()
.
Shadow
()
.
AnyTimes
()
.
Return
(
shadow
)
ktctl
.
EXPECT
()
.
Kubernetes
()
.
AnyTimes
()
.
Return
(
kubernetes
,
nil
)
...
...
@@ -125,7 +126,7 @@ func Test_shouldConnectClusterFailWhenFailGetCrids(t *testing.T) {
opts
:=
options
.
NewDaemonOptions
()
opts
.
Labels
=
"a:b"
if
err
:=
connectToCluster
(
ktctl
,
opts
);
err
==
nil
{
if
err
:=
connectToCluster
(
context
.
TODO
(),
ktctl
,
opts
);
err
==
nil
{
t
.
Errorf
(
"connectToCluster() error = %v, wantErr %v"
,
err
,
true
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/kt/command/provide_test.go
+
7
-
6
View file @
21a4a484
package
command
import
(
"context"
"errors"
"flag"
"io/ioutil"
...
...
@@ -91,12 +92,12 @@ func Test_shouldExposeLocalServiceToCluster(t *testing.T) {
},
}
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
Return
(
args
.
shadowResponse
.
podIP
,
args
.
shadowResponse
.
podName
,
args
.
shadowResponse
.
sshcm
,
args
.
shadowResponse
.
credential
,
args
.
shadowResponse
.
err
)
kubernetes
.
EXPECT
()
.
CreateService
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
Return
(
args
.
serviceResponse
.
service
,
args
.
serviceResponse
.
err
)
kubernetes
.
EXPECT
()
.
CreateService
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
Return
(
args
.
serviceResponse
.
service
,
args
.
serviceResponse
.
err
)
shadow
.
EXPECT
()
.
Inbound
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
Return
(
args
.
inboundResponse
.
err
)
if
err
:=
provide
(
args
.
service
,
fakeKtCli
,
args
.
options
);
err
!=
nil
{
if
err
:=
provide
(
context
.
TODO
(),
args
.
service
,
fakeKtCli
,
args
.
options
);
err
!=
nil
{
t
.
Errorf
(
"expect no error, actual is %v"
,
err
)
}
}
...
...
@@ -125,12 +126,12 @@ func Test_shouldExposeLocalServiceFailWhenShadowCreateFail(t *testing.T) {
},
}
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
kubernetes
.
EXPECT
()
.
GetOrCreateShadow
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
1
)
.
Return
(
args
.
shadowResponse
.
podIP
,
args
.
shadowResponse
.
podName
,
args
.
shadowResponse
.
sshcm
,
args
.
shadowResponse
.
credential
,
args
.
shadowResponse
.
err
)
kubernetes
.
EXPECT
()
.
CreateService
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
0
)
.
Return
(
args
.
serviceResponse
.
service
,
args
.
serviceResponse
.
err
)
kubernetes
.
EXPECT
()
.
CreateService
(
context
.
TODO
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
0
)
.
Return
(
args
.
serviceResponse
.
service
,
args
.
serviceResponse
.
err
)
shadow
.
EXPECT
()
.
Inbound
(
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
(),
gomock
.
Any
())
.
Times
(
0
)
.
Return
(
args
.
inboundResponse
.
err
)
if
err
:=
provide
(
args
.
service
,
fakeKtCli
,
args
.
options
);
err
==
nil
{
if
err
:=
provide
(
context
.
TODO
(),
args
.
service
,
fakeKtCli
,
args
.
options
);
err
==
nil
{
t
.
Errorf
(
"expect error = %v, actual is nil"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help