From 24ea252c96d28b5d43fbb34adde6c113896b167b Mon Sep 17 00:00:00 2001 From: Rene Nochebuena Date: Sat, 12 Apr 2025 17:42:47 -0600 Subject: [PATCH] Add unit tests for stoneerror package 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. --- error_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 error_test.go diff --git a/error_test.go b/error_test.go new file mode 100644 index 0000000..755e386 --- /dev/null +++ b/error_test.go @@ -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() + } +}