Skip to content

Commit f316d5d

Browse files
authored
Merge pull request #119 from suborbital/connor/runnable-request-input
Use CoordinatedRequest body as Runnable input
2 parents 503859d + 6f87b95 commit f316d5d

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

rwasm/wasmrunnable.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package rwasm
22

33
import (
44
"encoding/json"
5-
"fmt"
65

76
"github.com/suborbital/reactr/request"
87
"github.com/suborbital/reactr/rt"
@@ -51,11 +50,10 @@ func (w *Runner) Run(job rt.Job, ctx *rt.Ctx) (interface{}, error) {
5150
jobBytes = bytes
5251
} else {
5352
// if the job is a request, add it to the Ctx and
54-
// set the job input to be a summary of the request
53+
// set the job input to be the body of the request
5554
ctx.UseRequest(req)
5655

57-
input := fmt.Sprintf("%s %s %s", req.Method, req.URL, req.ID)
58-
jobBytes = []byte(input)
56+
jobBytes = req.Body
5957
}
6058

6159
var output []byte
@@ -118,7 +116,7 @@ func (w *Runner) Run(job rt.Job, ctx *rt.Ctx) (interface{}, error) {
118116
return output, nil
119117
}
120118

121-
// OnChange evt ChangeEventruns when a worker starts using this Runnable
119+
// OnChange runs when a worker starts using this Runnable
122120
func (w *Runner) OnChange(evt rt.ChangeEvent) error {
123121
if evt == rt.ChangeTypeStart {
124122
if err := w.env.addInstance(); err != nil {

rwasm/wasmtest/rust_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,43 @@ func TestWasmRunnerWithRequest(t *testing.T) {
124124
}
125125
}
126126

127+
func TestEmptyRequestBody(t *testing.T) {
128+
r := rt.New()
129+
130+
// using a Rust module
131+
doWasm := r.Register("wasm", rwasm.NewRunner("../testdata/log/log.wasm"))
132+
133+
req := &request.CoordinatedRequest{
134+
Method: "GET",
135+
URL: "/hello/world",
136+
ID: uuid.New().String(),
137+
Body: []byte{},
138+
State: map[string][]byte{
139+
"hello": []byte("what is up"),
140+
},
141+
}
142+
143+
reqJSON, err := req.ToJSON()
144+
if err != nil {
145+
t.Error("failed to ToJSON", err)
146+
}
147+
148+
res, err := doWasm(reqJSON).Then()
149+
if err != nil {
150+
t.Error(errors.Wrap(err, "failed to Then"))
151+
return
152+
}
153+
154+
resp := &request.CoordinatedResponse{}
155+
if err := json.Unmarshal(res.([]byte), resp); err != nil {
156+
t.Error("failed to Unmarshal response")
157+
}
158+
159+
if string(resp.Output) != "hello what is up" {
160+
t.Error(fmt.Errorf("expected 'hello, what is up', got %s", string(res.([]byte))))
161+
}
162+
}
163+
127164
func TestContentType(t *testing.T) {
128165
body := testBody{
129166
Username: "cohix",

0 commit comments

Comments
 (0)