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
a0185649
Unverified
Commit
a0185649
authored
Oct 20, 2016
by
Derek McQuay
Committed by
Paulo Pires
Oct 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: added tests for util/{error,kubeconfig}
parent
1bfa8670
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
226 additions
and
1 deletion
+226
-1
error_test.go
cmd/kubeadm/app/util/error_test.go
+51
-0
kubeconfig_test.go
cmd/kubeadm/app/util/kubeconfig_test.go
+174
-0
tokens_test.go
cmd/kubeadm/app/util/tokens_test.go
+1
-1
No files found.
cmd/kubeadm/app/util/error_test.go
0 → 100644
View file @
a0185649
/*
Copyright 2016 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
util
import
(
"fmt"
"testing"
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
)
func
TestCheckErr
(
t
*
testing
.
T
)
{
var
codeReturned
int
errHandle
:=
func
(
err
string
,
code
int
)
{
codeReturned
=
code
}
var
tokenTest
=
[]
struct
{
e
error
expected
int
}{
{
nil
,
0
},
{
fmt
.
Errorf
(
""
),
1
},
{
&
preflight
.
PreFlightError
{},
2
},
}
for
_
,
rt
:=
range
tokenTest
{
checkErr
(
""
,
rt
.
e
,
errHandle
)
if
codeReturned
!=
rt
.
expected
{
t
.
Errorf
(
"failed checkErr:
\n\t
expected: %d
\n\t
actual: %d"
,
rt
.
expected
,
codeReturned
,
)
}
}
}
cmd/kubeadm/app/util/kubeconfig_test.go
0 → 100644
View file @
a0185649
/*
Copyright 2016 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
util
import
(
"fmt"
"log"
"math/rand"
"os"
"runtime"
"strings"
"testing"
"time"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
)
type
configClient
struct
{
c
string
s
string
ca
[]
byte
}
type
configClientWithCerts
struct
{
c
*
clientcmdapi
.
Config
clusterName
string
userName
string
clientKey
[]
byte
clientCert
[]
byte
}
type
configClientWithToken
struct
{
c
*
clientcmdapi
.
Config
clusterName
string
userName
string
token
string
}
func
init
()
{
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
}
func
TestCreateBasicClientConfig
(
t
*
testing
.
T
)
{
var
createBasicTest
=
[]
struct
{
cc
configClient
expected
string
}{
{
configClient
{},
""
},
{
configClient
{
c
:
"kubernetes"
},
""
},
}
for
_
,
rt
:=
range
createBasicTest
{
c
:=
CreateBasicClientConfig
(
rt
.
cc
.
c
,
rt
.
cc
.
s
,
rt
.
cc
.
ca
)
if
c
.
Kind
!=
rt
.
expected
{
t
.
Errorf
(
"failed CreateBasicClientConfig:
\n\t
expected: %s
\n\t
actual: %s"
,
c
.
Kind
,
rt
.
expected
,
)
}
}
}
func
TestMakeClientConfigWithCerts
(
t
*
testing
.
T
)
{
var
createBasicTest
=
[]
struct
{
cc
configClient
ccWithCerts
configClientWithCerts
expected
string
}{
{
configClient
{},
configClientWithCerts
{},
""
},
{
configClient
{
c
:
"kubernetes"
},
configClientWithCerts
{},
""
},
}
for
_
,
rt
:=
range
createBasicTest
{
c
:=
CreateBasicClientConfig
(
rt
.
cc
.
c
,
rt
.
cc
.
s
,
rt
.
cc
.
ca
)
rt
.
ccWithCerts
.
c
=
c
cwc
:=
MakeClientConfigWithCerts
(
rt
.
ccWithCerts
.
c
,
rt
.
ccWithCerts
.
clusterName
,
rt
.
ccWithCerts
.
userName
,
rt
.
ccWithCerts
.
clientKey
,
rt
.
ccWithCerts
.
clientCert
,
)
if
cwc
.
Kind
!=
rt
.
expected
{
t
.
Errorf
(
"failed MakeClientConfigWithCerts:
\n\t
expected: %s
\n\t
actual: %s"
,
c
.
Kind
,
rt
.
expected
,
)
}
}
}
func
TestMakeClientConfigWithToken
(
t
*
testing
.
T
)
{
var
createBasicTest
=
[]
struct
{
cc
configClient
ccWithToken
configClientWithToken
expected
string
}{
{
configClient
{},
configClientWithToken
{},
""
},
{
configClient
{
c
:
"kubernetes"
},
configClientWithToken
{},
""
},
}
for
_
,
rt
:=
range
createBasicTest
{
c
:=
CreateBasicClientConfig
(
rt
.
cc
.
c
,
rt
.
cc
.
s
,
rt
.
cc
.
ca
)
rt
.
ccWithToken
.
c
=
c
cwc
:=
MakeClientConfigWithToken
(
rt
.
ccWithToken
.
c
,
rt
.
ccWithToken
.
clusterName
,
rt
.
ccWithToken
.
userName
,
rt
.
ccWithToken
.
token
,
)
if
cwc
.
Kind
!=
rt
.
expected
{
t
.
Errorf
(
"failed MakeClientConfigWithCerts:
\n\t
expected: %s
\n\t
actual: %s"
,
c
.
Kind
,
rt
.
expected
,
)
}
}
}
func
setEnvs
()
{
rand
:=
rand
.
Int
()
var
envParams
=
map
[
string
]
string
{
"kubernetes_dir"
:
fmt
.
Sprintf
(
"/tmp/%d/etc/kubernetes"
,
rand
),
"host_pki_path"
:
fmt
.
Sprintf
(
"/tmp/%d/etc/kubernetes/pki"
,
rand
),
"host_etcd_path"
:
fmt
.
Sprintf
(
"/tmp/%d/var/lib/etcd"
,
rand
),
"hyperkube_image"
:
""
,
"discovery_image"
:
fmt
.
Sprintf
(
"gcr.io/google_containers/kube-discovery-%s:%s"
,
runtime
.
GOARCH
,
"1.0"
),
"etcd_image"
:
""
,
"component_loglevel"
:
"--v=4"
,
}
for
k
,
v
:=
range
envParams
{
err
:=
os
.
Setenv
(
fmt
.
Sprintf
(
"KUBE_%s"
,
strings
.
ToUpper
(
k
)),
v
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
func
TestWriteKubeconfigIfNotExists
(
t
*
testing
.
T
)
{
setEnvs
()
var
writeConfig
=
[]
struct
{
name
string
cc
configClient
expected
error
}{
{
fmt
.
Sprintf
(
"%d"
,
rand
.
Int
()),
configClient
{},
nil
},
{
fmt
.
Sprintf
(
"%d"
,
rand
.
Int
()),
configClient
{
c
:
"kubernetes"
},
nil
},
}
for
_
,
rt
:=
range
writeConfig
{
c
:=
CreateBasicClientConfig
(
rt
.
cc
.
c
,
rt
.
cc
.
s
,
rt
.
cc
.
ca
)
err
:=
WriteKubeconfigIfNotExists
(
rt
.
name
,
c
)
if
err
!=
rt
.
expected
{
t
.
Errorf
(
"failed WriteKubeconfigIfNotExists:
\n\t
expected: %s
\n\t
actual: %s"
,
err
,
rt
.
expected
,
)
}
}
}
cmd/kubeadm/app/util/tokens_test.go
View file @
a0185649
...
@@ -154,7 +154,7 @@ func TestRandBytes(t *testing.T) {
...
@@ -154,7 +154,7 @@ func TestRandBytes(t *testing.T) {
actual
,
_
,
err
:=
RandBytes
(
rt
.
r
)
actual
,
_
,
err
:=
RandBytes
(
rt
.
r
)
if
err
!=
rt
.
expected
{
if
err
!=
rt
.
expected
{
t
.
Errorf
(
t
.
Errorf
(
"failed RandBytes:
\n\t
expected: %
t
\n\t
actual: %t
"
,
"failed RandBytes:
\n\t
expected: %
s
\n\t
actual: %s
"
,
rt
.
expected
,
rt
.
expected
,
err
,
err
,
)
)
...
...
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