-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent/exec: rewrite IsTemporary() to use errors.As()
This makes sure we detect temporary errors both with pkg/errors.Wrap() and with native Go error wrapping. Signed-off-by: Sebastiaan van Stijn <[email protected]>
- Loading branch information
Showing
2 changed files
with
30 additions
and
9 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,27 @@ | ||
package exec | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestIsTemporary(t *testing.T) { | ||
err := fmt.Errorf("err") | ||
err1 := MakeTemporary(fmt.Errorf("err1: %w", err)) | ||
err2 := fmt.Errorf("err2: %w", err1) | ||
err3 := errors.Wrap(err2, "err3") | ||
err4 := fmt.Errorf("err4: %w", err3) | ||
err5 := errors.Wrap(err4, "err5") | ||
|
||
if IsTemporary(nil) { | ||
t.Error("expected error to not be a temporary error") | ||
} | ||
if IsTemporary(err) { | ||
t.Error("expected error to not be a temporary error") | ||
} | ||
if !IsTemporary(err5) { | ||
t.Error("expected error to be a temporary error") | ||
} | ||
} |