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

Migrate testify/assert and testify/require dependencies to use gotest.tools #419

Closed
wants to merge 5 commits into from
Closed
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
32 changes: 16 additions & 16 deletions cmd/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
junoCmd "github.com/NethermindEth/juno/cmd/juno"
"github.com/NethermindEth/juno/internal/juno"
"github.com/NethermindEth/juno/internal/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

type spyJuno struct {
Expand Down Expand Up @@ -55,14 +55,14 @@ Juno is a Go implementation of a StarkNet full node client made with ❤️ by N
cmd := junoCmd.NewCmd(newSpyJuno, quitTest())
cmd.SetOut(b)
err := cmd.Execute()
require.NoError(t, err)
assert.NilError(t, err)

actual := b.String()
assert.Equal(t, expected, actual)
assert.Check(t, is.Equal(expected, actual))

n, ok := junoCmd.StarkNetNode.(*spyJuno)
require.Equal(t, true, ok)
assert.Equal(t, []string{"run", "shutdown"}, n.calls)
assert.Equal(t, true, ok)
assert.Check(t, is.DeepEqual([]string{"run", "shutdown"}, n.calls))
})

t.Run("config precedence", func(t *testing.T) {
Expand Down Expand Up @@ -255,15 +255,15 @@ network: 1

err := cmd.Execute()
if tc.expectErr {
require.Error(t, err)
assert.Assert(t, is.ErrorContains(err, ""))
return
}
require.NoError(t, err)
assert.NilError(t, err)

n, ok := junoCmd.StarkNetNode.(*spyJuno)
require.Equal(t, true, ok)
assert.Equal(t, tc.expectedConfig, n.cfg)
assert.Equal(t, []string{"run", "shutdown"}, n.calls)
assert.Equal(t, true, ok)
assert.Check(t, is.DeepEqual(tc.expectedConfig, n.cfg))
assert.Check(t, is.DeepEqual([]string{"run", "shutdown"}, n.calls))
})
}
})
Expand All @@ -280,21 +280,21 @@ func quitTest() chan os.Signal {

func tempCfgFile(t *testing.T, cfg string) (string, func()) {
f, err := ioutil.TempFile("", "junoCfg.*.yaml")
require.NoError(t, err)
assert.NilError(t, err)

defer func() {
err = f.Close()
require.NoError(t, err)
assert.NilError(t, err)
}()

_, err = f.WriteString(cfg)
require.NoError(t, err)
assert.NilError(t, err)

err = f.Sync()
require.NoError(t, err)
assert.NilError(t, err)

return f.Name(), func() {
err = os.Remove(f.Name())
require.NoError(t, err)
assert.NilError(t, err)
}
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/leanovate/gopter v0.2.9
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.0
github.com/torquem-ch/mdbx-go v0.24.2
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
Expand All @@ -26,6 +25,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/urfave/cli/v2 v2.10.2 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down Expand Up @@ -70,7 +70,6 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions internal/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

"github.com/NethermindEth/juno/internal/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

func TestNew(t *testing.T) {
Expand All @@ -23,17 +23,17 @@ func TestNew(t *testing.T) {
_, err := New(cfg)

if cfg.Network == utils.GOERLI || cfg.Network == utils.MAINNET {
assert.NoError(t, err)
assert.Check(t, err)
} else {
assert.Error(t, err, ErrUnknownNetwork)
assert.Check(t, is.ErrorContains(err, ""), ErrUnknownNetwork)
}
})
}
})

t.Run("default db-path", func(t *testing.T) {
defaultDataDir, err := utils.DefaultDataDir()
require.NoError(t, err)
assert.NilError(t, err)

networks := []utils.Network{utils.GOERLI, utils.MAINNET}

Expand All @@ -45,11 +45,11 @@ func TestNew(t *testing.T) {
DatabasePath: filepath.Join(defaultDataDir, n.String()),
}
node, err := New(cfg)
require.NoError(t, err)
assert.NilError(t, err)

junoN, ok := node.(*Node)
require.Equal(t, true, ok)
assert.Equal(t, expectedCfg, junoN.cfg)
assert.Equal(t, true, ok)
assert.Check(t, is.DeepEqual(expectedCfg, junoN.cfg))
})
}
})
Expand Down
7 changes: 4 additions & 3 deletions internal/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package log
import (
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

func TestGlobalLoggerVerbosity(t *testing.T) {
Expand Down Expand Up @@ -33,9 +34,9 @@ func TestGlobalLoggerVerbosity(t *testing.T) {
t.Run(test.verbosity, func(t *testing.T) {
err := SetGlobalLogger(test.verbosity)
if test.err {
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
} else {
assert.NoError(t, err)
assert.Check(t, err)
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions internal/utils/datadir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package utils
import (
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

func TestDataDir(t *testing.T) {
Expand Down Expand Up @@ -75,6 +76,6 @@ func TestDataDir(t *testing.T) {
}

for _, tc := range tests {
assert.Equal(t, tc.expectedDir, DataDir(tc.os, tc.userDataDir, tc.userHomeDir))
assert.Check(t, is.Equal(tc.expectedDir, DataDir(tc.os, tc.userDataDir, tc.userHomeDir)))
}
}
15 changes: 8 additions & 7 deletions internal/utils/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package utils
import (
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)

func TestNetwork(t *testing.T) {
Expand All @@ -12,11 +13,11 @@ func TestNetwork(t *testing.T) {
for _, n := range networks {
switch n {
case GOERLI:
assert.Equal(t, "goerli", n.String())
assert.Check(t, is.Equal("goerli", n.String()))
case MAINNET:
assert.Equal(t, "mainnet", n.String())
assert.Check(t, is.Equal("mainnet", n.String()))
default:
assert.Equal(t, "", n.String())
assert.Check(t, is.Equal("", n.String()))

}
}
Expand All @@ -25,11 +26,11 @@ func TestNetwork(t *testing.T) {
for _, n := range networks {
switch n {
case GOERLI:
assert.Equal(t, "https://alpha4.starknet.io", n.URL())
assert.Check(t, is.Equal("https://alpha4.starknet.io", n.URL()))
case MAINNET:
assert.Equal(t, "https://alpha-mainnet.starknet.io", n.URL())
assert.Check(t, is.Equal("https://alpha-mainnet.starknet.io", n.URL()))
default:
assert.Equal(t, "", n.URL())
assert.Check(t, is.Equal("", n.URL()))

}
}
Expand Down
Loading