1
0
Fork 0

Remove deprecated functions

master
Philip O'Toole 2 years ago
parent 069db5dc05
commit 68c7bc41b9

@ -6,7 +6,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
@ -26,10 +25,8 @@ func Test_TLSServiceInsecure(t *testing.T) {
if err != nil {
t.Fatalf("failed to generate self-signed cert: %s", err)
}
s.CertFile = mustWriteTempFile(cert)
defer os.Remove(s.CertFile)
s.KeyFile = mustWriteTempFile(key)
defer os.Remove(s.KeyFile)
s.CertFile = mustWriteTempFile(t, cert)
s.KeyFile = mustWriteTempFile(t, key)
s.BuildInfo = map[string]interface{}{
"version": "the version",
@ -83,10 +80,8 @@ func Test_TLSServiceSecure(t *testing.T) {
if err != nil {
t.Fatalf("failed to generate self-signed cert: %s", err)
}
s.CertFile = mustWriteTempFile(cert)
defer os.Remove(s.CertFile)
s.KeyFile = mustWriteTempFile(key)
defer os.Remove(s.KeyFile)
s.CertFile = mustWriteTempFile(t, cert)
s.KeyFile = mustWriteTempFile(t, key)
s.BuildInfo = map[string]interface{}{
"version": "the version",
@ -181,12 +176,9 @@ func Test_TLSServiceSecureMutual(t *testing.T) {
m := &MockStore{}
c := &mockClusterService{}
s := New("127.0.0.1:0", m, c, nil)
s.CertFile = mustWriteTempFile(certServer)
defer os.Remove(s.CertFile)
s.KeyFile = mustWriteTempFile(keyServer)
defer os.Remove(s.KeyFile)
s.CACertFile = mustWriteTempFile(caCertPEM) // Enables client verification by HTTP server
defer os.Remove(s.CACertFile)
s.CertFile = mustWriteTempFile(t, certServer)
s.KeyFile = mustWriteTempFile(t, keyServer)
s.CACertFile = mustWriteTempFile(t, caCertPEM) // Enables client verification by HTTP server
s.BuildInfo = map[string]interface{}{
"version": "the version",
}
@ -237,9 +229,10 @@ func Test_TLSServiceSecureMutual(t *testing.T) {
}
// mustWriteTempFile writes the given bytes to a temporary file, and returns the
// path to the file. If there is an error, it panics.
func mustWriteTempFile(b []byte) string {
f, err := ioutil.TempFile("", "rqlite-test")
// path to the file. If there is an error, it panics. The file will be automatically
// deleted when the test ends.
func mustWriteTempFile(t *testing.T, b []byte) string {
f, err := os.CreateTemp(t.TempDir(), "rqlite-test")
if err != nil {
panic("failed to create temp file")
}

@ -4,7 +4,7 @@ import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"io/ioutil"
"os"
"testing"
"time"
)
@ -171,7 +171,7 @@ func Test_CreateClientConfig(t *testing.T) {
// path to the file. If there is an error, it panics. The file will be automatically
// deleted when the test ends.
func mustWriteTempFile(t *testing.T, b []byte) string {
f, err := ioutil.TempFile(t.TempDir(), "rqlite-test")
f, err := os.CreateTemp(t.TempDir(), "rqlite-test")
if err != nil {
panic("failed to create temp file")
}

Loading…
Cancel
Save