-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(kong): upgrade --install and handle error properly (#536)
- Loading branch information
Showing
4 changed files
with
56 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
package retry_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kong/kubernetes-testing-framework/internal/retry" | ||
) | ||
|
||
func TestDoWithErrorHandling(t *testing.T) { | ||
t.Run("succeeded command won't call the errorFunc", func(t *testing.T) { | ||
cmd := retry.Command("echo", "test") | ||
|
||
itShouldntGetCalled := func(err error, _ *bytes.Buffer, _ *bytes.Buffer) error { | ||
t.Error("this function shouldn't be called because there was no error running command") | ||
return err | ||
} | ||
err := cmd.DoWithErrorHandling(context.Background(), itShouldntGetCalled) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("failing command will call the errorFunc", func(t *testing.T) { | ||
cmd := retry.Command("unknown-command") | ||
|
||
wasCalled := false | ||
itShouldBeCalled := func(err error, _ *bytes.Buffer, _ *bytes.Buffer) error { | ||
wasCalled = true | ||
return err | ||
} | ||
|
||
// Wait just a second to not make tests run too long. It's enough to know the errorFunc was called at least once. | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
err := cmd.DoWithErrorHandling(ctx, itShouldBeCalled) | ||
require.Error(t, err) | ||
require.True(t, wasCalled, "expected errorFunc to be called because the command has failed") | ||
}) | ||
} |
This file contains 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 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