-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): auto migrate dependency tools (#3505)
* create method to update go imports into a go file * add tools helpers * add migration pre handler * fix the method to update tools import * uncomment migrations questions * add changelog * idente ignite/pkg/cosmosgen/install_test.go tests Co-authored-by: Jerónimo Albi <[email protected]> * fix ignite/cmd/chain.go mesages Co-authored-by: Jerónimo Albi <[email protected]> * fix ignite/cmd/chain.go remove msg Co-authored-by: Jerónimo Albi <[email protected]> * ident ignite/pkg/cosmosgen/install_test.go Co-authored-by: Jerónimo Albi <[email protected]> * fix double ? in the ask question and improve comments * use io.writer intead return a byte array to goanalysis.UpdateInitImports method * fix goanalysis test package name * Update ignite/cmd/chain.go vars Co-authored-by: Jerónimo Albi <[email protected]> * run gofmt --------- Co-authored-by: Jerónimo Albi <[email protected]>
- Loading branch information
1 parent
91d0080
commit b543016
Showing
6 changed files
with
520 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package cosmosgen_test | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ignite/cli/ignite/pkg/cosmosgen" | ||
) | ||
|
||
func TestMissingTools(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
astFile *ast.File | ||
want []string | ||
}{ | ||
{ | ||
name: "no missing tools", | ||
astFile: createASTFileWithImports(cosmosgen.DepTools()...), | ||
want: nil, | ||
}, | ||
{ | ||
name: "some missing tools", | ||
astFile: createASTFileWithImports( | ||
"github.com/golang/protobuf/protoc-gen-go", | ||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway", | ||
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger", | ||
), | ||
want: []string{ | ||
"github.com/cosmos/gogoproto/protoc-gen-gocosmos", | ||
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2", | ||
}, | ||
}, | ||
{ | ||
name: "all tools missing", | ||
astFile: createASTFileWithImports(), | ||
want: cosmosgen.DepTools(), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := cosmosgen.MissingTools(tt.astFile) | ||
require.EqualValues(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func TestUnusedTools(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
astFile *ast.File | ||
want []string | ||
}{ | ||
{ | ||
name: "all unused tools", | ||
astFile: createASTFileWithImports( | ||
"fmt", | ||
"github.com/regen-network/cosmos-proto/protoc-gen-gocosmos", | ||
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner", | ||
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner/step", | ||
), | ||
want: []string{ | ||
"github.com/regen-network/cosmos-proto/protoc-gen-gocosmos", | ||
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner", | ||
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner/step", | ||
}, | ||
}, | ||
{ | ||
name: "some unused tools", | ||
astFile: createASTFileWithImports( | ||
"fmt", | ||
"github.com/ignite-hq/cli/ignite/pkg/cmdrunner", | ||
), | ||
want: []string{"github.com/ignite-hq/cli/ignite/pkg/cmdrunner"}, | ||
}, | ||
{ | ||
name: "no tools unused", | ||
astFile: createASTFileWithImports("fmt"), | ||
want: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := cosmosgen.UnusedTools(tt.astFile) | ||
require.EqualValues(t, tt.want, got) | ||
}) | ||
} | ||
} | ||
|
||
// createASTFileWithImports helper function to create an AST file with given imports. | ||
func createASTFileWithImports(imports ...string) *ast.File { | ||
f := &ast.File{Imports: make([]*ast.ImportSpec, len(imports))} | ||
for i, imp := range imports { | ||
f.Imports[i] = &ast.ImportSpec{ | ||
Path: &ast.BasicLit{ | ||
Kind: token.STRING, | ||
Value: strconv.Quote(imp), | ||
}, | ||
} | ||
} | ||
return f | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.