Skip to content
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

test: use T.TempDir to create temporary test directory #1021

Merged
merged 1 commit into from
Jul 24, 2022
Merged
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
13 changes: 3 additions & 10 deletions x/registration/internal/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"io/ioutil"
"os"
"testing"

"github.com/enigmampc/SecretNetwork/x/registration/internal/types"
Expand All @@ -11,9 +10,7 @@ import (
)

func TestInitGenesisNoMaster(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, keeper := CreateTestInput(t, false, tempDir, true)
//
//cert, err := ioutil.ReadFile("../../testdata/attestation_cert")
Expand All @@ -29,9 +26,7 @@ func TestInitGenesisNoMaster(t *testing.T) {
}

func TestInitGenesis(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, keeper := CreateTestInput(t, false, tempDir, true)

cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw")
Expand All @@ -47,9 +42,7 @@ func TestInitGenesis(t *testing.T) {
}

func TestExportGenesis(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, keeper := CreateTestInput(t, false, tempDir, true)

cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw")
Expand Down
18 changes: 5 additions & 13 deletions x/registration/internal/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ func init() {
}

func TestNewKeeper(t *testing.T) {
tempDir, err := ioutil.TempDir("", "reg")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
_, regKeeper := CreateTestInput(t, false, tempDir, true)
require.NotNil(t, regKeeper)
}

func TestNewKeeper_Node(t *testing.T) {
tempDir, err := ioutil.TempDir("", "reg")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()

seedPath := filepath.Join(tempDir, types.SecretNodeCfgFolder, types.SecretNodeSeedConfig)

err = os.MkdirAll(filepath.Join(tempDir, types.SecretNodeCfgFolder), 0o700)
err := os.MkdirAll(filepath.Join(tempDir, types.SecretNodeCfgFolder), 0o700)
require.NoError(t, err)

err = ioutil.WriteFile(seedPath, CreateTestSeedConfig(t), 0o700)
Expand All @@ -47,9 +43,7 @@ func TestNewKeeper_Node(t *testing.T) {
}

func TestKeeper_RegisterationStore(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, regKeeper := CreateTestInput(t, false, tempDir, true)

cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw")
Expand All @@ -73,9 +67,7 @@ func TestKeeper_RegisterationStore(t *testing.T) {
}

func TestKeeper_RegisterNode(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, regKeeper := CreateTestInput(t, false, tempDir, true)

cert, err := ioutil.ReadFile("../../testdata/attestation_cert_sw")
Expand Down
5 changes: 1 addition & 4 deletions x/registration/internal/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"io/ioutil"
"os"
"testing"

sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -18,9 +17,7 @@ import (
)

func TestNewQuerier(t *testing.T) {
tempDir, err := ioutil.TempDir("", "wasm")
require.NoError(t, err)
defer os.RemoveAll(tempDir)
tempDir := t.TempDir()
ctx, keeper := CreateTestInput(t, false, tempDir, true)

nodeIdInvalid := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Expand Down