Repository navigation
feat(container): add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155 - #175
Open
kw-00 wants to merge 5 commits into
Open
feat(container): add WithStrictStartupCommand and WithStrictAfterReadyCommand - fixing issue #155#175kw-00 wants to merge 5 commits into
kw-00 wants to merge 5 commits into
Conversation
These two functions are variants to WithStartupCommand and WithAfterReadyCommand, respectively. As opposed to the latter, they treat non-zero exit codes from executable commands as errors. The variants are implemented just like the original functions, except that they use createStrictExecutableHooks instead of createExecutableHooks. createStrictExecutableHooks is a variant of createExecutableHooks which treats non-zero exit codes as errors and has also been implemented as part of this commit.
…dyCommand For both features, the tests include the following: - command execution and io tests analogical to those found in WithStartupCommand and WithStrictAfterReadyCommand, respectively - test that expects an error when executable command finishes with a non-zero exit code - this is the new functionality that WithStrict... functions add
…mmand These tests merely check whether no error occurs when WithStrictStartupCommand and WithStrictAfterReadyCommand are used to register hooks and also whether the hooks actually gets registered. I am adding them because tests using the same logic already exist for the original WithStartupCommand and WithAfterReadyCommand, so it might be expected that the variants added in this PR are also tested for this. These tests do not test any new functionality. The new functionality of treating non-zero exit codes as errors is a feature used when running containers, and I have already added tests for this in container/container.run_test.go.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
I added a variant of WithStartupCommand called "WithStrictStartupCommand" as well as a variant of WithAfterReadyCommand called "WithStrictAfterReadyCommand".
These variants preserve the behaviour of the original functions, except that they treat non-zero exit codes in executable commands as errors. Those errors are eventually returned via container.Run().
I decided to do this by introducing a variant of the helper function named createExecutableHooks(). The variant, named createStrictExecutableHooks, is then used in the With... functions.
I also added tests for this new functionality.
The change was inspired by issue #155 . I decided to create new functions instead of modifying the original WithStartupCommand and WithAfterReadyCommand for the following reasons:
Why is it important?
The core problem is explained in issue #155 . When an executable command is hooked using WithStartupCommand or WithAfterReadyCommand, its exit status is ignored.
This causes a container to start "successfully", even though its startup/after-ready commands may have failed.
Related issues
Closes #155
How to test this PR
Tests for the new functionality have been added to container/container.run_test.go. No current functionality depends on these changes.
Follow-ups
It would be possible to deduplicate test code in container/container.run_test.go and also deduplicate logic in the With... functions used for registering hooks, though this could sacrifice straightforwardness.