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

ResultPath=$ replaces complete output #199

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/floe/workflow/reference_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ def get(context)
def set(context, value)
result = context.dup

# If the payload is '$' then merge the value into the context
# otherwise store the value under the path
#
# TODO: how to handle non-hash values, raise error if path=$ and value not a hash?
# If the payload is '$' then replace the output with the value
if path.empty?
result.merge!(value)
result = value.dup
else
child = result
keys = path.dup
Expand Down
12 changes: 10 additions & 2 deletions spec/workflow/reference_path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,27 @@

describe "#set" do
let(:payload) { "$" }
let(:input) { {} }
let(:input) { {"old" => "key"} }

context "with a simple path" do
it "sets the output at the top-level" do
expect(subject.set(input, "foo" => "bar")).to eq("foo" => "bar")
end
end

context "with a top level path" do
let(:payload) { "$.hash" }

it "sets the output at the correct nested level" do
expect(subject.set(input, "foo" => "bar")).to eq("old" => "key", "hash" => {"foo" => "bar"})
end
end

context "with a nested path" do
let(:payload) { "$.nested.hash" }

it "sets the output at the correct nested level" do
expect(subject.set(input, "foo" => "bar")).to eq("nested" => {"hash" => {"foo" => "bar"}})
expect(subject.set(input, "foo" => "bar")).to eq("old" => "key", "nested" => {"hash" => {"foo" => "bar"}})
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/workflow/states/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

workflow.current_state.run_nonblock!

expect(ctx.output).to eq("foo" => {"bar" => "baz"}, "bar" => {"baz" => "foo"}, "response" => ["192.168.1.2"])
expect(ctx.output).to eq("response" => ["192.168.1.2"])
end

context "with an error" do
Expand Down Expand Up @@ -80,7 +80,7 @@

workflow.current_state.run_nonblock!

expect(ctx.output).to eq("foo" => {"bar" => "baz"}, "bar" => {"baz" => "foo"}, "ip_addrs" => ["192.168.1.2"])
expect(ctx.output).to eq("ip_addrs" => ["192.168.1.2"])
end
end

Expand Down