Skip to content

Commit

Permalink
Merge pull request #1021 from Juneezee/test/t.TempDir
Browse files Browse the repository at this point in the history
test: use `T.TempDir` to create temporary test directory
  • Loading branch information
Cashmaney authored Jul 24, 2022
2 parents cd2cc91 + 28644b7 commit 0a03410
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
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

0 comments on commit 0a03410

Please sign in to comment.