mirror of
https://github.com/smallstep/certificates.git
synced 2024-11-11 07:11:00 +00:00
296ac4e207
This commit allows to use the standard error sql.ErrNoRows for not found errors.
33 lines
758 B
Go
33 lines
758 B
Go
package acme
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsErrNotFound(t *testing.T) {
|
|
type args struct {
|
|
err error
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want bool
|
|
}{
|
|
{"true ErrNotFound", args{ErrNotFound}, true},
|
|
{"true sql.ErrNoRows", args{sql.ErrNoRows}, true},
|
|
{"true wrapped ErrNotFound", args{fmt.Errorf("something failed: %w", ErrNotFound)}, true},
|
|
{"true wrapped sql.ErrNoRows", args{fmt.Errorf("something failed: %w", sql.ErrNoRows)}, true},
|
|
{"false other", args{errors.New("not found")}, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := IsErrNotFound(tt.args.err); got != tt.want {
|
|
t.Errorf("IsErrNotFound() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|