-
Notifications
You must be signed in to change notification settings - Fork 91
fix(steps): provide functions args in function conditions values #343
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
Open
rclsilver
wants to merge
3
commits into
master
Choose a base branch
from
fix-function-conditions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,34 @@ | ||
name: hello-with-conditions | ||
description: Say hello with conditions | ||
action: | ||
type: echo::hello::world | ||
configuration: | ||
name: '{{.function_args.name}}' | ||
custom_states: | ||
- SAID_HELLO | ||
- NOT_EXPECTED | ||
conditions: | ||
- type: skip | ||
if: | ||
- value: '{{.function_args.skip | default `false`}}' | ||
operator: EQ | ||
expected: 'true' | ||
then: | ||
this: PRUNE | ||
message: 'No hello {{.function_args.name}} !' | ||
- type: check | ||
if: | ||
- value: '{{.function_args.name}}' | ||
operator: NE | ||
expected: '{{.function_args.expected}}' | ||
then: | ||
this: NOT_EXPECTED | ||
message: 'Expected {{.function_args.expected}}, got {{.function_args.name}}' | ||
- type: check | ||
if: | ||
- value: '{{.function_args.name}}' | ||
operator: EQ | ||
expected: '{{.function_args.expected}}' | ||
then: | ||
this: SAID_HELLO | ||
message: 'Said hello to {{.function_args.name}}' |
This file contains hidden or 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 hidden or 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,29 @@ | ||
name: functionConditions | ||
description: Test function conditions | ||
title_format: "[test] Test function conditions" | ||
auto_runnable: true | ||
steps: | ||
asExpected: | ||
description: Say hello to foobar | ||
action: | ||
type: hello-with-conditions | ||
configuration: | ||
name: foobar | ||
expected: foobar | ||
|
||
notExpected: | ||
description: Say hello to foo but expect bar | ||
action: | ||
type: hello-with-conditions | ||
configuration: | ||
name: foo | ||
expected: bar | ||
|
||
skipped: | ||
description: Say hello to foo but expect bar | ||
rclsilver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
action: | ||
type: hello-with-conditions | ||
configuration: | ||
name: foo | ||
expected: foor | ||
skip: true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here, we previously used
values.Clone
to prevent alter on thevalues
object of the caller.But, in this function, we have a second parameter, which is
ss
forStateSetter
: https://github.com/ovh/utask/blob/master/engine/step/step.go#L521Called from here: https://github.com/ovh/utask/blob/master/engine/engine.go#L431
definition of this function is here: https://github.com/ovh/utask/blob/master/engine/engine.go#L1064-L1071
Everytime a condition is matching, we need to alter the
state
of some steps, usingss
(such as here https://github.com/ovh/utask/blob/master/engine/step/step.go#L551 )And the call of the closure in
resolutionStateSetter
is using the parentvalues
object to alter the current state.So when the second condition is evaluated, and require that the first condition altered the state to match, we are using the cloned value, which has not been altered by the closure in
resolutionStateSetter
, which mean that the condition state will not match, making the test failing.I guess not cloning the values is fine, but the drawback of function_args not working in conditions if they are nested seems a huge drawback that we should address before merging this one