-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed usage of deprecated pkg/errors
- Loading branch information
1 parent
9b70f62
commit 0f7f3b4
Showing
7 changed files
with
157 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package solr | ||
|
||
import "fmt" | ||
|
||
// M is an alias for map of interface | ||
type M map[string]interface{} | ||
|
||
// wrapErr wraps the error with message | ||
func wrapErr(err error, msg string) error { | ||
if err == nil { | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("%s: %w", msg, err) | ||
} |
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,39 @@ | ||
package solr | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_wrapErr(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
msg string | ||
wrappedErr error | ||
}{ | ||
{ | ||
name: "nil error", | ||
msg: "an error", | ||
}, | ||
{ | ||
name: "non-nil error", | ||
msg: "an error", | ||
wrappedErr: assert.AnError, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := wrapErr(tc.wrappedErr, tc.msg) | ||
if tc.wrappedErr != nil { | ||
assert.ErrorIs(t, err, tc.wrappedErr) | ||
expectStr := fmt.Sprintf("%s: %s", tc.msg, tc.wrappedErr.Error()) | ||
assert.Equal(t, expectStr, err.Error()) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.