Skip to content

Commit

Permalink
transport/ca/localca: remove uses of deprecated io/ioutil
Browse files Browse the repository at this point in the history
Using their replacements instead. Also making use of t.TempDir(),
to let Go's testing take care of cleaning up.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Nov 21, 2022
1 parent b069c86 commit 0eecfe2
Showing 1 changed file with 6 additions and 25 deletions.
31 changes: 6 additions & 25 deletions transport/ca/localca/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@ package localca
import (
"encoding/pem"
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/initca"
)

func tempName() (string, error) {
tmpf, err := ioutil.TempFile("", "transport_cachedkp_")
if err != nil {
return "", err
}

name := tmpf.Name()
tmpf.Close()
return name, nil
}

func TestEncodePEM(t *testing.T) {
p := &pem.Block{
Type: "CERTIFICATE REQUEST",
Expand All @@ -48,24 +37,16 @@ func TestLoadSigner(t *testing.T) {
t.Fatalf("expected an errNotSetup (%v), got: %v", errNotSetup, err)
}

lca.KeyFile, err = tempName()
if err != nil {
t.Fatal(err)
}
defer os.Remove(lca.KeyFile)

lca.CertFile, err = tempName()
if err != nil {
t.Fatal(err)
}
defer os.Remove(lca.CertFile)
tmpDir := t.TempDir()
lca.KeyFile = filepath.Join(tmpDir, "KeyFile")
lca.CertFile = filepath.Join(tmpDir, "CertFile")

err = ioutil.WriteFile(lca.KeyFile, keyPEM, 0644)
err = os.WriteFile(lca.KeyFile, keyPEM, 0644)
if err != nil {
t.Fatal(err)
}

err = ioutil.WriteFile(lca.CertFile, certPEM, 0644)
err = os.WriteFile(lca.CertFile, certPEM, 0644)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 0eecfe2

Please sign in to comment.