Skip to content

Commit

Permalink
Add test case for internal/errors/mysql.go (#918)
Browse files Browse the repository at this point in the history
* feat: add test case and comment

Signed-off-by: hlts2 <[email protected]>

* fix: add godoc comment

Signed-off-by: hlts2 <[email protected]>

* Apply suggestions from code review

* fix: goleak bug

Signed-off-by: hlts2 <[email protected]>

* fix: fails test

Signed-off-by: hlts2 <[email protected]>

* Update internal/errors/mysql_test.go

* Apply suggestions from code review

Co-authored-by: Kiichiro YUKAWA <[email protected]>

Co-authored-by: Kiichiro YUKAWA <[email protected]>
  • Loading branch information
hlts2 and vankichi authored Jan 25, 2021
1 parent 153f8d0 commit 5df9ec1
Show file tree
Hide file tree
Showing 2 changed files with 534 additions and 181 deletions.
16 changes: 15 additions & 1 deletion internal/errors/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,63 +18,77 @@
package errors

var (
// MySQL.
// ErrMySQLConnectionPingFailed represents an error that the ping failed.
ErrMySQLConnectionPingFailed = New("error MySQL connection ping failed")

// NewErrMySQLNotFoundIdentity represents a function to generate an error that the element is not found.
NewErrMySQLNotFoundIdentity = func() error {
return &ErrMySQLNotFoundIdentity{
err: New("error mysql element not found"),
}
}

// ErrMySQLConnectionClosed represents a function to generate an error that the connection closed.
ErrMySQLConnectionClosed = New("error MySQL connection closed")

// ErrMySQLTransactionNotCreated represents an error that the transaction is not closed.
ErrMySQLTransactionNotCreated = New("error MySQL transaction not created")

// ErrRequiredElementNotFoundByUUID represents a function to generate an error that the required element is not found.
ErrRequiredElementNotFoundByUUID = func(uuid string) error {
return Wrapf(NewErrMySQLNotFoundIdentity(), "error required element not found, uuid: %s", uuid)
}

// NewErrMySQLInvalidArgumentIdentity represents a function to generate an error that the argument is invalid.
NewErrMySQLInvalidArgumentIdentity = func() error {
return &ErrMySQLInvalidArgumentIdentity{
err: New("error mysql invalid argument"),
}
}

// ErrRequiredMemberNotFilled represents a function to generate an error that the required member is not filled.
ErrRequiredMemberNotFilled = func(member string) error {
return Wrapf(NewErrMySQLInvalidArgumentIdentity(), "error required member not filled (member: %s)", member)
}
)

// ErrMySQLNotFoundIdentity represents a custom error type that the element is not found.
type ErrMySQLNotFoundIdentity struct {
err error
}

// Error returns the string of internal error.
func (e *ErrMySQLNotFoundIdentity) Error() string {
return e.err.Error()
}

// Unwrap returns the internal error.
func (e *ErrMySQLNotFoundIdentity) Unwrap() error {
return e.err
}

// IsErrMySQLNotFound returns true when the err type is ErrMySQLNotFoundIdentity.
func IsErrMySQLNotFound(err error) bool {
target := new(ErrMySQLNotFoundIdentity)
return As(err, &target)
}

// ErrMySQLInvalidArgumentIdentity represents a custom error type that the argument is not found.
type ErrMySQLInvalidArgumentIdentity struct {
err error
}

// Error returns the string of internal error.
func (e *ErrMySQLInvalidArgumentIdentity) Error() string {
return e.err.Error()
}

// Unwrap returns the internal error.
func (e *ErrMySQLInvalidArgumentIdentity) Unwrap() error {
return e.err
}

// IsErrMySQLInvalidArgument returns true when the err type is ErrMySQLInvalidArgumentIdentity.
func IsErrMySQLInvalidArgument(err error) bool {
target := new(ErrMySQLInvalidArgumentIdentity)
return As(err, &target)
Expand Down
Loading

0 comments on commit 5df9ec1

Please sign in to comment.