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

#911 Enhance command sysl pb --mode=pb to output binary message #912

Merged
merged 8 commits into from
Jun 24, 2020
Prev Previous commit
Next Next commit
#911 Corrected func name to GeneratePBBinaryMessageFile.
  • Loading branch information
ericzhang6222 committed Jun 24, 2020
commit 0c436f1e1473514598ff3b6c22271fca48eba1d7
2 changes: 1 addition & 1 deletion cmd/sysl/cmd_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ func (p *protobuf) Execute(args cmdutils.ExecuteArgs) error {
if p.output == "-" {
return pbutil.GeneratePBBinaryMessage(os.Stdout, args.Modules[0])
}
return pbutil.GeneratePBBinaryMessage2File(args.Modules[0], p.output, args.Filesystem)
return pbutil.GeneratePBBinaryMessageFile(args.Modules[0], p.output, args.Filesystem)
}
4 changes: 2 additions & 2 deletions pkg/pbutil/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func FTextPB(w io.Writer, m protoreflect.ProtoMessage) error {
return err
}

// GeneratePBBinaryMessage2File generates binary message to the file specified by `filename`.
func GeneratePBBinaryMessage2File(m protoreflect.ProtoMessage, filename string, fs afero.Fs) error {
// GeneratePBBinaryMessageFile generates binary message to the file specified by `filename`.
func GeneratePBBinaryMessageFile(m protoreflect.ProtoMessage, filename string, fs afero.Fs) error {
if m == nil {
return fmt.Errorf("module is nil: %#v", filename)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/pbutil/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,24 @@ func TestFPBNilModule(t *testing.T) {
assert.Equal(t, "", output.String())
}

func TestPB(t *testing.T) {
func TestGeneratePBBinaryMessageFile(t *testing.T) {
t.Parallel()

unmarshalled := &sysl.Module{}
fs := afero.NewMemMapFs()
filename := "/out.pb"
require.NoError(t, GeneratePBBinaryMessage2File(testModule(), filename, fs))
require.NoError(t, GeneratePBBinaryMessageFile(testModule(), filename, fs))
output, err := afero.ReadFile(fs, filename)
require.NoError(t, err)
require.NoError(t, proto.Unmarshal(output, unmarshalled))
assert.True(t, proto.Equal(unmarshalled, protoreflect.ProtoMessage(testModule())))
}

func TestPBNilModule(t *testing.T) {
func TestGeneratePBBinaryMessageFileNilModule(t *testing.T) {
t.Parallel()

fs := afero.NewMemMapFs()
filename := "/out.pb"
require.Error(t, GeneratePBBinaryMessage2File(nil, filename, fs))
require.Error(t, GeneratePBBinaryMessageFile(nil, filename, fs))
syslutil.AssertFsHasExactly(t, fs)
}