-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
- Loading branch information
1 parent
2134fc2
commit d6b5032
Showing
7 changed files
with
146 additions
and
22 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,86 @@ | ||
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" | ||
"testing" | ||
) | ||
|
||
type testPrompt struct { | ||
input string | ||
} | ||
|
||
func (t *testPrompt) Input() (string, error) { | ||
return t.input, nil | ||
} | ||
|
||
func (t *testPrompt) Select(message string, options []string) (selected string, _ error) { | ||
panic("implement me") | ||
} | ||
|
||
func (t *testPrompt) SetPrefix(prefix string) { | ||
} | ||
|
||
func (t *testPrompt) SetPrefixColor(color prompt.Color) { | ||
} | ||
|
||
func (t *testPrompt) SetCompleter(c prompt.Completer) { | ||
} | ||
|
||
func (t *testPrompt) GetCommandHistory() []string { | ||
return []string{} | ||
} | ||
|
||
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