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

Catching invalid step functions #61

Merged
merged 3 commits into from
Feb 3, 2020
Merged

Catching invalid step functions #61

merged 3 commits into from
Feb 3, 2020

Conversation

bkielbasa
Copy link
Collaborator

Fixes #48
FYI @sagikazarmark

t tester
steps []stepDef
options SuiteOptions
stepsErrors []error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Steps could be validated in Run as well. What's the reason for caching errors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make the Run function as small as possible. There's no another way of adding steps than using AddStep*.

The second reason why I did it is that (maybe in the future) we'll want to add more checks before calling the Run. Then, the only thing we'll need to do is to rename it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm...I still think it might better be to run checks in the beginning of Run. Eg. validateSteps(). It would keep both Run and AddStep* clean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not so simple. When working with regex's, we have to compile them. If we do it in AddStep then we have to or use MustCompile (which throws a panic) or regular Compile but we have to store the error somewhere. It means, there have to be some if err != nil in the function.

Or... store strings (not compiled) and try to compile them in the validateSteps() function. But IMO it would complicate things even more.

By doing it this way, we're at least consistent with the behaviour.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay, I see. Well, it's an internal detail, so it should be fine.

gobdd.go Outdated
@@ -91,8 +92,17 @@ type stepDef struct {
f interface{}
}

type tester interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type should be exported, since it's used in an exported function. I would probably keep calling it T or TestingT (as seen in testify).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! changed 👍

@bkielbasa bkielbasa added this to the 1.0 milestone Feb 3, 2020
@bkielbasa bkielbasa merged commit f847eef into master Feb 3, 2020
@bkielbasa bkielbasa deleted the issue-48 branch February 3, 2020 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catching invalid step functions
2 participants