From 01fff61e04ae21c0e693b15883d5ea9593f43f03 Mon Sep 17 00:00:00 2001 From: Prabhjot Singh Sethi Date: Thu, 17 Apr 2025 21:42:28 +0000 Subject: [PATCH] Add test scenarios for errors package Signed-off-by: Prabhjot Singh Sethi --- errors/errors_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 errors/errors_test.go diff --git a/errors/errors_test.go b/errors/errors_test.go new file mode 100644 index 0000000..5c003d7 --- /dev/null +++ b/errors/errors_test.go @@ -0,0 +1,31 @@ +// Copyright © 2025 Prabhjot Singh Sethi, All Rights reserved +// Author: Prabhjot Singh Sethi + +package errors + +import ( + "fmt" + "testing" +) + +func Test_ErrorValidations(t *testing.T) { + err := fmt.Errorf("%s", "test error from fmt") + if GetErrCode(err) != Unknown { + t.Errorf("expected error type unknown, got %v", GetErrCode(err)) + } + + err = New("test error from errors pkg") + if GetErrCode(err) != Unknown { + t.Errorf("expected error type unknown, got %v", GetErrCode(err)) + } + + err = Wrap(AlreadyExists, "test wrap error from errors pkg") + if !IsAlreadyExists(err) { + t.Errorf("expected error type Already exists") + } + + err = Wrapf(NotFound, "%s", "test wrapf error from errors pkg") + if !IsNotFound(err) { + t.Errorf("expected error type Not Found") + } +}