mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Incomplete coverage of test scenarios and bad code
This commit is contained in:
parent
537941765f
commit
696d537239
@ -247,13 +247,8 @@ func CertOrKeyExist(pkiPath, name string) bool {
|
|||||||
|
|
||||||
_, certErr := os.Stat(certificatePath)
|
_, certErr := os.Stat(certificatePath)
|
||||||
_, keyErr := os.Stat(privateKeyPath)
|
_, keyErr := os.Stat(privateKeyPath)
|
||||||
if os.IsNotExist(certErr) && os.IsNotExist(keyErr) {
|
|
||||||
// The cert and the key do not exist
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Both files exist or one of them
|
return !(os.IsNotExist(certErr) && os.IsNotExist(keyErr))
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSROrKeyExist returns true if one of the CSR or key exists
|
// CSROrKeyExist returns true if one of the CSR or key exists
|
||||||
|
@ -262,12 +262,16 @@ func TestCertOrKeyExist(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
caCert := &x509.Certificate{}
|
if err = WriteCertAndKey(tmpdir, "foo-0", rootCACert, rootCAKey); err != nil {
|
||||||
actual := WriteCertAndKey(tmpdir, "foo", caCert, rootCAKey)
|
|
||||||
if actual != nil {
|
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"failed WriteCertAndKey with an error: %v",
|
"failed WriteCertAndKey with an error: %v",
|
||||||
actual,
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if err = WriteCert(tmpdir, "foo-1", rootCACert); err != nil {
|
||||||
|
t.Errorf(
|
||||||
|
"failed WriteCert with an error: %v",
|
||||||
|
err,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,9 +288,15 @@ func TestCertOrKeyExist(t *testing.T) {
|
|||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "valid path and name",
|
desc: "valid path and name, both cert and key exist",
|
||||||
path: tmpdir,
|
path: tmpdir,
|
||||||
name: "foo",
|
name: "foo-0",
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "valid path and name, only cert exist",
|
||||||
|
path: tmpdir,
|
||||||
|
name: "foo-1",
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user