Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
552453f6
Unverified
Commit
552453f6
authored
Oct 08, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69537 from logicalhan/index-test
refactor index_test to compress the assertions and make consistent with store_test.go
parents
f81b72f7
de0043b1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
48 deletions
+19
-48
index_test.go
staging/src/k8s.io/client-go/tools/cache/index_test.go
+19
-48
No files found.
staging/src/k8s.io/client-go/tools/cache/index_test.go
View file @
552453f6
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
cache
import
(
"k8s.io/apimachinery/pkg/util/sets"
"strings"
"testing"
...
...
@@ -70,60 +71,31 @@ func TestMultiIndexKeys(t *testing.T) {
index
.
Add
(
pod2
)
index
.
Add
(
pod3
)
erniePods
,
err
:=
index
.
ByIndex
(
"byUser"
,
"ernie"
)
expected
:=
map
[
string
]
sets
.
String
{}
expected
[
"ernie"
]
=
sets
.
NewString
(
"one"
,
"tre"
)
expected
[
"bert"
]
=
sets
.
NewString
(
"one"
,
"two"
)
expected
[
"elmo"
]
=
sets
.
NewString
(
"tre"
)
expected
[
"oscar"
]
=
sets
.
NewString
(
"two"
)
expected
[
"elmo"
]
=
sets
.
NewString
()
// let's just make sure we don't get anything back in this case
{
for
k
,
v
:=
range
expected
{
found
:=
sets
.
String
{}
indexResults
,
err
:=
index
.
ByIndex
(
"byUser"
,
k
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error:
%v"
,
err
)
t
.
Errorf
(
"Unexpected error
%v"
,
err
)
}
if
len
(
erniePods
)
!=
2
{
t
.
Errorf
(
"Expected 2 pods but got %v"
,
len
(
erniePods
))
}
for
_
,
erniePod
:=
range
erniePods
{
if
erniePod
.
(
*
v1
.
Pod
)
.
Name
!=
"one"
&&
erniePod
.
(
*
v1
.
Pod
)
.
Name
!=
"tre"
{
t
.
Errorf
(
"Expected only 'one' or 'tre' but got %s"
,
erniePod
.
(
*
v1
.
Pod
)
.
Name
)
for
_
,
item
:=
range
indexResults
{
found
.
Insert
(
item
.
(
*
v1
.
Pod
)
.
Name
)
}
items
:=
v
.
List
()
if
!
found
.
HasAll
(
items
...
)
{
t
.
Errorf
(
"missing items, index %s, expected %v but found %v"
,
k
,
items
,
found
.
List
())
}
bertPods
,
err
:=
index
.
ByIndex
(
"byUser"
,
"bert"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
bertPods
)
!=
2
{
t
.
Errorf
(
"Expected 2 pods but got %v"
,
len
(
bertPods
))
}
for
_
,
bertPod
:=
range
bertPods
{
if
bertPod
.
(
*
v1
.
Pod
)
.
Name
!=
"one"
&&
bertPod
.
(
*
v1
.
Pod
)
.
Name
!=
"two"
{
t
.
Errorf
(
"Expected only 'one' or 'two' but got %s"
,
bertPod
.
(
*
v1
.
Pod
)
.
Name
)
}
}
oscarPods
,
err
:=
index
.
ByIndex
(
"byUser"
,
"oscar"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
oscarPods
)
!=
1
{
t
.
Errorf
(
"Expected 1 pods but got %v"
,
len
(
erniePods
))
}
for
_
,
oscarPod
:=
range
oscarPods
{
if
oscarPod
.
(
*
v1
.
Pod
)
.
Name
!=
"two"
{
t
.
Errorf
(
"Expected only 'two' but got %s"
,
oscarPod
.
(
*
v1
.
Pod
)
.
Name
)
}
}
ernieAndBertKeys
,
err
:=
index
.
Index
(
"byUser"
,
pod1
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
if
len
(
ernieAndBertKeys
)
!=
3
{
t
.
Errorf
(
"Expected 3 pods but got %v"
,
len
(
ernieAndBertKeys
))
}
for
_
,
ernieAndBertKey
:=
range
ernieAndBertKeys
{
if
ernieAndBertKey
.
(
*
v1
.
Pod
)
.
Name
!=
"one"
&&
ernieAndBertKey
.
(
*
v1
.
Pod
)
.
Name
!=
"two"
&&
ernieAndBertKey
.
(
*
v1
.
Pod
)
.
Name
!=
"tre"
{
t
.
Errorf
(
"Expected only 'one', 'two' or 'tre' but got %s"
,
ernieAndBertKey
.
(
*
v1
.
Pod
)
.
Name
)
}
}
index
.
Delete
(
pod3
)
erniePods
,
err
=
index
.
ByIndex
(
"byUser"
,
"ernie"
)
erniePods
,
err
:
=
index
.
ByIndex
(
"byUser"
,
"ernie"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -147,7 +119,7 @@ func TestMultiIndexKeys(t *testing.T) {
copyOfPod2
:=
pod2
.
DeepCopy
()
copyOfPod2
.
Annotations
[
"users"
]
=
"oscar"
index
.
Update
(
copyOfPod2
)
bertPods
,
err
=
index
.
ByIndex
(
"byUser"
,
"bert"
)
bertPods
,
err
:
=
index
.
ByIndex
(
"byUser"
,
"bert"
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
...
...
@@ -159,5 +131,4 @@ func TestMultiIndexKeys(t *testing.T) {
t
.
Errorf
(
"Expected only 'one' but got %s"
,
bertPod
.
(
*
v1
.
Pod
)
.
Name
)
}
}
}
Write
Preview
Markdown
is supported
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