Skip to content

Commit ac90cda

Browse files
authored
add unwrap test scenario to NonRetriable (Azure#21866)
1 parent 060dee4 commit ac90cda

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

sdk/internal/errorinfo/errorinfo_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,31 @@
77
package errorinfo
88

99
import (
10-
"errors"
1110
"testing"
11+
12+
"github.com/stretchr/testify/require"
1213
)
1314

15+
type fakeError struct {
16+
Message string
17+
}
18+
19+
func (fe *fakeError) Error() string {
20+
return fe.Message
21+
}
22+
1423
func TestNonRetriableError(t *testing.T) {
1524
const dnr string = "Do Not Retry"
1625

1726
// Create sample error.
18-
err := NonRetriableError(errors.New(dnr))
19-
27+
err := NonRetriableError(&fakeError{Message: dnr})
2028
// Check error message is correct
21-
if err.Error() != dnr {
22-
t.Fatalf("Expected error message to be '%q' but got '%q'.", dnr, err.Error())
23-
}
29+
require.Error(t, err, dnr)
2430

2531
var e NonRetriable
26-
if !errors.As(err, &e) {
27-
t.Fatalf("Expected error to be of type NonRetriable")
28-
}
32+
require.ErrorAs(t, err, &e)
33+
34+
// Check Unwrap method on NonRetriable error type
35+
var fe *fakeError
36+
require.ErrorAs(t, err, &fe)
2937
}

0 commit comments

Comments
 (0)