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
870a1634
Commit
870a1634
authored
May 12, 2016
by
Saad Ali
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #24722 from derekwaynecarr/kubelet_testing
Code cleanups in kubelet_test.go
parents
ab6c3121
a7dfdeb6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
119 deletions
+29
-119
kubelet_test.go
pkg/kubelet/kubelet_test.go
+29
-119
No files found.
pkg/kubelet/kubelet_test.go
View file @
870a1634
...
@@ -962,108 +962,32 @@ func (e envs) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
...
@@ -962,108 +962,32 @@ func (e envs) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
func
(
e
envs
)
Less
(
i
,
j
int
)
bool
{
return
e
[
i
]
.
Name
<
e
[
j
]
.
Name
}
func
(
e
envs
)
Less
(
i
,
j
int
)
bool
{
return
e
[
i
]
.
Name
<
e
[
j
]
.
Name
}
func
TestMakeEnvironmentVariables
(
t
*
testing
.
T
)
{
func
buildService
(
name
,
namespace
,
clusterIP
,
protocol
string
,
port
int
)
api
.
Service
{
services
:=
[]
api
.
Service
{
return
api
.
Service
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
namespace
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"kubernetes"
,
Namespace
:
api
.
NamespaceDefault
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8081
,
}},
ClusterIP
:
"1.2.3.1"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"test1"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8083
,
}},
ClusterIP
:
"1.2.3.3"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"kubernetes"
,
Namespace
:
"test2"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8084
,
}},
ClusterIP
:
"1.2.3.4"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"test2"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8085
,
}},
ClusterIP
:
"1.2.3.5"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"test2"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8085
,
}},
ClusterIP
:
"None"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test"
,
Namespace
:
"test2"
},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Protocol
:
api
.
Protocol
(
protocol
)
,
Port
:
8085
,
Port
:
int32
(
port
)
,
}},
}},
},
ClusterIP
:
clusterIP
,
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"kubernetes"
,
Namespace
:
"kubernetes"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8086
,
}},
ClusterIP
:
"1.2.3.6"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"not-special"
,
Namespace
:
"kubernetes"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8088
,
}},
ClusterIP
:
"1.2.3.8"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"not-special"
,
Namespace
:
"kubernetes"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8088
,
}},
ClusterIP
:
"None"
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"not-special"
,
Namespace
:
"kubernetes"
},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{{
Protocol
:
"TCP"
,
Port
:
8088
,
}},
ClusterIP
:
""
,
},
},
},
}
}
}
func
TestMakeEnvironmentVariables
(
t
*
testing
.
T
)
{
services
:=
[]
api
.
Service
{
buildService
(
"kubernetes"
,
api
.
NamespaceDefault
,
"1.2.3.1"
,
"TCP"
,
8081
),
buildService
(
"test"
,
"test1"
,
"1.2.3.3"
,
"TCP"
,
8083
),
buildService
(
"kubernetes"
,
"test2"
,
"1.2.3.4"
,
"TCP"
,
8084
),
buildService
(
"test"
,
"test2"
,
"1.2.3.5"
,
"TCP"
,
8085
),
buildService
(
"test"
,
"test2"
,
"None"
,
"TCP"
,
8085
),
buildService
(
"test"
,
"test2"
,
""
,
"TCP"
,
8085
),
buildService
(
"kubernetes"
,
"kubernetes"
,
"1.2.3.6"
,
"TCP"
,
8086
),
buildService
(
"not-special"
,
"kubernetes"
,
"1.2.3.8"
,
"TCP"
,
8088
),
buildService
(
"not-special"
,
"kubernetes"
,
"None"
,
"TCP"
,
8088
),
buildService
(
"not-special"
,
"kubernetes"
,
""
,
"TCP"
,
8088
),
}
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
// the name of the test case
name
string
// the name of the test case
...
@@ -2203,7 +2127,7 @@ func TestHandleHostNameConflicts(t *testing.T) {
...
@@ -2203,7 +2127,7 @@ func TestHandleHostNameConflicts(t *testing.T) {
func
TestHandleNodeSelector
(
t
*
testing
.
T
)
{
func
TestHandleNodeSelector
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
kl
.
nodeLister
=
testNodeLister
{
nodes
:
[]
api
.
Node
{
nodes
:=
[]
api
.
Node
{
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
,
Labels
:
map
[
string
]
string
{
"key"
:
"B"
}},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
,
Labels
:
map
[
string
]
string
{
"key"
:
"B"
}},
Status
:
api
.
NodeStatus
{
Status
:
api
.
NodeStatus
{
...
@@ -2212,17 +2136,9 @@ func TestHandleNodeSelector(t *testing.T) {
...
@@ -2212,17 +2136,9 @@ func TestHandleNodeSelector(t *testing.T) {
},
},
},
},
},
},
}}
}
kl
.
nodeInfo
=
testNodeInfo
{
nodes
:
[]
api
.
Node
{
kl
.
nodeLister
=
testNodeLister
{
nodes
:
nodes
}
{
kl
.
nodeInfo
=
testNodeInfo
{
nodes
:
nodes
}
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
,
Labels
:
map
[
string
]
string
{
"key"
:
"B"
}},
Status
:
api
.
NodeStatus
{
Allocatable
:
api
.
ResourceList
{
api
.
ResourcePods
:
*
resource
.
NewQuantity
(
110
,
resource
.
DecimalSI
),
},
},
},
}}
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
...
@@ -2272,22 +2188,16 @@ func TestHandleNodeSelector(t *testing.T) {
...
@@ -2272,22 +2188,16 @@ func TestHandleNodeSelector(t *testing.T) {
func
TestHandleMemExceeded
(
t
*
testing
.
T
)
{
func
TestHandleMemExceeded
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
kl
:=
testKubelet
.
kubelet
kl
:=
testKubelet
.
kubelet
kl
.
nodeLister
=
testNodeLister
{
nodes
:
[]
api
.
Node
{
nodes
:=
[]
api
.
Node
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
},
Status
:
api
.
NodeStatus
{
Capacity
:
api
.
ResourceList
{},
Allocatable
:
api
.
ResourceList
{
Status
:
api
.
NodeStatus
{
Capacity
:
api
.
ResourceList
{},
Allocatable
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
10
,
resource
.
DecimalSI
),
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
10
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
100
,
resource
.
BinarySI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
100
,
resource
.
BinarySI
),
api
.
ResourcePods
:
*
resource
.
NewQuantity
(
40
,
resource
.
DecimalSI
),
api
.
ResourcePods
:
*
resource
.
NewQuantity
(
40
,
resource
.
DecimalSI
),
}}},
}}},
}}
}
kl
.
nodeInfo
=
testNodeInfo
{
nodes
:
[]
api
.
Node
{
kl
.
nodeLister
=
testNodeLister
{
nodes
:
nodes
}
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
testKubeletHostname
},
kl
.
nodeInfo
=
testNodeInfo
{
nodes
:
nodes
}
Status
:
api
.
NodeStatus
{
Capacity
:
api
.
ResourceList
{},
Allocatable
:
api
.
ResourceList
{
api
.
ResourceCPU
:
*
resource
.
NewMilliQuantity
(
10
,
resource
.
DecimalSI
),
api
.
ResourceMemory
:
*
resource
.
NewQuantity
(
100
,
resource
.
BinarySI
),
api
.
ResourcePods
:
*
resource
.
NewQuantity
(
40
,
resource
.
DecimalSI
),
}}},
}}
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorapi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"DockerImagesFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
nil
)
...
...
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