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
d23507f4
Commit
d23507f4
authored
Feb 02, 2017
by
Derek McQuay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: added tests cert/pkiutil pkg
raised coverage from ~37% to ~77%
parent
9e427c88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
1 deletion
+99
-1
pki_helpers_test.go
cmd/kubeadm/app/phases/certs/pkiutil/pki_helpers_test.go
+99
-1
No files found.
cmd/kubeadm/app/phases/certs/pkiutil/pki_helpers_test.go
View file @
d23507f4
...
@@ -92,7 +92,7 @@ func TestWriteCertAndKey(t *testing.T) {
...
@@ -92,7 +92,7 @@ func TestWriteCertAndKey(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create tmpdir"
)
t
.
Fatalf
(
"Couldn't create tmpdir"
)
}
}
defer
os
.
Remove
(
tmpdir
)
defer
os
.
Remove
All
(
tmpdir
)
caKey
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
caKey
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -107,3 +107,101 @@ func TestWriteCertAndKey(t *testing.T) {
...
@@ -107,3 +107,101 @@ func TestWriteCertAndKey(t *testing.T) {
)
)
}
}
}
}
func
TestCertOrKeyExist
(
t
*
testing
.
T
)
{
tmpdir
,
err
:=
ioutil
.
TempDir
(
""
,
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create tmpdir"
)
}
defer
os
.
RemoveAll
(
tmpdir
)
caKey
,
err
:=
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create rsa Private Key"
)
}
caCert
:=
&
x509
.
Certificate
{}
actual
:=
WriteCertAndKey
(
tmpdir
,
"foo"
,
caCert
,
caKey
)
if
actual
!=
nil
{
t
.
Errorf
(
"failed WriteCertAndKey with an error: %v"
,
actual
,
)
}
var
tests
=
[]
struct
{
path
string
name
string
expected
bool
}{
{
path
:
""
,
name
:
""
,
expected
:
false
,
},
{
path
:
tmpdir
,
name
:
"foo"
,
expected
:
true
,
},
}
for
_
,
rt
:=
range
tests
{
actual
:=
CertOrKeyExist
(
rt
.
path
,
rt
.
name
)
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
"failed CertOrKeyExist:
\n\t
expected: %t
\n\t
actual: %t"
,
rt
.
expected
,
actual
,
)
}
}
}
func
TestTryLoadCertAndKeyFromDisk
(
t
*
testing
.
T
)
{
tmpdir
,
err
:=
ioutil
.
TempDir
(
""
,
""
)
if
err
!=
nil
{
t
.
Fatalf
(
"Couldn't create tmpdir"
)
}
defer
os
.
RemoveAll
(
tmpdir
)
caCert
,
caKey
,
err
:=
NewCertificateAuthority
()
if
err
!=
nil
{
t
.
Errorf
(
"failed to create cert and key with an error: %v"
,
err
,
)
}
err
=
WriteCertAndKey
(
tmpdir
,
"foo"
,
caCert
,
caKey
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to write cert and key with an error: %v"
,
err
,
)
}
var
tests
=
[]
struct
{
path
string
name
string
expected
bool
}{
{
path
:
""
,
name
:
""
,
expected
:
false
,
},
{
path
:
tmpdir
,
name
:
"foo"
,
expected
:
true
,
},
}
for
_
,
rt
:=
range
tests
{
_
,
_
,
actual
:=
TryLoadCertAndKeyFromDisk
(
rt
.
path
,
rt
.
name
)
if
(
actual
==
nil
)
!=
rt
.
expected
{
t
.
Errorf
(
"failed TryLoadCertAndKeyFromDisk:
\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