-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Switch): Don't duplicate outside steps inside switch matches. (#133)
We use a temporary reactor struct for composition to ensure that each switch branch can be validated. Once that's done we copy all the steps from that reactor into the new switch step's options. Unfortunately we were using the parent reactor, which already contained steps which wound up being duplicated into all switch branches. Closes #132. Thanks @mitel!
- Loading branch information
Showing
5 changed files
with
96 additions
and
10 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 |
---|---|---|
|
@@ -15,3 +15,4 @@ jobs: | |
with: | ||
spark-formatter: true | ||
postgres: false | ||
igniter-upgrade: false |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
defmodule Reactor.Bugs.SwitchPrecedingStepsTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: false | ||
import ExUnit.CaptureLog | ||
|
||
defmodule MooStep do | ||
@moduledoc false | ||
use Reactor.Step | ||
require Logger | ||
|
||
def run(_args, _context, _opts) do | ||
Logger.warning("MOO") | ||
{:ok, :moo} | ||
end | ||
end | ||
|
||
defmodule BooStep do | ||
@moduledoc false | ||
use Reactor.Step | ||
require Logger | ||
|
||
def run(args, _context, _opts) do | ||
Logger.warning("BOO") | ||
{:ok, !args.value} | ||
end | ||
end | ||
|
||
defmodule TruthyStep do | ||
@moduledoc false | ||
use Reactor.Step | ||
require Logger | ||
|
||
def run(_args, _context, _opts) do | ||
Logger.warning("TRUTHY") | ||
{:ok, :truthy} | ||
end | ||
end | ||
|
||
defmodule FalsyStep do | ||
@moduledoc false | ||
use Reactor.Step | ||
require Logger | ||
|
||
def run(_args, _context, _opts) do | ||
Logger.warning("FALSY") | ||
{:ok, :falsy} | ||
end | ||
end | ||
|
||
defmodule BugReactor do | ||
@moduledoc false | ||
use Reactor | ||
|
||
input :value | ||
|
||
step :moo, MooStep | ||
|
||
step :boo, BooStep do | ||
argument :value, input(:value) | ||
end | ||
|
||
switch :is_truthy? do | ||
on result(:boo) | ||
|
||
matches? &(&1 in [nil, false]) do | ||
step :falsy, FalsyStep | ||
end | ||
|
||
default do | ||
step :truthy, TruthyStep | ||
end | ||
end | ||
end | ||
|
||
test "steps preceding a switch only get executed once" do | ||
logs = | ||
[level: :warning, format: "$message\n", colors: [enabled: false]] | ||
|> capture_log(fn -> | ||
Reactor.run(BugReactor, %{value: true}) | ||
end) | ||
|> String.split(~r/\n+/) | ||
|> Enum.reject(&(&1 == "")) | ||
|> Enum.frequencies() | ||
|
||
assert logs["MOO"] == 1 | ||
assert logs["BOO"] == 1 | ||
assert logs["FALSY"] == 1 | ||
end | ||
end |