-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: in REPL mode allow user to specify path to file for byte…
…s field (#280) * Enhancement: in REPL mode allow user to specify path to file for bytes field * fixing imports * applying changes from review Co-authored-by: ktr <ktr@syfm.me>
- Loading branch information
1 parent
ad23f4b
commit b5f289f
Showing
7 changed files
with
123 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
usage: call <method name> | ||
|
||
Options: | ||
--dig-manually prompt asks whether to dig down if it encountered to a message field | ||
--enrich enrich response output includes header, message, trailer and status | ||
--bytes-from-file interpret TYPE_BYTES input as a relative path to a file | ||
--dig-manually prompt asks whether to dig down if it encountered to a message field | ||
--enrich enrich response output includes header, message, trailer and status | ||
|
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
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 |
---|---|---|
@@ -1,16 +1,72 @@ | ||
package proto_test | ||
package proto | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/protobuf/protoc-gen-go/descriptor" | ||
"github.com/ktr0731/evans/fill" | ||
"github.com/ktr0731/evans/fill/proto" | ||
"github.com/ktr0731/evans/prompt" | ||
) | ||
|
||
type testPrompt struct { | ||
prompt.Prompt | ||
|
||
input string | ||
} | ||
|
||
func (t *testPrompt) Input() (string, error) { | ||
return t.input, nil | ||
} | ||
|
||
func TestInteractiveProtoFiller(t *testing.T) { | ||
f := proto.NewInteractiveFiller(nil, "") | ||
err := f.Fill("invalid type", false) | ||
f := NewInteractiveFiller(nil, "") | ||
err := f.Fill("invalid type", fill.InteractiveFillerOpts{}) | ||
if err != fill.ErrCodecMismatch { | ||
t.Errorf("must return fill.ErrCodecMismatch because the arg is invalid type, but got: %s", err) | ||
} | ||
|
||
tp := &testPrompt{ | ||
input: "../../go.mod", | ||
} | ||
|
||
f = NewInteractiveFiller(tp, "") | ||
f.bytesFromFile = true | ||
|
||
var v interface{} | ||
v, err = f.inputPrimitiveField(descriptor.FieldDescriptorProto_TYPE_BYTES) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if _, ok := v.([]byte); !ok { | ||
t.Errorf("value should be of type []byte") | ||
} | ||
|
||
fileContent, err := readFileFromRelativePath(tp.input) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if len(v.([]byte)) != len(fileContent) { | ||
t.Error("contents should have the same length") | ||
} | ||
|
||
tp = &testPrompt{ | ||
input: "\\x6f\\x67\\x69\\x73\\x6f", | ||
} | ||
|
||
f = NewInteractiveFiller(tp, "") | ||
|
||
v, err = f.inputPrimitiveField(descriptor.FieldDescriptorProto_TYPE_BYTES) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if _, ok := v.([]byte); !ok { | ||
t.Errorf("value should be of type []byte") | ||
} | ||
|
||
if string(v.([]byte)) != "ogiso" { | ||
t.Error("unequal content") | ||
} | ||
} |
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