All checks were successful
Go CI/CD / go-ci (push) Successful in 10m5s
Reviewed-on: #2 Reviewed-by: Cloud Administrator <cloud-admin@noreply.gitstormr.dev> Co-authored-by: Rene Nochebuena <code-raider@noreply.gitstormr.dev> Co-committed-by: Rene Nochebuena <code-raider@noreply.gitstormr.dev>
80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
package stoneerror
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func Test_StoneErrorWithoutMetadata(t *testing.T) {
|
|
stoneError := New(1, "test")
|
|
|
|
t.Log(stoneError)
|
|
}
|
|
|
|
func Test_StoneErrorWithMetadata(t *testing.T) {
|
|
stoneError := New(1, "test").
|
|
WithMetadata("key", "value").
|
|
WithMetadata("key2", "value2")
|
|
|
|
t.Log(stoneError)
|
|
}
|
|
|
|
func Test_NormalWrap(t *testing.T) {
|
|
normalError := errors.New("test")
|
|
stoneError := Wrap(normalError, 1, "test")
|
|
t.Log(stoneError)
|
|
}
|
|
|
|
func Test_StoneWrap(t *testing.T) {
|
|
originalError := New(1, "test").
|
|
WithMetadata("key", "value").
|
|
WithMetadata("key2", "value2")
|
|
stoneError := Wrap(originalError, 1, "test")
|
|
t.Log(stoneError)
|
|
}
|
|
|
|
func Test_NormalUnwrap(t *testing.T) {
|
|
normalError := errors.New("test")
|
|
stoneError := Wrap(normalError, 1, "test")
|
|
|
|
unwrap := stoneError.Unwrap()
|
|
|
|
if IsStoneError(unwrap) {
|
|
t.Fail()
|
|
} else {
|
|
t.Log(stoneError)
|
|
}
|
|
}
|
|
|
|
func Test_StoneUnwrap(t *testing.T) {
|
|
normalError := New(1, "test")
|
|
stoneError := Wrap(normalError, 1, "test")
|
|
|
|
unwrap := stoneError.Unwrap()
|
|
|
|
if !IsStoneError(unwrap) {
|
|
t.Fail()
|
|
} else {
|
|
t.Log(stoneError)
|
|
}
|
|
}
|
|
|
|
func Test_ToJSON(t *testing.T) {
|
|
stoneError := New(1, "test").
|
|
WithMetadata("key", "value").
|
|
WithMetadata("key2", "value2")
|
|
jsonData := stoneError.ToJSON()
|
|
t.Log(string(jsonData))
|
|
}
|
|
|
|
func Test_IsStoneError(t *testing.T) {
|
|
stoneError := New(1, "test").
|
|
WithMetadata("key", "value")
|
|
|
|
if IsStoneError(stoneError) {
|
|
t.Log("Is stone error")
|
|
} else {
|
|
t.Fail()
|
|
}
|
|
}
|