Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Clutch
Commits
9d0da861
Commit
9d0da861
authored
4 years ago
by
Daniel Hochman
Browse files
Options
Download
Email Patches
Plain Diff
tests
parent
d881392f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/service/k8s/clientset_test.go
+48
-0
backend/service/k8s/clientset_test.go
backend/service/k8s/pods_test.go
+1
-22
backend/service/k8s/pods_test.go
with
49 additions
and
22 deletions
+49
-22
backend/service/k8s/clientset_test.go
0 → 100644
+
48
-
0
View file @
9d0da861
package
k8s
import
(
"context"
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/kubernetes/fake"
)
func
TestClientsetManager
(
t
*
testing
.
T
)
{
fcs
:=
fake
.
NewSimpleClientset
()
m
:=
managerImpl
{
clientsets
:
map
[
string
]
*
ctxClientsetImpl
{
"core-0"
:
NewContextClientset
(
"core-namespace"
,
"core-cluster-0"
,
fcs
)
.
(
*
ctxClientsetImpl
),
"core-1a"
:
NewContextClientset
(
"core-namespace"
,
"core-cluster-1"
,
fcs
)
.
(
*
ctxClientsetImpl
),
"core-1b"
:
NewContextClientset
(
"core-namespace"
,
"core-cluster-1"
,
fcs
)
.
(
*
ctxClientsetImpl
),
}}
// No match found.
cs
,
err
:=
m
.
GetK8sClientset
(
context
.
Background
(),
"foo"
,
"foo"
,
"foo"
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"not found"
)
assert
.
Nil
(
t
,
cs
)
// Clientset found but cluster does not match.
cs
,
err
=
m
.
GetK8sClientset
(
context
.
Background
(),
"core-0"
,
"foo"
,
"foo"
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"does not match clientset"
)
assert
.
Nil
(
t
,
cs
)
// Clientset match and check namespace.
cs
,
err
=
m
.
GetK8sClientset
(
context
.
Background
(),
"core-0"
,
"core-cluster-0"
,
"foo"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
cs
)
assert
.
Equal
(
t
,
"foo"
,
cs
.
Namespace
())
assert
.
Equal
(
t
,
"core-cluster-0"
,
cs
.
Cluster
())
// Cluster match.
cs
,
err
=
m
.
GetK8sClientset
(
context
.
Background
(),
"undefined"
,
"core-cluster-0"
,
"foo"
)
assert
.
NoError
(
t
,
err
)
assert
.
NotNil
(
t
,
cs
)
// Multiple cluster match error.
cs
,
err
=
m
.
GetK8sClientset
(
context
.
Background
(),
"undefined"
,
"core-cluster-1"
,
""
)
assert
.
Error
(
t
,
err
)
assert
.
Contains
(
t
,
err
.
Error
(),
"impossible to determine"
)
assert
.
Nil
(
t
,
cs
)
}
This diff is collapsed.
Click to expand it.
backend/service/k8s/pods_test.go
+
1
-
22
View file @
9d0da861
...
...
@@ -202,30 +202,9 @@ func TestListPods(t *testing.T) {
}},
},
}
// Clientset not found
result
,
err
:=
s
.
ListPods
(
context
.
Background
(),
"unknown-clientset"
,
"testing-cluster"
,
"testing-namespace"
,
&
k8sv1
.
ListOptions
{},
)
assert
.
Error
(
t
,
err
)
assert
.
Nil
(
t
,
result
)
// No matching pods
result
,
err
=
s
.
ListPods
(
context
.
Background
(),
"testing-clientset"
,
"testing-cluster"
,
"testing-namespace"
,
&
k8sv1
.
ListOptions
{
Labels
:
map
[
string
]
string
{
"unknown-annotation"
:
"bar"
}},
)
assert
.
NoError
(
t
,
err
)
assert
.
Empty
(
t
,
result
)
// Two matching pods
result
,
err
=
s
.
ListPods
(
result
,
err
:
=
s
.
ListPods
(
context
.
Background
(),
"testing-clientset"
,
"testing-cluster"
,
...
...
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