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
98b3e421
Unverified
Commit
98b3e421
authored
Jan 02, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 02, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72483 from bart0sh/PR0055-kubeadm-rest-app-use-T.Run
kubeadm: use T.Run API in app/
parents
d582682b
215db4d4
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
15 deletions
+65
-15
validation_test.go
cmd/kubeadm/app/componentconfigs/validation_test.go
+15
-0
constants_test.go
cmd/kubeadm/app/constants/constants_test.go
+8
-0
discovery_test.go
cmd/kubeadm/app/discovery/discovery_test.go
+11
-1
features_test.go
cmd/kubeadm/app/features/features_test.go
+22
-10
checks_test.go
cmd/kubeadm/app/preflight/checks_test.go
+7
-2
utils_test.go
cmd/kubeadm/app/preflight/utils_test.go
+2
-2
No files found.
cmd/kubeadm/app/componentconfigs/validation_test.go
View file @
98b3e421
...
...
@@ -31,11 +31,13 @@ import (
func
TestValidateKubeProxyConfiguration
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
name
string
clusterConfig
*
kubeadm
.
ClusterConfiguration
msg
string
expectErr
bool
}{
{
name
:
"valid config"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -67,6 +69,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
false
,
},
{
name
:
"invalid BindAddress"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -100,6 +103,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
true
,
},
{
name
:
"invalid HealthzBindAddress"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -133,6 +137,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
true
,
},
{
name
:
"invalid MetricsBindAddress"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -166,6 +171,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
true
,
},
{
name
:
"invalid ClusterCIDR"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -199,6 +205,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
true
,
},
{
name
:
"invalid UDPIdleTimeout"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -232,6 +239,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
expectErr
:
true
,
},
{
name
:
"invalid ConfigSyncPeriod"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
KubeProxy
:
&
kubeproxyconfig
.
KubeProxyConfiguration
{
...
...
@@ -266,6 +274,7 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
},
}
for
i
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
name
,
func
(
t
*
testing
.
T
)
{
err
:=
ValidateKubeProxyConfiguration
(
rt
.
clusterConfig
,
nil
)
.
ToAggregate
()
if
(
err
!=
nil
)
!=
rt
.
expectErr
{
t
.
Errorf
(
"%d failed ValidateKubeProxyConfiguration: expected error %t, got error %t"
,
i
,
rt
.
expectErr
,
err
!=
nil
)
...
...
@@ -273,15 +282,18 @@ func TestValidateKubeProxyConfiguration(t *testing.T) {
if
err
!=
nil
&&
!
strings
.
Contains
(
err
.
Error
(),
rt
.
msg
)
{
t
.
Errorf
(
"%d failed ValidateKubeProxyConfiguration: unexpected error: %v, expected: %s"
,
i
,
err
,
rt
.
msg
)
}
})
}
}
func
TestValidateKubeletConfiguration
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
name
string
clusterConfig
*
kubeadm
.
ClusterConfiguration
expectErr
bool
}{
{
name
:
"valid configuration"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
Kubelet
:
&
kubeletconfig
.
KubeletConfiguration
{
...
...
@@ -314,6 +326,7 @@ func TestValidateKubeletConfiguration(t *testing.T) {
expectErr
:
false
,
},
{
name
:
"invalid configuration"
,
clusterConfig
:
&
kubeadm
.
ClusterConfiguration
{
ComponentConfigs
:
kubeadm
.
ComponentConfigs
{
Kubelet
:
&
kubeletconfig
.
KubeletConfiguration
{
...
...
@@ -345,9 +358,11 @@ func TestValidateKubeletConfiguration(t *testing.T) {
},
}
for
i
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
name
,
func
(
t
*
testing
.
T
)
{
err
:=
ValidateKubeletConfiguration
(
rt
.
clusterConfig
,
nil
)
.
ToAggregate
()
if
(
err
!=
nil
)
!=
rt
.
expectErr
{
t
.
Errorf
(
"%d failed ValidateKubeletConfiguration: expected error %t, got error %t"
,
i
,
rt
.
expectErr
,
err
!=
nil
)
}
})
}
}
cmd/kubeadm/app/constants/constants_test.go
View file @
98b3e421
...
...
@@ -100,6 +100,7 @@ func TestGetStaticPodFilepath(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
componentName
,
func
(
t
*
testing
.
T
)
{
actual
:=
GetStaticPodFilepath
(
rt
.
componentName
,
rt
.
manifestsDir
)
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -108,6 +109,7 @@ func TestGetStaticPodFilepath(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -133,6 +135,7 @@ func TestAddSelfHostedPrefix(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
componentName
,
func
(
t
*
testing
.
T
)
{
actual
:=
AddSelfHostedPrefix
(
rt
.
componentName
)
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -141,6 +144,7 @@ func TestAddSelfHostedPrefix(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -182,6 +186,7 @@ func TestEtcdSupportedVersion(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
kubernetesVersion
,
func
(
t
*
testing
.
T
)
{
actualVersion
,
actualError
:=
EtcdSupportedVersion
(
rt
.
kubernetesVersion
)
if
actualError
!=
nil
{
if
rt
.
expectedError
==
nil
{
...
...
@@ -204,6 +209,7 @@ func TestEtcdSupportedVersion(t *testing.T) {
)
}
}
})
}
}
...
...
@@ -222,6 +228,7 @@ func TestGetKubeDNSVersion(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
string
(
rt
.
dns
),
func
(
t
*
testing
.
T
)
{
actualDNSVersion
:=
GetDNSVersion
(
rt
.
dns
)
if
actualDNSVersion
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -230,5 +237,6 @@ func TestGetKubeDNSVersion(t *testing.T) {
actualDNSVersion
,
)
}
})
}
}
cmd/kubeadm/app/discovery/discovery_test.go
View file @
98b3e421
...
...
@@ -24,11 +24,17 @@ import (
func
TestFor
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
d
kubeadm
.
JoinConfiguration
expect
bool
}{
{
d
:
kubeadm
.
JoinConfiguration
{},
expect
:
false
},
{
name
:
"default Discovery"
,
d
:
kubeadm
.
JoinConfiguration
{},
expect
:
false
,
},
{
name
:
"file Discovery with a path"
,
d
:
kubeadm
.
JoinConfiguration
{
Discovery
:
kubeadm
.
Discovery
{
File
:
&
kubeadm
.
FileDiscovery
{
...
...
@@ -39,6 +45,7 @@ func TestFor(t *testing.T) {
expect
:
false
,
},
{
name
:
"file Discovery with an url"
,
d
:
kubeadm
.
JoinConfiguration
{
Discovery
:
kubeadm
.
Discovery
{
File
:
&
kubeadm
.
FileDiscovery
{
...
...
@@ -49,6 +56,7 @@ func TestFor(t *testing.T) {
expect
:
false
,
},
{
name
:
"BootstrapTokenDiscovery"
,
d
:
kubeadm
.
JoinConfiguration
{
Discovery
:
kubeadm
.
Discovery
{
BootstrapToken
:
&
kubeadm
.
BootstrapTokenDiscovery
{
...
...
@@ -60,6 +68,7 @@ func TestFor(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
name
,
func
(
t
*
testing
.
T
)
{
_
,
actual
:=
For
(
&
rt
.
d
)
if
(
actual
==
nil
)
!=
rt
.
expect
{
t
.
Errorf
(
...
...
@@ -68,5 +77,6 @@ func TestFor(t *testing.T) {
(
actual
==
nil
),
)
}
})
}
}
cmd/kubeadm/app/features/features_test.go
View file @
98b3e421
...
...
@@ -108,20 +108,21 @@ func TestNewFeatureGate(t *testing.T) {
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
value
,
func
(
t
*
testing
.
T
)
{
r
,
err
:=
NewFeatureGate
(
&
someFeatures
,
test
.
value
)
if
!
test
.
expectedError
&&
err
!=
nil
{
t
.
Errorf
(
"NewFeatureGate failed when not expected: %v"
,
err
)
continue
return
}
else
if
test
.
expectedError
&&
err
==
nil
{
t
.
Error
(
"NewFeatureGate didn't failed when expected"
)
continue
return
}
if
!
reflect
.
DeepEqual
(
r
,
test
.
expectedFeaturesGate
)
{
t
.
Errorf
(
"NewFeatureGate returned a unexpected value"
)
}
})
}
}
...
...
@@ -132,20 +133,24 @@ func TestValidateVersion(t *testing.T) {
}
var
tests
=
[]
struct
{
name
string
requestedVersion
string
requestedFeatures
map
[
string
]
bool
expectedError
bool
}{
{
//no min version
{
name
:
"no min version"
,
requestedFeatures
:
map
[
string
]
bool
{
"feature1"
:
true
},
expectedError
:
false
,
},
{
//min version but correct value given
{
name
:
"min version but correct value given"
,
requestedFeatures
:
map
[
string
]
bool
{
"feature2"
:
true
},
requestedVersion
:
constants
.
MinimumControlPlaneVersion
.
String
(),
expectedError
:
false
,
},
{
//min version and incorrect value given
{
name
:
"min version and incorrect value given"
,
requestedFeatures
:
map
[
string
]
bool
{
"feature2"
:
true
},
requestedVersion
:
"v1.11.2"
,
expectedError
:
true
,
...
...
@@ -153,14 +158,16 @@ func TestValidateVersion(t *testing.T) {
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
err
:=
ValidateVersion
(
someFeatures
,
test
.
requestedFeatures
,
test
.
requestedVersion
)
if
!
test
.
expectedError
&&
err
!=
nil
{
t
.
Errorf
(
"ValidateVersion failed when not expected: %v"
,
err
)
continue
return
}
else
if
test
.
expectedError
&&
err
==
nil
{
t
.
Error
(
"ValidateVersion didn't failed when expected"
)
continue
return
}
})
}
}
...
...
@@ -185,23 +192,28 @@ func TestCheckDeprecatedFlags(t *testing.T) {
}
var
tests
=
[]
struct
{
name
string
features
map
[
string
]
bool
expectedMsg
map
[
string
]
string
}{
{
// feature deprecated
{
name
:
"deprecated feature"
,
features
:
map
[
string
]
bool
{
"deprecated"
:
true
},
expectedMsg
:
map
[
string
]
string
{
"deprecated"
:
dummyMessage
},
},
{
// valid feature
{
name
:
"valid feature"
,
features
:
map
[
string
]
bool
{
"feature1"
:
true
},
expectedMsg
:
map
[
string
]
string
{},
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
msg
:=
CheckDeprecatedFlags
(
&
someFeatures
,
test
.
features
)
if
!
reflect
.
DeepEqual
(
test
.
expectedMsg
,
msg
)
{
t
.
Error
(
"CheckDeprecatedFlags didn't returned expected message"
)
}
})
}
}
cmd/kubeadm/app/preflight/checks_test.go
View file @
98b3e421
...
...
@@ -18,6 +18,7 @@ package preflight
import
(
"bytes"
"fmt"
"io/ioutil"
"strings"
"testing"
...
...
@@ -658,6 +659,7 @@ func TestKubeletVersionCheck(t *testing.T) {
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
kubeletVersion
,
func
(
t
*
testing
.
T
)
{
fcmd
:=
fakeexec
.
FakeCmd
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
func
()
([]
byte
,
error
)
{
return
[]
byte
(
"Kubernetes "
+
tc
.
kubeletVersion
),
nil
},
...
...
@@ -682,9 +684,8 @@ func TestKubeletVersionCheck(t *testing.T) {
case
errors
==
nil
&&
tc
.
expectErrors
:
t
.
Errorf
(
"KubeletVersionCheck: expected errors for kubelet version %q and Kubernetes version %q but got nothing"
,
tc
.
kubeletVersion
,
tc
.
k8sVersion
)
}
})
}
}
func
TestSetHasItemOrAll
(
t
*
testing
.
T
)
{
...
...
@@ -702,6 +703,7 @@ func TestSetHasItemOrAll(t *testing.T) {
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
testString
,
func
(
t
*
testing
.
T
)
{
result
:=
setHasItemOrAll
(
rt
.
ignoreSet
,
rt
.
testString
)
if
result
!=
rt
.
expectedResult
{
t
.
Errorf
(
...
...
@@ -711,6 +713,7 @@ func TestSetHasItemOrAll(t *testing.T) {
rt
.
testString
,
)
}
})
}
}
...
...
@@ -790,6 +793,7 @@ func TestNumCPUCheck(t *testing.T) {
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
fmt
.
Sprintf
(
"number of CPUs: %d"
,
rt
.
numCPU
),
func
(
t
*
testing
.
T
)
{
warnings
,
errors
:=
NumCPUCheck
{
NumCPU
:
rt
.
numCPU
}
.
Check
()
if
len
(
warnings
)
!=
rt
.
numWarnings
{
t
.
Errorf
(
"expected %d warning(s) but got %d: %q"
,
rt
.
numWarnings
,
len
(
warnings
),
warnings
)
...
...
@@ -797,5 +801,6 @@ func TestNumCPUCheck(t *testing.T) {
if
len
(
errors
)
!=
rt
.
numErrors
{
t
.
Errorf
(
"expected %d warning(s) but got %d: %q"
,
rt
.
numErrors
,
len
(
errors
),
errors
)
}
})
}
}
cmd/kubeadm/app/preflight/utils_test.go
View file @
98b3e421
...
...
@@ -40,6 +40,7 @@ func TestGetKubeletVersion(t *testing.T) {
}
for
_
,
tc
:=
range
cases
{
t
.
Run
(
tc
.
output
,
func
(
t
*
testing
.
T
)
{
fcmd
:=
fakeexec
.
FakeCmd
{
CombinedOutputScript
:
[]
fakeexec
.
FakeCombinedOutputAction
{
func
()
([]
byte
,
error
)
{
return
[]
byte
(
tc
.
output
),
tc
.
err
},
...
...
@@ -59,7 +60,6 @@ func TestGetKubeletVersion(t *testing.T) {
case
ver
!=
nil
&&
ver
.
String
()
!=
tc
.
expected
:
t
.
Errorf
(
"GetKubeletVersion: unexpected version result for key %q. Expected: %q Actual: %q"
,
tc
.
output
,
tc
.
expected
,
ver
)
}
})
}
}
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