@@ -6,23 +6,76 @@ import (
66 "path/filepath"
77 "testing"
88
9- "github.com/kr/pretty"
9+ "github.com/stretchr/testify/assert"
10+ "github.com/stretchr/testify/require"
11+ "github.com/tendermint/starport/starport/pkg/protoanalysis"
1012)
1113
12- func TestExampleDiscover (t * testing.T ) {
14+ func TestDiscover (t * testing.T ) {
1315 goPath := os .Getenv ("GOPATH" )
14- t .Run ("test folder without proto files" , func (t * testing.T ) {
15- pretty .Println (Discover (
16- context .Background (),
17- filepath .Join (goPath , "src/github.com/tendermint/starport/local_test/mars" ),
18- "proto" ,
19- ))
20- })
21- t .Run ("test folder with proto files" , func (t * testing.T ) {
22- pretty .Println (Discover (
23- context .Background (),
24- filepath .Join (goPath , "src/github.com/tendermint/starport" ),
25- "starport/pkg/protoc/data/include/google/protobuf" ,
26- ))
27- })
16+ testDataPath := filepath .Join (goPath ,
17+ "src/github.com/tendermint/starport/starport/pkg/cosmosanalysis/module/testdata" )
18+
19+ type args struct {
20+ sourcePath string
21+ protoDir string
22+ }
23+ tests := []struct {
24+ name string
25+ args args
26+ want []Module
27+ err error
28+ }{
29+ {
30+ name : "test valid" ,
31+ args : args {
32+ sourcePath : filepath .Join (testDataPath , "planet" ),
33+ protoDir : "proto" ,
34+ },
35+ want : []Module {
36+ {Pkg : protoanalysis.Package {}},
37+ },
38+ }, {
39+ name : "test no proto folder" ,
40+ args : args {
41+ sourcePath : filepath .Join (testDataPath , "planet" ),
42+ protoDir : "" ,
43+ },
44+ want : []Module {
45+ {Pkg : protoanalysis.Package {}},
46+ },
47+ }, {
48+ name : "test invalid proto folder" ,
49+ args : args {
50+ sourcePath : filepath .Join (testDataPath , "planet" ),
51+ protoDir : "invalid" ,
52+ },
53+ want : nil ,
54+ }, {
55+ name : "test invalid folder" ,
56+ args : args {
57+ sourcePath : filepath .Join (testDataPath , "invalid" ),
58+ protoDir : "" ,
59+ },
60+ want : []Module {},
61+ }, {
62+ name : "test invalid main and proto folder" ,
63+ args : args {
64+ sourcePath : filepath .Join (testDataPath , "../../.." ),
65+ protoDir : "proto" ,
66+ },
67+ want : []Module {},
68+ },
69+ }
70+ for _ , tt := range tests {
71+ t .Run (tt .name , func (t * testing.T ) {
72+ got , err := Discover (context .Background (), tt .args .sourcePath , tt .args .protoDir )
73+ if tt .err != nil {
74+ require .ErrorIs (t , err , tt .err )
75+ return
76+ }
77+ require .NoError (t , err )
78+ assert .Equal (t , tt .want , got )
79+ })
80+ }
2881}
0 commit comments