multi: repleace ioutil.ReadFile

This commit is contained in:
erik
2023-06-13 21:22:44 +07:00
committed by ErikEk
parent 619c8f4eb8
commit ab83343c87
23 changed files with 55 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
package cert_test
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
@@ -42,10 +42,10 @@ func TestIsOutdatedCert(t *testing.T) {
// number of IPs and domains.
for numIPs := 1; numIPs <= len(extraIPs); numIPs++ {
for numDomains := 1; numDomains <= len(extraDomains); numDomains++ {
certBytes, err := ioutil.ReadFile(certPath)
certBytes, err := os.ReadFile(certPath)
require.NoError(t, err)
keyBytes, err := ioutil.ReadFile(keyPath)
keyBytes, err := os.ReadFile(keyPath)
require.NoError(t, err)
_, parsedCert, err := cert.LoadCertFromBytes(
@@ -98,10 +98,10 @@ func TestIsOutdatedPermutation(t *testing.T) {
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
require.NoError(t, err)
certBytes, err = ioutil.ReadFile(certPath)
certBytes, err = os.ReadFile(certPath)
require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath)
keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err)
_, parsedCert, err := cert.LoadCertFromBytes(certBytes, keyBytes)
@@ -171,10 +171,10 @@ func TestTLSDisableAutofill(t *testing.T) {
require.NoError(t, err)
// Read certs from disk.
certBytes, err = ioutil.ReadFile(certPath)
certBytes, err = os.ReadFile(certPath)
require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath)
keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err)
// Load the certificate.
@@ -230,10 +230,10 @@ func TestTLSConfig(t *testing.T) {
err = cert.WriteCertPair(certPath, keyPath, certBytes, keyBytes)
require.NoError(t, err)
certBytes, err = ioutil.ReadFile(certPath)
certBytes, err = os.ReadFile(certPath)
require.NoError(t, err)
keyBytes, err = ioutil.ReadFile(keyPath)
keyBytes, err = os.ReadFile(keyPath)
require.NoError(t, err)
// Load the certificate.

View File

@@ -3,7 +3,7 @@ package cert
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"os"
"sync"
)
@@ -31,11 +31,11 @@ var (
func GetCertBytesFromPath(certPath, keyPath string) (certBytes,
keyBytes []byte, err error) {
certBytes, err = ioutil.ReadFile(certPath)
certBytes, err = os.ReadFile(certPath)
if err != nil {
return nil, nil, err
}
keyBytes, err = ioutil.ReadFile(keyPath)
keyBytes, err = os.ReadFile(keyPath)
if err != nil {
return nil, nil, err
}