You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package ratchet
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func AssertErrorString(t *testing.T, got, want string) {
|
|
t.Helper()
|
|
if got != want {
|
|
t.Errorf("Incorrect error code/message got %q want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestErrorCode(t *testing.T) {
|
|
|
|
t.Run("should return empty", func(t *testing.T) {
|
|
got := ErrorCode(nil)
|
|
|
|
AssertErrorString(t, got, "")
|
|
})
|
|
|
|
t.Run("should return internal error", func(t *testing.T) {
|
|
want := EINTERNAL
|
|
got := ErrorCode(errors.New("Mock disk error"))
|
|
|
|
AssertErrorString(t, got, want)
|
|
})
|
|
|
|
t.Run("should return my code", func(t *testing.T) {
|
|
e := &Error{Code: "my_code", Message: "my_message"}
|
|
got := ErrorCode(e)
|
|
|
|
AssertErrorString(t, got, e.Code)
|
|
})
|
|
}
|
|
|
|
func TestErrorMessage(t *testing.T) {
|
|
t.Run("empty error should return empty string", func(t *testing.T) {
|
|
got := ErrorMessage(nil)
|
|
|
|
AssertErrorString(t, got, "")
|
|
})
|
|
|
|
t.Run("should return internal error message", func(t *testing.T) {
|
|
got := ErrorMessage(errors.New("Mock disk error"))
|
|
|
|
AssertErrorString(t, got, INTERNAL_ERROR_MESSAGE)
|
|
})
|
|
|
|
t.Run("should return application error message", func(t *testing.T) {
|
|
e := &Error{Message: "my_message"}
|
|
got := ErrorMessage(e)
|
|
|
|
AssertErrorString(t, got, e.Message)
|
|
})
|
|
}
|