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

feat(exitcode): Add exit code sugar method #2342

Merged
merged 7 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions wait/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (ws *ExecStrategy) WithStartupTimeout(startupTimeout time.Duration) *ExecSt
return ws
}

func (ws *ExecStrategy) WithExitCode(exitCode int) *ExecStrategy {

mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
return ws.WithExitCodeMatcher(func(actualCode int) bool {
return actualCode == exitCode
})
}

func (ws *ExecStrategy) WithExitCodeMatcher(exitCodeMatcher func(exitCode int) bool) *ExecStrategy {
ws.ExitCodeMatcher = exitCodeMatcher
return ws
Expand Down
21 changes: 21 additions & 0 deletions wait/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ func TestExecStrategyWaitUntilReady_CustomExitCode(t *testing.T) {
}
}

func TestExecStrategyWaitUntilReadyWithSugaryExitCode(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a blocker, but more consistent name with other test functions

Suggested change
func TestExecStrategyWaitUntilReadyWithSugaryExitCode(t *testing.T) {
func TestExecStrategyWaitUntilReady_ExitCode(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mdelapenya Updated.

target := mockExecTarget{
exitCode: 10,
}
wg := wait.NewExecStrategy([]string{"true"}).WithExitCode(10)
// Default is 60. Let's shorten that
wg.WithStartupTimeout(time.Second*2)
err := wg.WaitUntilReady(context.Background(), target)
if err != nil {
t.Fatal(err)
}

//Ensure we aren't spuriously returning on any code
wg = wait.NewExecStrategy([]string{"true"}).WithExitCode(0)
wg.WithStartupTimeout(time.Second*2)
err = wg.WaitUntilReady(context.Background(), target)
if err == nil {
t.Fatalf("Expected strategy to timeout out")
}
}

func TestExecStrategyWaitUntilReady_CustomResponseMatcher(t *testing.T) {
// waitForExecExitCodeResponse {
dockerReq := testcontainers.ContainerRequest{
Expand Down