Add unit tests for stoneerror package
All checks were successful
Go CI/CD / go-ci (pull_request) Successful in 10m37s
Go CI/CD / go-ci (push) Successful in 10m38s

Introduce comprehensive tests for core functionalities including error creation, metadata handling, wrapping, JSON conversion, and type validation. These tests ensure robustness and reliability of the stoneerror package.
This commit is contained in:
Rene Nochebuena 2025-04-12 17:42:47 -06:00
parent b42137701b
commit 24ea252c96
Signed by: Rene Nochebuena
GPG Key ID: A9FD83117EA538D8

53
error_test.go Normal file
View File

@ -0,0 +1,53 @@
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_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()
}
}