diff --git a/changelog.md b/changelog.md index 8c87a09713..2323b8a7d2 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,7 @@ ### Changes + - [#4157](https://github.com/ignite/cli/pull/4157) Upgrade golang to 1.22 - [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`. - [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler. diff --git a/ignite/cmd/plugin_test.go b/ignite/cmd/plugin_test.go index d4cf70fede..cb9bfd846f 100644 --- a/ignite/cmd/plugin_test.go +++ b/ignite/cmd/plugin_test.go @@ -45,6 +45,7 @@ func buildRootCmd(ctx context.Context) *cobra.Command { } func assertFlags(t *testing.T, expectedFlags []*plugin.Flag, execCmd *plugin.ExecutedCommand) { + t.Helper() var ( have []string expected []string @@ -116,6 +117,7 @@ func TestLinkPluginCmds(t *testing.T) { { name: "ok: link foo at root", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() cmd := &plugin.Command{ Use: "foo", } @@ -135,6 +137,7 @@ ignite { name: "ok: link foo at subcommand", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() cmd := &plugin.Command{ Use: "foo", PlaceCommandUnder: "ignite scaffold", @@ -155,6 +158,7 @@ ignite { name: "ok: link foo at subcommand with incomplete PlaceCommandUnder", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() cmd := &plugin.Command{ Use: "foo", PlaceCommandUnder: "scaffold", @@ -175,6 +179,7 @@ ignite { name: "fail: link to runnable command", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -193,6 +198,7 @@ ignite { name: "fail: link to unknown command", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -211,6 +217,7 @@ ignite { name: "fail: plugin name exists in legacy commands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -228,6 +235,7 @@ ignite { name: "fail: plugin name with args exists in legacy commands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -245,6 +253,7 @@ ignite { name: "fail: plugin name exists in legacy sub commands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -263,6 +272,7 @@ ignite { name: "ok: link multiple at root", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() fooCmd := &plugin.Command{ Use: "foo", } @@ -293,6 +303,7 @@ ignite { name: "ok: link with subcommands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() cmd := &plugin.Command{ Use: "foo", Commands: []*plugin.Command{ @@ -324,6 +335,7 @@ ignite { name: "ok: link with multiple subcommands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() cmd := &plugin.Command{ Use: "foo", Commands: []*plugin.Command{ @@ -413,6 +425,7 @@ func TestLinkPluginHooks(t *testing.T) { // helper to assert pluginInterface.ExecuteHook*() calls in expected order // (pre, then post, then cleanup) expectExecuteHook = func(t *testing.T, p *mocks.PluginInterface, expectedFlags []*plugin.Flag, hooks ...*plugin.Hook) { + t.Helper() matcher := func(hook *plugin.Hook) any { return mock.MatchedBy(func(execHook *plugin.ExecutedHook) bool { return hook.Name == execHook.Hook.Name && @@ -463,6 +476,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "fail: command not runnable", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -481,6 +495,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "fail: command doesn't exists", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() p.EXPECT(). Manifest(ctx). Return(&plugin.Manifest{ @@ -499,6 +514,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "ok: single hook", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() hook := &plugin.Hook{ Name: "test-hook", PlaceHookOn: "scaffold chain", @@ -512,6 +528,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "ok: multiple hooks on same command", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() hook1 := &plugin.Hook{ Name: "test-hook-1", PlaceHookOn: "scaffold chain", @@ -529,6 +546,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "ok: multiple hooks on different commands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() hookChain1 := &plugin.Hook{ Name: "test-hook-1", PlaceHookOn: "scaffold chain", @@ -551,6 +569,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "ok: duplicate hook names on same command", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() hooks := []*plugin.Hook{ { Name: "test-hook", @@ -570,6 +589,7 @@ func TestLinkPluginHooks(t *testing.T) { { name: "ok: duplicate hook names on different commands", setup: func(t *testing.T, ctx context.Context, p *mocks.PluginInterface) { + t.Helper() hookChain := &plugin.Hook{ Name: "test-hook", PlaceHookOn: "ignite scaffold chain", @@ -619,6 +639,7 @@ func TestLinkPluginHooks(t *testing.T) { // execCmd executes all the runnable commands contained in c. func execCmd(t *testing.T, c *cobra.Command, args []string) { + t.Helper() if c.Runnable() { os.Args = strings.Fields(c.CommandPath()) os.Args = append(os.Args, args...) diff --git a/ignite/config/plugins/config_test.go b/ignite/config/plugins/config_test.go index 2c4df2bc20..eeefe54ee5 100644 --- a/ignite/config/plugins/config_test.go +++ b/ignite/config/plugins/config_test.go @@ -259,6 +259,7 @@ func TestConfigSave(t *testing.T) { { name: "fail: config path is empty", buildConfig: func(t *testing.T) *pluginsconfig.Config { + t.Helper() return &pluginsconfig.Config{} }, expectedError: "plugin config save: empty path", @@ -266,6 +267,7 @@ func TestConfigSave(t *testing.T) { { name: "ok: config path is a file that doesn't exist", buildConfig: func(t *testing.T) *pluginsconfig.Config { + t.Helper() cfg, err := pluginsconfig.ParseDir(t.TempDir()) require.NoError(t, err) return cfg @@ -275,6 +277,7 @@ func TestConfigSave(t *testing.T) { { name: "ok: config path is an existing file", buildConfig: func(t *testing.T) *pluginsconfig.Config { + t.Helper() // copy testdata/igniteapps.yml to tmp because it will be modified dir := t.TempDir() bz, err := os.ReadFile("testdata/igniteapps.yml") diff --git a/ignite/internal/plugin/consumer_test.go b/ignite/internal/plugin/consumer_test.go index 0b3e356d4d..cccc64e595 100644 --- a/ignite/internal/plugin/consumer_test.go +++ b/ignite/internal/plugin/consumer_test.go @@ -38,6 +38,7 @@ func TestConsumerPlugin(t *testing.T) { name: "fail: writeFenesis w/o genesis.json", args: []string{"writeGenesis"}, setup: func(t *testing.T, path string) { + t.Helper() // Add priv_validator_key.json to path bz, err := os.ReadFile("testdata/consumer/config/priv_validator_key.json") require.NoError(t, err) @@ -51,6 +52,7 @@ func TestConsumerPlugin(t *testing.T) { name: "ok: writeGenesis", args: []string{"writeGenesis"}, setup: func(t *testing.T, path string) { + t.Helper() // Add priv_validator_key.json to path bz, err := os.ReadFile("testdata/consumer/config/priv_validator_key.json") require.NoError(t, err) @@ -73,6 +75,7 @@ func TestConsumerPlugin(t *testing.T) { name: "ok: isInitialized returns true", args: []string{"isInitialized"}, setup: func(t *testing.T, path string) { + t.Helper() // isInitialized returns true if there's a consumer genesis with an // InitialValSet length != 0 // Add priv_validator_key.json to path diff --git a/ignite/pkg/cosmosclient/cosmosclient_test.go b/ignite/pkg/cosmosclient/cosmosclient_test.go index ea7489866f..bbad683991 100644 --- a/ignite/pkg/cosmosclient/cosmosclient_test.go +++ b/ignite/pkg/cosmosclient/cosmosclient_test.go @@ -45,6 +45,7 @@ type suite struct { } func newClient(t *testing.T, setup func(suite), opts ...cosmosclient.Option) cosmosclient.Client { + t.Helper() s := suite{ rpcClient: mocks.NewRPCClient(t), accountRetriever: mocks.NewAccountRetriever(t), diff --git a/ignite/pkg/cosmosfaucet/http_test.go b/ignite/pkg/cosmosfaucet/http_test.go index 8798b7a822..dd5f4d3394 100644 --- a/ignite/pkg/cosmosfaucet/http_test.go +++ b/ignite/pkg/cosmosfaucet/http_test.go @@ -38,7 +38,10 @@ func TestServeHTTPCORS(t *testing.T) { f.ServeHTTP(res, req) // Assert - require.Equal(t, http.StatusNoContent, res.Result().StatusCode) + result := res.Result() + defer result.Body.Close() // Ensure the response body is closed + + require.Equal(t, http.StatusNoContent, result.StatusCode) }) } } diff --git a/ignite/pkg/cosmostxcollector/adapter/postgres/postgres_test.go b/ignite/pkg/cosmostxcollector/adapter/postgres/postgres_test.go index 98faf36474..1ecc8dcef7 100644 --- a/ignite/pkg/cosmostxcollector/adapter/postgres/postgres_test.go +++ b/ignite/pkg/cosmostxcollector/adapter/postgres/postgres_test.go @@ -162,7 +162,7 @@ func TestSave(t *testing.T) { ) attrStmt. ExpectExec(). - WithArgs(evtID, string(evtAttr.Key), jsonEvtAttrValue). + WithArgs(evtID, evtAttr.Key, jsonEvtAttrValue). WillReturnResult(insertResult) mock.ExpectCommit() @@ -540,6 +540,7 @@ func TestEventQueryWithEventAttrFilters(t *testing.T) { } func createMatchEqualSQLMock(t *testing.T) (*sql.DB, sqlmock.Sqlmock) { + t.Helper() db, mock, err := sqlmock.New( sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual), ) diff --git a/ignite/pkg/cosmostxcollector/collector_test.go b/ignite/pkg/cosmostxcollector/collector_test.go index f5061d782c..90db312671 100644 --- a/ignite/pkg/cosmostxcollector/collector_test.go +++ b/ignite/pkg/cosmostxcollector/collector_test.go @@ -30,7 +30,7 @@ func TestCollector(t *testing.T) { fromHeight, mock.AnythingOfType("chan<- []cosmosclient.TX"), ). - Run(func(ctx context.Context, fromHeight int64, tc chan<- []cosmosclient.TX) { + Run(func(_ context.Context, _ int64, tc chan<- []cosmosclient.TX) { defer close(tc) // Send the collected block transactions @@ -46,7 +46,7 @@ func TestCollector(t *testing.T) { mock.Anything, mock.AnythingOfType("[]cosmosclient.TX"), ). - Run(func(ctx context.Context, txs []cosmosclient.TX) { + Run(func(_ context.Context, txs []cosmosclient.TX) { // Save the transactions savedTXs = append(savedTXs, txs) }). @@ -75,7 +75,7 @@ func TestCollectorWithCollectError(t *testing.T) { mock.AnythingOfType("int64"), mock.AnythingOfType("chan<- []cosmosclient.TX"), ). - Run(func(ctx context.Context, fromHeight int64, tc chan<- []cosmosclient.TX) { + Run(func(_ context.Context, _ int64, tc chan<- []cosmosclient.TX) { close(tc) }). Return(wantErr). @@ -106,7 +106,7 @@ func TestCollectorWithSaveError(t *testing.T) { mock.AnythingOfType("int64"), mock.AnythingOfType("chan<- []cosmosclient.TX"), ). - Run(func(ctx context.Context, fromHeight int64, tc chan<- []cosmosclient.TX) { + Run(func(_ context.Context, _ int64, tc chan<- []cosmosclient.TX) { defer close(tc) // Send the collected block transactions diff --git a/ignite/pkg/dirchange/dirchange_test.go b/ignite/pkg/dirchange/dirchange_test.go index 055045b7ea..d7a361ceef 100644 --- a/ignite/pkg/dirchange/dirchange_test.go +++ b/ignite/pkg/dirchange/dirchange_test.go @@ -18,6 +18,7 @@ const ( ) func randomBytes(t *testing.T, n int) []byte { + t.Helper() bytes := make([]byte, n) _, err := rand.Read(bytes) require.NoError(t, err) diff --git a/ignite/pkg/httpstatuschecker/httpstatuschecker_test.go b/ignite/pkg/httpstatuschecker/httpstatuschecker_test.go index d9a2d6ed01..22dcb2d95a 100644 --- a/ignite/pkg/httpstatuschecker/httpstatuschecker_test.go +++ b/ignite/pkg/httpstatuschecker/httpstatuschecker_test.go @@ -21,7 +21,7 @@ func TestCheckStatus(t *testing.T) { } for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(tt.returnedStatus) })) defer ts.Close() diff --git a/ignite/pkg/jsonfile/jsonfile_test.go b/ignite/pkg/jsonfile/jsonfile_test.go index c522f9be2c..d98d100d16 100644 --- a/ignite/pkg/jsonfile/jsonfile_test.go +++ b/ignite/pkg/jsonfile/jsonfile_test.go @@ -356,7 +356,7 @@ func TestFromURL(t *testing.T) { t.Run(tt.name, func(t *testing.T) { url := tt.args.url if url == "" { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { file, err := os.ReadFile(tt.args.filepath) require.NoError(t, err) _, err = w.Write(file) diff --git a/ignite/pkg/protoanalysis/protoutil/creator_test.go b/ignite/pkg/protoanalysis/protoutil/creator_test.go index ed201c95ca..22176d9747 100644 --- a/ignite/pkg/protoanalysis/protoutil/creator_test.go +++ b/ignite/pkg/protoanalysis/protoutil/creator_test.go @@ -74,7 +74,7 @@ func TestCreatePackage(t *testing.T) { } } -// Options +// Options. func TestCreateOption(t *testing.T) { cases := []struct { name, constant, setField string @@ -221,7 +221,7 @@ func TestCreateService(t *testing.T) { } } -// Fields +// Fields. func TestCreateField(t *testing.T) { cases := []struct { name, typeName string @@ -332,15 +332,16 @@ func TestCreateMessage(t *testing.T) { // options added first, then fields and then enums. lenOpts, lenFields, lenEnums := len(test.options), len(test.fields), len(test.enums) for i, field := range message.Elements { - if i < lenOpts { + switch { + case i < lenOpts: opt, ok := field.(*proto.Option) require.True(t, ok, "expected option, got %T", field) require.Equal(t, test.options[i], opt, "expected %v, got %v", test.options[i], opt) - } else if i < lenOpts+lenFields { + case i < lenOpts+lenFields: field, ok := field.(*proto.NormalField) require.True(t, ok, "expected field, got %T", field) require.Equal(t, test.fields[i-lenOpts], field, "expected %v, got %v", test.fields[i-lenOpts], field) - } else { + default: enum, ok := field.(*proto.Enum) require.True(t, ok, "expected enum, got %T", field) require.Equal(t, test.enums[i-lenOpts-lenFields], enum, "expected %v, got %v", test.enums[i-lenOpts-lenFields], enum) @@ -387,7 +388,7 @@ func TestCreateEnumField(t *testing.T) { } } -// Enums: +// Enums:. func TestCreateEnum(t *testing.T) { cases := []struct { name string @@ -435,7 +436,7 @@ func TestCreateEnum(t *testing.T) { } } -// OneOf fields: +// OneOf fields:. func TestCreateOneofField(t *testing.T) { cases := []struct { name, typeName string @@ -473,7 +474,7 @@ func TestCreateOneofField(t *testing.T) { } } -// Oneof: +// Oneof:. func TestCreateOneof(t *testing.T) { cases := []struct { name string diff --git a/ignite/pkg/protoanalysis/protoutil/cursor_test.go b/ignite/pkg/protoanalysis/protoutil/cursor_test.go index 8e336cb311..e1203c93d8 100644 --- a/ignite/pkg/protoanalysis/protoutil/cursor_test.go +++ b/ignite/pkg/protoanalysis/protoutil/cursor_test.go @@ -7,6 +7,12 @@ import ( "github.com/stretchr/testify/require" ) +const ( + world = "World" + elements = "Elements" + kirby = "Kirby" +) + // Make a simple replacement of package -> import. func TestSimpleReplacement(t *testing.T) { f, err := parseStringProto(`package "package"`) @@ -38,7 +44,7 @@ func TestSimpleInsertAfter(t *testing.T) { Apply(f, nil, func(c *Cursor) bool { n := c.Node() if n, ok := n.(*proto.Message); ok { - if n.Name == "World" { + if n.Name == world { msg = NewMessage("WeComeInPeace") c.InsertAfter(msg) } @@ -50,7 +56,7 @@ func TestSimpleInsertAfter(t *testing.T) { Apply(f, nil, func(c *Cursor) bool { n := c.Node() if n, ok := n.(*proto.Message); ok { - if n.Name == "World" { + if n.Name == world { next, ok := c.Next() require.True(t, ok) require.True(t, next.(*proto.Message).Name == "WeComeInPeace") @@ -61,9 +67,11 @@ func TestSimpleInsertAfter(t *testing.T) { } // Can really only panic with comments since -// other elements in nodes aren't Visitees +// other elements in nodes aren't Visitees. +// +//nolint:dupword func TestInsertAfterPanic(t *testing.T) { - f, err := parseStringProto(`syntax = "proto3" + f, err := parseStringProto(`syntax = "proto3" // my import import "this"; @@ -95,7 +103,7 @@ func TestSimpleInsertBefore(t *testing.T) { Apply(f, nil, func(c *Cursor) bool { n := c.Node() if n, ok := n.(*proto.Message); ok { - if n.Name == "World" { + if n.Name == world { // add hello between say and world msg = NewMessage("Hello") c.InsertBefore(msg) @@ -120,7 +128,9 @@ func TestSimpleInsertBefore(t *testing.T) { } // Can really only panic with comments since -// other elements in nodes aren't Visitees +// other elements in nodes aren't Visitees. +// +//nolint:dupword func TestInsertBeforePanic(t *testing.T) { f, err := parseStringProto(`syntax = "proto3" @@ -158,15 +168,15 @@ func TestAppendFile(t *testing.T) { Append(f, o) require.True(t, containsElement(f, o)) - oneof_f := NewOneofField("this", "string", 2) + oneofF := NewOneofField("this", "string", 2) // Can directly append an option if required: opt := NewOption("this", "that") - Append(oneof_f, opt) - require.True(t, containsElement(oneof_f, opt)) + Append(oneofF, opt) + require.True(t, containsElement(oneofF, opt)) oneof := NewOneof("myoneof") - Append(oneof, oneof_f) - require.True(t, containsElement(oneof, oneof_f)) + Append(oneof, oneofF) + require.True(t, containsElement(oneof, oneofF)) normalfield := NewField("that", "string", 3) @@ -187,9 +197,9 @@ func TestAppendFile(t *testing.T) { // An empty enum e := NewEnum("Hey") // Add an enum field to it: - e_f := NewEnumField("HEY", 1) - Append(e, e_f) - require.True(t, containsElement(e, e_f)) + ef := NewEnumField("HEY", 1) + Append(e, ef) + require.True(t, containsElement(e, ef)) Append(f, e) require.True(t, containsElement(f, e)) @@ -247,9 +257,9 @@ func TestCursorOps(t *testing.T) { require.True(t, ok) require.True(t, parent.Filename == "") // currently useless. - require.True(t, c.Name() == "Elements") + require.True(t, c.Name() == elements) } - if n.Name == "World" { + if n.Name == world { require.True(t, c.IsLast()) n, ok := c.Next() require.False(t, ok) @@ -259,7 +269,7 @@ func TestCursorOps(t *testing.T) { require.True(t, ok) require.True(t, parent.Filename == "") // currently useless. - require.True(t, c.Name() == "Elements") + require.True(t, c.Name() == elements) } if n.Name == "Hey" { @@ -273,7 +283,7 @@ func TestCursorOps(t *testing.T) { require.True(t, ok) require.True(t, parent.Name == "World") // currently useless. - require.True(t, c.Name() == "Elements") + require.True(t, c.Name() == elements) } } @@ -288,7 +298,7 @@ func TestCursorOps(t *testing.T) { require.True(t, ok) require.True(t, parent.Name == "World") // currently useless. - require.True(t, c.Name() == "Elements") + require.True(t, c.Name() == elements) } // Don't make sense for elements not contained in a slice (currently diff --git a/ignite/pkg/protoanalysis/protoutil/proto_test.go b/ignite/pkg/protoanalysis/protoutil/proto_test.go index 3c021f8f37..2d27870ffe 100644 --- a/ignite/pkg/protoanalysis/protoutil/proto_test.go +++ b/ignite/pkg/protoanalysis/protoutil/proto_test.go @@ -25,7 +25,7 @@ func containsElement(f proto.Visitee, v proto.Visitee) bool { } // parseStringProto takes a string, parses it into a proto.File, and returns a ProtoFile. -// Nodes can be created easily (newnode) by wrapping them correctly. (e.g field in a message) +// Nodes can be created easily (newnode) by wrapping them correctly. (e.g field in a message). func parseStringProto(s string) (*proto.Proto, error) { p, err := proto.NewParser(strings.NewReader(s)).Parse() if err != nil { @@ -89,9 +89,9 @@ service Msg {} ) // Test that the changes from adding a list with starport scaffold list -// are applied correctly to tx.proto +// are applied correctly to tx.proto. func TestAddEmptyList_tx(t *testing.T) { - typename, modname := "Kirby", "chainname" + typename, modname := kirby, "chainname" f, err := parseStringProto(txProto) require.NoError(t, err) @@ -160,7 +160,7 @@ func TestAddEmptyList_tx(t *testing.T) { } // Test that the changes from adding a list with starport scaffold list -// are applied correctly to genesis.proto +// are applied correctly to genesis.proto. func TestAddEmptyList_genesis(t *testing.T) { typename, modname := "Kirby", "mod" f, err := parseStringProto(genesisProto) diff --git a/ignite/pkg/xast/xast_test.go b/ignite/pkg/xast/xast_test.go index 3c458e304a..9e259ee676 100644 --- a/ignite/pkg/xast/xast_test.go +++ b/ignite/pkg/xast/xast_test.go @@ -25,14 +25,14 @@ func TestInspect(t *testing.T) { }{ { name: "random error", - f: func(n ast.Node) error { + f: func(ast.Node) error { return errors.New("oups") }, expectedError: "oups", }, { name: "stop error", - f: func(n ast.Node) error { + f: func(ast.Node) error { calls++ return xast.ErrStop }, @@ -40,7 +40,7 @@ func TestInspect(t *testing.T) { }, { name: "no error", - f: func(n ast.Node) error { + f: func(ast.Node) error { calls++ return nil }, diff --git a/ignite/pkg/xembed/xembed_test.go b/ignite/pkg/xembed/xembed_test.go index edb65a6d3e..31acc4e62e 100644 --- a/ignite/pkg/xembed/xembed_test.go +++ b/ignite/pkg/xembed/xembed_test.go @@ -57,7 +57,7 @@ func TestFileList(t *testing.T) { }, }, { - name: "sub sub testdata folder", + name: "sub sub testdata folder", //nolint:dupword args: args{ efs: fsProtoTest, path: "testdata/subtestdata/subtestdata", diff --git a/ignite/pkg/xgit/xgit_test.go b/ignite/pkg/xgit/xgit_test.go index 8935060dd5..a1e09ff546 100644 --- a/ignite/pkg/xgit/xgit_test.go +++ b/ignite/pkg/xgit/xgit_test.go @@ -29,6 +29,7 @@ func TestInitAndCommit(t *testing.T) { { name: "dir is not inside an existing repo", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() err := os.WriteFile(path.Join(dir, "foo"), []byte("hello"), 0o755) require.NoError(t, err) @@ -43,6 +44,7 @@ func TestInitAndCommit(t *testing.T) { // In this repo, there's no existing commit but a standalone uncommitted // foo file that shouldn't be included in the xgit.InitAndCommit's commit. dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -62,6 +64,7 @@ func TestInitAndCommit(t *testing.T) { { name: "dir is an existing repo", dirFunc: func(t *testing.T) string { + t.Helper() // In this repo, there's one existing commit, and an uncommitted baz file // that must be included in the xgit.InitAndCommit's commit. dir := t.TempDir() @@ -144,6 +147,7 @@ func TestAreChangesCommitted(t *testing.T) { { name: "dir is not a git repo", dirFunc: func(t *testing.T) string { + t.Helper() return t.TempDir() }, expectedResult: true, @@ -151,6 +155,7 @@ func TestAreChangesCommitted(t *testing.T) { { name: "dir is a empty git repo", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -161,6 +166,7 @@ func TestAreChangesCommitted(t *testing.T) { { name: "dir is a dirty empty git repo", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -173,6 +179,7 @@ func TestAreChangesCommitted(t *testing.T) { { name: "dir is a cleaned git repo", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -195,6 +202,7 @@ func TestAreChangesCommitted(t *testing.T) { { name: "dir is a dirty git repo", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -390,6 +398,7 @@ func TestIsRepository(t *testing.T) { { name: "path is a repository", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() _, err := git.PlainInit(dir, false) require.NoError(t, err) @@ -400,6 +409,7 @@ func TestIsRepository(t *testing.T) { { name: "path is not a repository", dirFunc: func(t *testing.T) string { + t.Helper() return t.TempDir() }, expected: false, @@ -407,6 +417,7 @@ func TestIsRepository(t *testing.T) { { name: "repository error", dirFunc: func(t *testing.T) string { + t.Helper() dir := t.TempDir() err := os.Chmod(dir, 0) require.NoError(t, err) diff --git a/ignite/pkg/xhttp/response_test.go b/ignite/pkg/xhttp/response_test.go index 336f5ee8f1..1b5ab4e54a 100644 --- a/ignite/pkg/xhttp/response_test.go +++ b/ignite/pkg/xhttp/response_test.go @@ -17,12 +17,14 @@ func TestResponseJSON(t *testing.T) { data := map[string]interface{}{"a": 1} require.NoError(t, ResponseJSON(w, http.StatusCreated, data)) resp := w.Result() + defer resp.Body.Close() // Ensure the response body is closed require.Equal(t, http.StatusCreated, resp.StatusCode) require.Equal(t, "application/json", resp.Header.Get("Content-Type")) body, _ := io.ReadAll(resp.Body) - dataJSON, _ := json.Marshal(data) + dataJSON, err := json.Marshal(data) + require.NoError(t, err) require.Equal(t, dataJSON, body) } diff --git a/ignite/pkg/xtime/unix_test.go b/ignite/pkg/xtime/unix_test.go index 0f661d8947..bcac885e82 100644 --- a/ignite/pkg/xtime/unix_test.go +++ b/ignite/pkg/xtime/unix_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - "github.com/ignite/cli/v29/ignite/pkg/xtime" - "github.com/stretchr/testify/require" + + "github.com/ignite/cli/v29/ignite/pkg/xtime" ) func TestSeconds(t *testing.T) { diff --git a/ignite/services/chain/chain_test.go b/ignite/services/chain/chain_test.go index ddfc356730..a62c627e48 100644 --- a/ignite/services/chain/chain_test.go +++ b/ignite/services/chain/chain_test.go @@ -29,6 +29,8 @@ func TestSourceVersion(t *testing.T) { } func tempSource(t *testing.T, tarPath string) (path string) { + t.Helper() + f, err := os.Open(tarPath) require.NoError(t, err) diff --git a/ignite/services/chain/lint_test.go b/ignite/services/chain/lint_test.go index dc1f90b240..7821f73d66 100644 --- a/ignite/services/chain/lint_test.go +++ b/ignite/services/chain/lint_test.go @@ -2,5 +2,5 @@ package chain_test import "testing" -func TestChainLint(t *testing.T) { +func TestChainLint(_ *testing.T) { } diff --git a/ignite/services/plugin/grpc/v1/types_command_test.go b/ignite/services/plugin/grpc/v1/types_command_test.go index 8958006ac7..9b68bd89e6 100644 --- a/ignite/services/plugin/grpc/v1/types_command_test.go +++ b/ignite/services/plugin/grpc/v1/types_command_test.go @@ -131,7 +131,8 @@ func TestExecutedCommandImportFlags(t *testing.T) { cmd := cobra.Command{} cmd.Flags().StringP("foo", "f", "bar", "foo usage") cmd.PersistentFlags().IntP("test", "t", 1, "test usage") - cmd.ParseFlags([]string{"--foo", "baz", "--test", "42"}) + err := cmd.ParseFlags([]string{"--foo", "baz", "--test", "42"}) + require.NoError(t, err) // Act execCmd.ImportFlags(&cmd) diff --git a/ignite/services/plugin/plugin_test.go b/ignite/services/plugin/plugin_test.go index babae27521..25acc45649 100644 --- a/ignite/services/plugin/plugin_test.go +++ b/ignite/services/plugin/plugin_test.go @@ -192,7 +192,7 @@ func TestNewPlugin(t *testing.T) { } // Helper to make a local git repository with gofile committed. -// Returns the repo directory and the git.Repository +// Returns the repo directory and the git.Repository. func makeGitRepo(t *testing.T, name string) (string, *git.Repository) { t.Helper() @@ -240,6 +240,7 @@ func TestPluginLoad(t *testing.T) { { name: "fail: plugin is already in error", buildPlugin: func(t *testing.T) Plugin { + t.Helper() return Plugin{ Error: errors.New("oups"), } @@ -249,6 +250,7 @@ func TestPluginLoad(t *testing.T) { { name: "fail: no go files in srcPath", buildPlugin: func(t *testing.T) Plugin { + t.Helper() return Plugin{ srcPath: path.Join(wd, "testdata"), name: "testdata", @@ -259,6 +261,7 @@ func TestPluginLoad(t *testing.T) { { name: "ok: from local", buildPlugin: func(t *testing.T) Plugin { + t.Helper() path := scaffoldPlugin(t, t.TempDir(), "github.com/foo/bar", false) return Plugin{ srcPath: path, @@ -269,6 +272,7 @@ func TestPluginLoad(t *testing.T) { { name: "ok: from git repo", buildPlugin: func(t *testing.T) Plugin { + t.Helper() repoDir, _ := makeGitRepo(t, "remote") cloneDir := t.TempDir() @@ -283,6 +287,7 @@ func TestPluginLoad(t *testing.T) { { name: "fail: git repo doesnt exists", buildPlugin: func(t *testing.T) Plugin { + t.Helper() cloneDir := t.TempDir() return Plugin{ @@ -297,6 +302,7 @@ func TestPluginLoad(t *testing.T) { { name: "ok: from git repo with tag", buildPlugin: func(t *testing.T) Plugin { + t.Helper() repoDir, repo := makeGitRepo(t, "remote-tag") h, err := repo.Head() require.NoError(t, err) @@ -320,6 +326,7 @@ func TestPluginLoad(t *testing.T) { { name: "ok: from git repo with branch", buildPlugin: func(t *testing.T) Plugin { + t.Helper() repoDir, repo := makeGitRepo(t, "remote-branch") w, err := repo.Worktree() require.NoError(t, err) @@ -343,6 +350,7 @@ func TestPluginLoad(t *testing.T) { { name: "ok: from git repo with hash", buildPlugin: func(t *testing.T) Plugin { + t.Helper() repoDir, repo := makeGitRepo(t, "remote-hash") h, err := repo.Head() require.NoError(t, err) @@ -361,6 +369,7 @@ func TestPluginLoad(t *testing.T) { { name: "fail: git ref not found", buildPlugin: func(t *testing.T) Plugin { + t.Helper() repoDir, _ := makeGitRepo(t, "remote-no-ref") cloneDir := t.TempDir() diff --git a/ignite/services/plugin/scaffold_test.go b/ignite/services/plugin/scaffold_test.go index 8c48544163..c9c0e5a5e7 100644 --- a/ignite/services/plugin/scaffold_test.go +++ b/ignite/services/plugin/scaffold_test.go @@ -33,7 +33,7 @@ func TestScaffold(t *testing.T) { func TestScaffoldedConfig(t *testing.T) { // Arrange ctx := context.Background() - path := scaffoldApp(t, ctx, fooBarAppURI) + path := scaffoldApp(ctx, t, fooBarAppURI) // Act cfg := readConfig(t, path) @@ -46,7 +46,7 @@ func TestScaffoldedConfig(t *testing.T) { func TestScaffoldedTests(t *testing.T) { // Arrange ctx := context.Background() - path := scaffoldApp(t, ctx, fooBarAppURI) + path := scaffoldApp(ctx, t, fooBarAppURI) path = filepath.Join(path, "integration") // Act @@ -61,7 +61,7 @@ func TestScaffoldedTests(t *testing.T) { require.NoError(t, err) } -func scaffoldApp(t *testing.T, ctx context.Context, path string) string { +func scaffoldApp(ctx context.Context, t *testing.T, path string) string { t.Helper() path, err := plugin.Scaffold(ctx, t.TempDir(), path, false) diff --git a/ignite/services/scaffolder/type_test.go b/ignite/services/scaffolder/type_test.go index 3c999a2077..6c15220f29 100644 --- a/ignite/services/scaffolder/type_test.go +++ b/ignite/services/scaffolder/type_test.go @@ -148,7 +148,7 @@ func TestParseTypeFields(t *testing.T) { } } -// indirectly tests checkForbiddenTypeField() +// indirectly tests checkForbiddenTypeField(). func TestCheckForbiddenTypeIndexField(t *testing.T) { tests := []struct { name string @@ -216,5 +216,5 @@ func TestCheckForbiddenTypeIndexField(t *testing.T) { } } -func TestAddType(t *testing.T) { +func TestAddType(_ *testing.T) { } diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index 6904d478d1..71f976f891 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -59,8 +59,8 @@ var ( } ) -// TestGenerapAppCheckBufPulsarPath tests scaffolding a new chain and checks if the buf.gen.pulsar.yaml file is correct -func TestGenerapAppCheckBufPulsarPath(t *testing.T) { +// TestGenerateAppCheckBufPulsarPath tests scaffolding a new chain and checks if the buf.gen.pulsar.yaml file is correct. +func TestGenerateAppCheckBufPulsarPath(t *testing.T) { var ( env = envtest.New(t) app = env.Scaffold("github.com/test/blog") diff --git a/integration/chain/cache_test.go b/integration/chain/cache_test.go index 049cbd2882..fc0bbcac55 100644 --- a/integration/chain/cache_test.go +++ b/integration/chain/cache_test.go @@ -96,6 +96,7 @@ func TestCliWithCaching(t *testing.T) { } func deleteCachedFiles(t *testing.T, vueGenerated, openapiGenerated, typesDir string) { + t.Helper() require.NoError(t, os.RemoveAll(vueGenerated)) require.NoError(t, os.Remove(openapiGenerated)) diff --git a/integration/faucet/faucet_test.go b/integration/faucet/faucet_test.go index 079588d6f0..ae0da1c4e7 100644 --- a/integration/faucet/faucet_test.go +++ b/integration/faucet/faucet_test.go @@ -39,8 +39,8 @@ func TestRequestCoinsFromFaucet(t *testing.T) { faucetClient = cosmosfaucet.NewClient(faucetURL) ) isErrTransferRequest := func(err error, expectedCode int) { - require.ErrorAs(t, err, &cosmosfaucet.ErrTransferRequest{}) - errTransfer := err.(cosmosfaucet.ErrTransferRequest) + var errTransfer cosmosfaucet.ErrTransferRequest + require.ErrorAs(t, err, &errTransfer) require.EqualValues(t, expectedCode, errTransfer.StatusCode) } @@ -69,12 +69,12 @@ func TestRequestCoinsFromFaucet(t *testing.T) { // the faucet sends the default faucet coins value when not specified _, err = faucetClient.Transfer(ctx, cosmosfaucet.NewTransferRequest(addr, nil)) require.NoError(t, err) - checkAccountBalance(t, ctx, cosmosClient, addr, defaultCoins) + checkAccountBalance(ctx, t, cosmosClient, addr, defaultCoins) // the faucet can send a specified amount of coins _, err = faucetClient.Transfer(ctx, cosmosfaucet.NewTransferRequest(addr, []string{"20token", "2stake"})) require.NoError(t, err) - checkAccountBalance(t, ctx, cosmosClient, addr, []string{"30token", "3stake"}) + checkAccountBalance(ctx, t, cosmosClient, addr, []string{"30token", "3stake"}) // faucet request fails on malformed coins _, err = faucetClient.Transfer(ctx, cosmosfaucet.NewTransferRequest(addr, []string{"no-token"})) @@ -101,10 +101,11 @@ func TestRequestCoinsFromFaucet(t *testing.T) { }) } require.NoError(t, g.Wait()) - checkAccountBalance(t, ctx, cosmosClient, addr, []string{"130token", "13stake"}) + checkAccountBalance(ctx, t, cosmosClient, addr, []string{"130token", "13stake"}) } -func checkAccountBalance(t *testing.T, ctx context.Context, c cosmosclient.Client, accAddr string, coins []string) { +func checkAccountBalance(ctx context.Context, t *testing.T, c cosmosclient.Client, accAddr string, coins []string) { + t.Helper() resp, err := banktypes.NewQueryClient(c.Context()).AllBalances(ctx, &banktypes.QueryAllBalancesRequest{ Address: accAddr, }) diff --git a/integration/network/network_test.go b/integration/network/network_test.go index 7dbb16f0df..b2f87aa972 100644 --- a/integration/network/network_test.go +++ b/integration/network/network_test.go @@ -100,6 +100,7 @@ func setupSPN(env envtest.Env) string { } func migrateSPNConfig(t *testing.T, spnPath string) { + t.Helper() configPath := filepath.Join(spnPath, spnConfigFile) rawCfg, err := os.ReadFile(configPath) require.NoError(t, err) diff --git a/integration/relayer/cmd_relayer_test.go b/integration/relayer/cmd_relayer_test.go index 9cedb817b1..3e3efef01f 100644 --- a/integration/relayer/cmd_relayer_test.go +++ b/integration/relayer/cmd_relayer_test.go @@ -202,14 +202,14 @@ func (k Keeper) OnTimeoutIbcPostPacket(ctx sdk.Context, packet channeltypes.Pack type ( QueryChannels struct { Channels []struct { - ChannelId string `json:"channel_id"` + ChannelID string `json:"channel_id"` ConnectionHops []string `json:"connection_hops"` Counterparty struct { - ChannelId string `json:"channel_id"` - PortId string `json:"port_id"` + ChannelID string `json:"channel_id"` + PortID string `json:"port_id"` } `json:"counterparty"` Ordering string `json:"ordering"` - PortId string `json:"port_id"` + PortID string `json:"port_id"` State string `json:"state"` Version string `json:"version"` } `json:"channels"` @@ -221,8 +221,8 @@ type ( ) func runChain( - t *testing.T, ctx context.Context, + t *testing.T, env envtest.Env, app envtest.App, cfg v1.Config, @@ -402,10 +402,10 @@ func TestBlogIBC(t *testing.T) { availableport.WithMaxPort(5000), ) require.NoError(t, err) - earthAPI, earthRPC, earthGRPC, earthFaucet := runChain(t, ctx, env, app, earthConfig, tmpDir, ports[:7]) + earthAPI, earthRPC, earthGRPC, earthFaucet := runChain(ctx, t, env, app, earthConfig, tmpDir, ports[:7]) earthChainID := earthConfig.Genesis["chain_id"].(string) earthHome := earthConfig.Validators[0].Home - marsAPI, marsRPC, marsGRPC, marsFaucet := runChain(t, ctx, env, app, marsConfig, tmpDir, ports[7:]) + marsAPI, marsRPC, marsGRPC, marsFaucet := runChain(ctx, t, env, app, marsConfig, tmpDir, ports[7:]) marsChainID := marsConfig.Genesis["chain_id"].(string) marsHome := marsConfig.Validators[0].Home