Skip to content

Commit f5bba89

Browse files
committed
add unit test and testdata
1 parent 5493d82 commit f5bba89

File tree

4 files changed

+78
-16
lines changed

4 files changed

+78
-16
lines changed

starport/pkg/cosmosanalysis/module/module_test.go

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module github.com/tendermint/planet
2+
3+
go 1.16
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
syntax = "proto3";
2+
package tendermint.planet.planet;
3+
option go_package = "github.com/tendermint/planet/x/planet/types";
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package types

0 commit comments

Comments
 (0)