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

fix: remove most uses of log.Fatal when running programatically #99

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

anuraaga
Copy link
Contributor

go-ftw provides a programmatic entry point for tests like this one

https://github.com/corazawaf/coraza/blob/v3/dev/testing/coreruleset/coreruleset_test.go#L213

There are some quirks like global config (will look at in another PR) and the code causing the process to exit because of use of log.Fatal, making test failures difficult to understand. This replaces log.Fatal with propagating errors. There is one remaining Fatal for a regexp which will require some less mechanical change but that also should have lower chance of triggering

@anuraaga anuraaga changed the title fix: remove most uses of log.Fatal when running fix: remove most uses of log.Fatal when running programatically Oct 31, 2022
assert.LessOrEqual(t, 0, res.Stats.TotalFailed(), "Oops, test run failed!")
}

func TestDisabledRun(t *testing.T) {
t.Cleanup(config.Reset)

err := config.NewConfigFromString(yamlConfig)
err := config.NewConfigFromString(yamlCloudConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you have to change the config here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking forgot to mention it previously the presence of a log file was checked lazily so if we the test didn't run, like this one checking behavior of disabled tests, it was ok without a log file set. Now that validation is eager, which should generally be good. It seemed simplest to use cloud mode here which doesn't need a log file instead of setting up an unused file

Copy link
Collaborator

@theseion theseion left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks!

@theseion theseion merged commit f29629b into coreruleset:develop Nov 2, 2022
@fzipi fzipi mentioned this pull request Nov 2, 2022
fzipi pushed a commit that referenced this pull request Nov 2, 2022
Propagate errors instead of exiting immediately
@fzipi fzipi mentioned this pull request Nov 17, 2022
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.

3 participants