HEAVY: finish music service migration, tidy up services, more tests
This commit is contained in:
parent
9e311df462
commit
90a671982c
47 changed files with 2698 additions and 902 deletions
16
errors/notexist.go
Normal file
16
errors/notexist.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package errors
|
||||
|
||||
type NotExistError struct {
|
||||
query string
|
||||
}
|
||||
func NewNotExistError(query string) *NotExistError {
|
||||
return &NotExistError{ query: query }
|
||||
}
|
||||
func (err *NotExistError) Error() string {
|
||||
return err.query
|
||||
}
|
||||
func IsNotExistError(err error) bool {
|
||||
_, ok := err.(*NotExistError)
|
||||
return ok
|
||||
}
|
||||
|
||||
26
errors/notexist_test.go
Normal file
26
errors/notexist_test.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package errors_test
|
||||
|
||||
import (
|
||||
"arimelody-web/errors"
|
||||
goErrors "errors"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func Test_NotExistError(t *testing.T) {
|
||||
var err error
|
||||
message := "entity does not exist"
|
||||
|
||||
t.Run("can create error", func(t *testing.T) {
|
||||
err = errors.NewNotExistError(message)
|
||||
assert.Error(t, err, message)
|
||||
})
|
||||
|
||||
t.Run("validator returns true for valid error", func(t *testing.T) {
|
||||
assert.Equal(t, errors.IsNotExistError(err), true)
|
||||
})
|
||||
t.Run("validator returns false for invalid error", func(t *testing.T) {
|
||||
assert.Equal(t, errors.IsNotExistError(goErrors.New("other error")), false)
|
||||
})
|
||||
}
|
||||
15
errors/validation.go
Normal file
15
errors/validation.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package errors
|
||||
|
||||
type ValidationError struct {
|
||||
message string
|
||||
}
|
||||
func NewValidationError(message string) *ValidationError {
|
||||
return &ValidationError{ message: message }
|
||||
}
|
||||
func (err *ValidationError) Error() string {
|
||||
return err.message
|
||||
}
|
||||
func IsValidationError(err error) bool {
|
||||
_, ok := err.(*ValidationError)
|
||||
return ok
|
||||
}
|
||||
26
errors/validation_test.go
Normal file
26
errors/validation_test.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package errors_test
|
||||
|
||||
import (
|
||||
"arimelody-web/errors"
|
||||
goErrors "errors"
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
)
|
||||
|
||||
func Test_ValidationError(t *testing.T) {
|
||||
var err error
|
||||
message := "invalid input"
|
||||
|
||||
t.Run("can create error", func(t *testing.T) {
|
||||
err = errors.NewValidationError(message)
|
||||
assert.Error(t, err, message)
|
||||
})
|
||||
|
||||
t.Run("validator returns true for valid error", func(t *testing.T) {
|
||||
assert.Equal(t, errors.IsValidationError(err), true)
|
||||
})
|
||||
t.Run("validator returns false for invalid error", func(t *testing.T) {
|
||||
assert.Equal(t, errors.IsValidationError(goErrors.New("other error")), false)
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue