-
Notifications
You must be signed in to change notification settings - Fork 39
Add Encoding & File to YAML template #338
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/yarpc/yab/encoding" | ||
| "github.com/yarpc/yab/internal/yamlalias" | ||
| "github.com/yarpc/yab/templateargs" | ||
|
|
||
|
|
@@ -56,6 +57,8 @@ type template struct { | |
| Request map[interface{}]interface{} `yaml:"request"` | ||
| Requests []map[interface{}]interface{} `yaml:"requests"` | ||
| Timeout time.Duration `yaml:"timeout"` | ||
| File string `yaml:"file"` | ||
| Encoding string `yaml:"encoding"` | ||
| } | ||
|
|
||
| func readYAMLFile(yamlTemplate string, templateArgs map[string]string, opts *Options) error { | ||
|
|
@@ -129,6 +132,13 @@ func readYAMLRequest(base string, contents []byte, templateArgs map[string]strin | |
| return err | ||
| } | ||
|
|
||
| if t.File != "" { | ||
| body, err = ioutil.ReadFile(t.File) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if t.Peer != "" { | ||
| opts.TOpts.Peers = []string{t.Peer} | ||
| opts.TOpts.PeerList = "" | ||
|
|
@@ -160,6 +170,17 @@ func readYAMLRequest(base string, contents []byte, templateArgs map[string]strin | |
| opts.ROpts.ThriftFile = thriftFileURL.Path | ||
| } | ||
|
|
||
| switch strings.ToLower(t.Encoding) { | ||
| case "thrift": | ||
| opts.ROpts.Encoding = encoding.Thrift | ||
| case "json": | ||
| opts.ROpts.Encoding = encoding.JSON | ||
| case "protobuf": | ||
| opts.ROpts.Encoding = encoding.Protobuf | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using the option -e, --encoding, encoding.Protobuf will match with |
||
| case "raw": | ||
| opts.ROpts.Encoding = encoding.Raw | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line |
||
| overrideParam(&opts.TOpts.CallerName, t.Caller) | ||
| overrideParam(&opts.TOpts.ServiceName, t.Service) | ||
| overrideParam(&opts.ROpts.Procedure, t.Procedure) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -391,3 +391,9 @@ func TestReadYAMLRequestFails(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestReadYAMLSucceeds(t *testing.T) { | ||
| opts := newOptions() | ||
| err := readYAMLFile("testdata/valid.yab", nil, opts) | ||
| assert.NoError(t, err) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add more test please? We should provide the following unit tests:
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should prevent users of using
fileandrequesttogether. Right now, File have priority over request, only one should be available