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
d9ffcace
Commit
d9ffcace
authored
Jul 08, 2016
by
Paul Morie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ExtractPodBandwidthResources test into appropriate package
parent
c25262b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
65 deletions
+89
-65
kubelet_test.go
pkg/kubelet/kubelet_test.go
+0
-65
utils_test.go
pkg/util/bandwidth/utils_test.go
+89
-0
No files found.
pkg/kubelet/kubelet_test.go
View file @
d9ffcace
...
...
@@ -65,7 +65,6 @@ import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/bandwidth"
"k8s.io/kubernetes/pkg/util/diff"
"k8s.io/kubernetes/pkg/util/flowcontrol"
"k8s.io/kubernetes/pkg/util/mount"
...
...
@@ -4007,70 +4006,6 @@ func TestDoesNotDeletePodDirsIfContainerIsRunning(t *testing.T) {
syncAndVerifyPodDir
(
t
,
testKubelet
,
pods
,
[]
*
api
.
Pod
{
apiPod
},
false
)
}
func
TestExtractBandwidthResources
(
t
*
testing
.
T
)
{
four
,
_
:=
resource
.
ParseQuantity
(
"4M"
)
ten
,
_
:=
resource
.
ParseQuantity
(
"10M"
)
twenty
,
_
:=
resource
.
ParseQuantity
(
"20M"
)
testPod
:=
func
(
ingress
,
egress
string
)
*
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{}}}
if
len
(
ingress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/ingress-bandwidth"
]
=
ingress
}
if
len
(
egress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/egress-bandwidth"
]
=
egress
}
return
pod
}
tests
:=
[]
struct
{
pod
*
api
.
Pod
expectedIngress
*
resource
.
Quantity
expectedEgress
*
resource
.
Quantity
expectError
bool
}{
{
pod
:
&
api
.
Pod
{},
},
{
pod
:
testPod
(
"10M"
,
""
),
expectedIngress
:
&
ten
,
},
{
pod
:
testPod
(
""
,
"10M"
),
expectedEgress
:
&
ten
,
},
{
pod
:
testPod
(
"4M"
,
"20M"
),
expectedIngress
:
&
four
,
expectedEgress
:
&
twenty
,
},
{
pod
:
testPod
(
"foo"
,
""
),
expectError
:
true
,
},
}
for
_
,
test
:=
range
tests
{
ingress
,
egress
,
err
:=
bandwidth
.
ExtractPodBandwidthResources
(
test
.
pod
.
Annotations
)
if
test
.
expectError
{
if
err
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
}
continue
}
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
continue
}
if
!
reflect
.
DeepEqual
(
ingress
,
test
.
expectedIngress
)
{
t
.
Errorf
(
"expected: %v, saw: %v"
,
ingress
,
test
.
expectedIngress
)
}
if
!
reflect
.
DeepEqual
(
egress
,
test
.
expectedEgress
)
{
t
.
Errorf
(
"expected: %v, saw: %v"
,
egress
,
test
.
expectedEgress
)
}
}
}
func
TestGetPodsToSync
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
,
false
/* controllerAttachDetachEnabled */
)
kubelet
:=
testKubelet
.
kubelet
...
...
pkg/util/bandwidth/utils_test.go
0 → 100644
View file @
d9ffcace
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
bandwidth
import
(
"reflect"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
)
func
TestExtractPodBandwidthResources
(
t
*
testing
.
T
)
{
four
,
_
:=
resource
.
ParseQuantity
(
"4M"
)
ten
,
_
:=
resource
.
ParseQuantity
(
"10M"
)
twenty
,
_
:=
resource
.
ParseQuantity
(
"20M"
)
testPod
:=
func
(
ingress
,
egress
string
)
*
api
.
Pod
{
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Annotations
:
map
[
string
]
string
{}}}
if
len
(
ingress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/ingress-bandwidth"
]
=
ingress
}
if
len
(
egress
)
!=
0
{
pod
.
Annotations
[
"kubernetes.io/egress-bandwidth"
]
=
egress
}
return
pod
}
tests
:=
[]
struct
{
pod
*
api
.
Pod
expectedIngress
*
resource
.
Quantity
expectedEgress
*
resource
.
Quantity
expectError
bool
}{
{
pod
:
&
api
.
Pod
{},
},
{
pod
:
testPod
(
"10M"
,
""
),
expectedIngress
:
&
ten
,
},
{
pod
:
testPod
(
""
,
"10M"
),
expectedEgress
:
&
ten
,
},
{
pod
:
testPod
(
"4M"
,
"20M"
),
expectedIngress
:
&
four
,
expectedEgress
:
&
twenty
,
},
{
pod
:
testPod
(
"foo"
,
""
),
expectError
:
true
,
},
}
for
_
,
test
:=
range
tests
{
ingress
,
egress
,
err
:=
ExtractPodBandwidthResources
(
test
.
pod
.
Annotations
)
if
test
.
expectError
{
if
err
==
nil
{
t
.
Errorf
(
"unexpected non-error"
)
}
continue
}
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
continue
}
if
!
reflect
.
DeepEqual
(
ingress
,
test
.
expectedIngress
)
{
t
.
Errorf
(
"expected: %v, saw: %v"
,
ingress
,
test
.
expectedIngress
)
}
if
!
reflect
.
DeepEqual
(
egress
,
test
.
expectedEgress
)
{
t
.
Errorf
(
"expected: %v, saw: %v"
,
egress
,
test
.
expectedEgress
)
}
}
}
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