mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +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)
|
||||
_, 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 true
|
||||
return !(os.IsNotExist(certErr) && os.IsNotExist(keyErr))
|
||||
}
|
||||
|
||||
// CSROrKeyExist returns true if one of the CSR or key exists
|
||||
|
@ -262,12 +262,16 @@ func TestCertOrKeyExist(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
caCert := &x509.Certificate{}
|
||||
actual := WriteCertAndKey(tmpdir, "foo", caCert, rootCAKey)
|
||||
if actual != nil {
|
||||
if err = WriteCertAndKey(tmpdir, "foo-0", rootCACert, rootCAKey); err != nil {
|
||||
t.Errorf(
|
||||
"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,
|
||||
},
|
||||
{
|
||||
desc: "valid path and name",
|
||||
desc: "valid path and name, both cert and key exist",
|
||||
path: tmpdir,
|
||||
name: "foo",
|
||||
name: "foo-0",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "valid path and name, only cert exist",
|
||||
path: tmpdir,
|
||||
name: "foo-1",
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user