Skip to content

refactor: use t.TempDir() instead of os.MkdirTemp #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/fsccli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ func TestArtifactsGen(t *testing.T) {
Expect(err).NotTo(HaveOccurred())
defer gexec.CleanupBuildArtifacts()

tmpDir, err := os.MkdirTemp("", t.Name())
Expect(err).NotTo(HaveOccurred())

defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()

topologyFolder := filepath.Join("testdata", "fabric_iou.yaml")
session, err := gexec.Start(exec.Command(cli, "artifactsgen", "gen", "-t", topologyFolder, "-o", tmpDir), GinkgoWriter, GinkgoWriter)
Expand Down
18 changes: 3 additions & 15 deletions integration/nwo/cmd/cryptogen/csp/csp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import (
)

func TestLoadPrivateKey(t *testing.T) {
testDir, err := os.MkdirTemp("", "csp-test")
if err != nil {
t.Fatalf("Failed to create test directory: %s", err)
}
defer os.RemoveAll(testDir)
testDir := t.TempDir()
priv, err := csp2.GeneratePrivateKey(testDir)
if err != nil {
t.Fatalf("Failed to generate private key: %s", err)
Expand All @@ -45,11 +41,7 @@ func TestLoadPrivateKey(t *testing.T) {
}

func TestLoadPrivateKey_BadPEM(t *testing.T) {
testDir, err := os.MkdirTemp("", "csp-test")
if err != nil {
t.Fatalf("Failed to create test directory: %s", err)
}
defer os.RemoveAll(testDir)
testDir := t.TempDir()

badPEMFile := filepath.Join(testDir, "badpem_sk")

Expand Down Expand Up @@ -108,11 +100,7 @@ func TestLoadPrivateKey_BadPEM(t *testing.T) {
}

func TestGeneratePrivateKey(t *testing.T) {
testDir, err := os.MkdirTemp("", "csp-test")
if err != nil {
t.Fatalf("Failed to create test directory: %s", err)
}
defer os.RemoveAll(testDir)
testDir := t.TempDir()

expectedFile := filepath.Join(testDir, "priv_sk")
priv, err := csp2.GeneratePrivateKey(testDir)
Expand Down
Loading