-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(buf): set correct prefix for api (#4198)
(cherry picked from commit 1316d69) # Conflicts: # ignite/templates/app/files/proto/buf.gen.pulsar.yaml # ignite/templates/app/files/proto/buf.gen.pulsar.yaml.plush # ignite/templates/app/files/{{protoDir}}/buf.gen.pulsar.yaml # ignite/templates/app/proto_test.go # integration/app/cmd_proto_path_test.go
- Loading branch information
1 parent
8cebfc3
commit 0300f27
Showing
5 changed files
with
188 additions
and
1 deletion.
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
23 changes: 23 additions & 0 deletions
23
ignite/templates/app/files/proto/buf.gen.pulsar.yaml.plush
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,23 @@ | ||
# This file is auto-generated from Ignite. You can edit | ||
# the file content but do not change the file name or path. | ||
# | ||
# buf.gen.pulsar.yaml | ||
# | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: <%= ModulePath %>/api | ||
except: | ||
- buf.build/googleapis/googleapis | ||
- buf.build/cosmos/gogo-proto | ||
- buf.build/cosmos/cosmos-proto | ||
override: | ||
buf.build/cosmos/cosmos-sdk: cosmossdk.io/api | ||
plugins: | ||
- name: go-pulsar | ||
out: ./api | ||
opt: paths=source_relative | ||
- name: go-grpc | ||
out: ./api | ||
opt: paths=source_relative |
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,58 @@ | ||
package app | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBufFiles(t *testing.T) { | ||
want := []string{"buf.work.yaml"} | ||
protoDir, err := os.ReadDir("files/{{protoDir}}") | ||
require.NoError(t, err) | ||
for _, e := range protoDir { | ||
want = append(want, filepath.Join("{{protoDir}}", strings.TrimSuffix(e.Name(), ".plush"))) | ||
} | ||
|
||
got, err := BufFiles() | ||
Check failure on line 20 in ignite/templates/app/proto_test.go GitHub Actions / test (ubuntu-latest)
|
||
require.NoError(t, err) | ||
require.ElementsMatch(t, want, got) | ||
} | ||
|
||
func TestCutTemplatePrefix(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
arg string | ||
want string | ||
ok bool | ||
}{ | ||
{ | ||
name: "with prefix", | ||
arg: "{{protoDir}}/myvalue", | ||
want: "myvalue", | ||
ok: true, | ||
}, | ||
{ | ||
name: "with 2 prefix", | ||
arg: "{{protoDir}}/{{protoDir}}/myvalue", | ||
want: "{{protoDir}}/myvalue", | ||
ok: true, | ||
}, | ||
{ | ||
name: "without prefix", | ||
arg: "myvalue", | ||
want: "myvalue", | ||
ok: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, ok := CutTemplatePrefix(tt.arg) | ||
Check failure on line 53 in ignite/templates/app/proto_test.go GitHub Actions / test (ubuntu-latest)
|
||
require.Equal(t, tt.ok, ok) | ||
require.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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,104 @@ | ||
//go:build !relayer | ||
|
||
package app_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/ignite/cli/v29/ignite/config/chain" | ||
Check failure on line 14 in integration/app/cmd_proto_path_test.go GitHub Actions / test app on ubuntu-latest
|
||
"github.com/ignite/cli/v29/ignite/config/chain/base" | ||
v1 "github.com/ignite/cli/v29/ignite/config/chain/v1" | ||
"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step" | ||
"github.com/ignite/cli/v29/ignite/pkg/xyaml" | ||
envtest "github.com/ignite/cli/v29/integration" | ||
) | ||
|
||
const newProtoPath = "myProto" | ||
|
||
var ( | ||
bobName = "bob" | ||
cfg = v1.Config{ | ||
Config: base.Config{ | ||
Version: 1, | ||
Build: base.Build{ | ||
Proto: base.Proto{ | ||
Path: newProtoPath, | ||
}, | ||
}, | ||
Accounts: []base.Account{ | ||
{ | ||
Name: "alice", | ||
Coins: []string{"100000000000token", "10000000000000000000stake"}, | ||
Mnemonic: "slide moment original seven milk crawl help text kick fluid boring awkward doll wonder sure fragile plate grid hard next casual expire okay body", | ||
}, | ||
{ | ||
Name: bobName, | ||
Coins: []string{"100000000000token", "10000000000000000000stake"}, | ||
Mnemonic: "trap possible liquid elite embody host segment fantasy swim cable digital eager tiny broom burden diary earn hen grow engine pigeon fringe claim program", | ||
}, | ||
}, | ||
Faucet: base.Faucet{ | ||
Name: &bobName, | ||
Coins: []string{"500token", "100000000stake"}, | ||
Host: ":4501", | ||
}, | ||
Genesis: xyaml.Map{"chain_id": "mars-1"}, | ||
}, | ||
Validators: []v1.Validator{ | ||
{ | ||
Name: "alice", | ||
Bonded: "100000000stake", | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
// TestGenerapAppCheckBufPulsarPath tests scaffolding a new chain and checks if the buf.gen.pulsar.yaml file is correct | ||
func TestGenerapAppCheckBufPulsarPath(t *testing.T) { | ||
var ( | ||
env = envtest.New(t) | ||
app = env.Scaffold("github.com/test/blog") | ||
) | ||
|
||
bufGenPulsarPath := filepath.Join(app.SourcePath(), "proto", "buf.gen.pulsar.yaml") | ||
_, statErr := os.Stat(bufGenPulsarPath) | ||
require.False(t, os.IsNotExist(statErr), "buf.gen.pulsar.yaml should be scaffolded") | ||
|
||
result, err := os.ReadFile(bufGenPulsarPath) | ||
require.NoError(t, err) | ||
|
||
require.True(t, strings.Contains(string(result), "default: github.com/test/blog/api"), "buf.gen.pulsar.yaml should contain the correct api override") | ||
|
||
app.EnsureSteady() | ||
} | ||
|
||
func TestChangeProtoPath(t *testing.T) { | ||
var ( | ||
env = envtest.New(t) | ||
app = env.Scaffold("github.com/test/protopath", "--proto-dir", newProtoPath) | ||
appPath = app.SourcePath() | ||
cfgPath = filepath.Join(appPath, chain.ConfigFilenames[0]) | ||
) | ||
|
||
// set the custom config path. | ||
file, err := os.Create(cfgPath) | ||
require.NoError(t, err) | ||
require.NoError(t, yaml.NewEncoder(file).Encode(cfg)) | ||
require.NoError(t, file.Close()) | ||
app.SetConfigPath(cfgPath) | ||
|
||
env.Must(env.Exec("create a list with a custom proto path from config", | ||
step.NewSteps(step.New( | ||
step.Exec(envtest.IgniteApp, "s", "list", "--yes", "listUser", "email"), | ||
step.Workdir(app.SourcePath()), | ||
)), | ||
)) | ||
|
||
app.EnsureSteady() | ||
} |