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

chore: venus-shared: more mock api #4814

Merged
merged 1 commit into from
Mar 4, 2022
Merged
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
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ cborgen:
gogen:
cd venus-shared && go generate ./...

mock-api-gen:
cd ./venus-shared/api/chain/v0 && go run github.com/golang/mock/mockgen -destination=./mock/full.go -package=mock . FullNode
cd ./venus-shared/api/chain/v1 && go run github.com/golang/mock/mockgen -destination=./mock/full.go -package=mock . FullNode

inline-gen:
cd venus-devtool && go run ./inline-gen/main.go ../ ./inline-gen/inlinegen-data.json

Expand All @@ -51,6 +47,7 @@ api-gen:
cd ./venus-devtool/ && go run ./api-gen/ proxy
cd ./venus-devtool/ && go run ./api-gen/ client
cd ./venus-devtool/ && go run ./api-gen/ doc
cd ./venus-devtool/ && go run ./api-gen/ mock

compatible-all: compatible-api compatible-actor

Expand Down
1 change: 1 addition & 0 deletions venus-devtool/api-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func main() {
proxyCmd,
clientCmd,
docGenCmd,
mockCmd,
},
}

Expand Down
38 changes: 38 additions & 0 deletions venus-devtool/api-gen/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"os/exec"
"path/filepath"
"strings"

"github.com/filecoin-project/venus/venus-devtool/util"
"github.com/urfave/cli/v2"
)

var mockCmd = &cli.Command{
Name: "mock",
Action: func(cctx *cli.Context) error {
for _, t := range apiTargets {
if err := mockAPI(t); err != nil {
return err
}
}

return nil
},
}

func mockAPI(t util.APIMeta) error {
opt := t.ParseOpt
opt.ResolveImports = true
_, astMeta, err := util.ParseInterfaceMetas(opt)
if err != nil {
return err
}

dest := filepath.Join(astMeta.Location, "mock/mock_"+strings.ToLower(t.Type.Name())+".go")
cmd := exec.Command("go", "run", "github.com/golang/mock/mockgen", "-destination", dest,
"-package", "mock", t.ParseOpt.ImportPath, t.Type.Name())

return cmd.Run()
}
321 changes: 321 additions & 0 deletions venus-shared/api/gateway/v0/mock/mock_igateway.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading