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
cb3b08a8
Commit
cb3b08a8
authored
Nov 03, 2016
by
Derek McQuay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: unit tests for app/master/tokens.go
parent
bbd447f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
tokens_test.go
cmd/kubeadm/app/master/tokens_test.go
+86
-0
No files found.
cmd/kubeadm/app/master/tokens_test.go
0 → 100644
View file @
cb3b08a8
/*
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
master
import
(
"fmt"
"io/ioutil"
"os"
"testing"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
)
func
TestGenerateTokenIfNeeded
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
s
kubeadmapi
.
Secrets
expected
bool
}{
{
kubeadmapi
.
Secrets
{
GivenToken
:
"noperiod"
},
false
},
// not 2-part '.' format
{
kubeadmapi
.
Secrets
{
GivenToken
:
"abcd.a"
},
false
},
// len(tokenID) != 6
{
kubeadmapi
.
Secrets
{
GivenToken
:
"abcdef.a"
},
true
},
{
kubeadmapi
.
Secrets
{
GivenToken
:
""
},
true
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
generateTokenIfNeeded
(
&
rt
.
s
)
fmt
.
Println
(
"here is a run:"
)
fmt
.
Println
(
actual
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed UseGivenTokenIfValid:
\n\t
expected: %t
\n\t
actual: %t
\n\t
token:%s"
,
rt
.
expected
,
(
actual
==
nil
),
rt
.
s
.
GivenToken
,
)
}
}
}
func
TestCreateTokenAuthFile
(
t
*
testing
.
T
)
{
tmpdir
,
err
:=
ioutil
.
TempDir
(
""
,
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create tmpdir"
)
}
defer
os
.
Remove
(
tmpdir
)
fmt
.
Println
(
tmpdir
)
// set up tmp GlobalEnvParams values for testing
oldEnv
:=
kubeadmapi
.
GlobalEnvParams
kubeadmapi
.
GlobalEnvParams
.
HostPKIPath
=
fmt
.
Sprintf
(
"%s/etc/kubernetes/pki"
,
tmpdir
)
defer
func
()
{
kubeadmapi
.
GlobalEnvParams
=
oldEnv
}()
var
tests
=
[]
struct
{
s
kubeadmapi
.
Secrets
expected
bool
}{
{
kubeadmapi
.
Secrets
{
GivenToken
:
"noperiod"
},
false
},
// not 2-part '.' format
{
kubeadmapi
.
Secrets
{
GivenToken
:
"abcd.a"
},
false
},
// len(tokenID) != 6
{
kubeadmapi
.
Secrets
{
GivenToken
:
"abcdef.a"
},
true
},
{
kubeadmapi
.
Secrets
{
GivenToken
:
""
},
true
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
CreateTokenAuthFile
(
&
rt
.
s
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed WriteKubeconfigIfNotExists with an error:
\n\t
expected: %t
\n\t
actual: %t"
,
rt
.
expected
,
(
actual
==
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