-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon_test.go
More file actions
47 lines (41 loc) · 1.34 KB
/
common_test.go
File metadata and controls
47 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package frame //nolint:testpackage // tests access package internals
import (
"database/sql"
"errors"
"fmt"
"testing"
"connectrpc.com/connect"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)
type ErrorSuite struct {
suite.Suite
}
func TestErrorSuite(t *testing.T) {
suite.Run(t, new(ErrorSuite))
}
func (s *ErrorSuite) TestErrorIsNotFoundTable() {
testCases := []struct {
name string
err error
want bool
}{
{name: "nil", err: nil, want: false},
{name: "sql no rows", err: sql.ErrNoRows, want: true},
{name: "gorm record not found", err: gorm.ErrRecordNotFound, want: true},
{name: "grpc not found", err: status.Error(codes.NotFound, "missing"), want: true},
{name: "grpc internal", err: status.Error(codes.Internal, "failed"), want: false},
{name: "connect not found", err: connect.NewError(connect.CodeNotFound, errors.New("missing")), want: true},
{name: "text not found", err: errors.New("resource not found"), want: true},
{name: "text compact notfound", err: errors.New("resource_notfound"), want: true},
{name: "text 404", err: fmt.Errorf("status=%d", 404), want: true},
{name: "other error", err: errors.New("boom"), want: false},
}
for _, tc := range testCases {
s.Run(tc.name, func() {
s.Equal(tc.want, ErrorIsNotFound(tc.err))
})
}
}