-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from rusq/defork
Use slack library directly, remove replace
- Loading branch information
Showing
25 changed files
with
811 additions
and
346 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,21 @@ | ||
package auth | ||
|
||
import "fmt" | ||
|
||
// Error is the error returned by New, the underlying Err contains | ||
// an API error returned by slack.AuthTest call. | ||
type Error struct { | ||
Err error | ||
} | ||
|
||
func (ae *Error) Error() string { | ||
return fmt.Sprintf("failed to authenticate: %s", ae.Err) | ||
} | ||
|
||
func (ae *Error) Unwrap() error { | ||
return ae.Err | ||
} | ||
|
||
func (ae *Error) Is(target error) bool { | ||
return target == ae.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,79 @@ | ||
package auth | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
var errSample = errors.New("test error") | ||
|
||
func TestAuthError_Unwrap(t *testing.T) { | ||
type fields struct { | ||
Err error | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr error | ||
}{ | ||
{ | ||
"unwrap unwraps properly", | ||
fields{Err: errSample}, | ||
errSample, | ||
}, | ||
{ | ||
"multilevel wrap", | ||
fields{Err: fmt.Errorf("blah: %w", errSample)}, | ||
errSample, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ae := &Error{ | ||
Err: tt.fields.Err, | ||
} | ||
if err := ae.Unwrap(); (err != nil) && !errors.Is(err, tt.wantErr) { | ||
t.Errorf("AuthError.Unwrap() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthError_Is(t *testing.T) { | ||
type fields struct { | ||
Err error | ||
} | ||
type args struct { | ||
target error | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
"is correctly compares underlying error", | ||
fields{Err: errSample}, | ||
args{errSample}, | ||
true, | ||
}, | ||
{ | ||
"not matching error returns false", | ||
fields{Err: errors.New("not me bro")}, | ||
args{errSample}, | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
ae := &Error{ | ||
Err: tt.fields.Err, | ||
} | ||
if got := ae.Is(tt.args.target); got != tt.want { | ||
t.Errorf("AuthError.Is() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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.