@@ -2,6 +2,7 @@ package push
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67)
78
@@ -313,3 +314,85 @@ func (h *UnitTestHandler) Reset() {
313314 h .lastNotification = nil
314315 h .errorToReturn = nil
315316}
317+
318+ // TestErrorWrapping tests that error checking functions work with wrapped errors
319+ func TestErrorWrapping (t * testing.T ) {
320+ t .Run ("IsHandlerExistsError with wrapped error" , func (t * testing.T ) {
321+ // Create a HandlerError
322+ handlerErr := ErrHandlerExists ("test-notification" )
323+
324+ // Wrap it
325+ wrappedErr := fmt .Errorf ("operation failed: %w" , handlerErr )
326+ doubleWrappedErr := fmt .Errorf ("context: %w" , wrappedErr )
327+
328+ // Should still be detected through wrapping
329+ if ! IsHandlerExistsError (doubleWrappedErr ) {
330+ t .Errorf ("IsHandlerExistsError should detect wrapped error" )
331+ }
332+
333+ // Verify it doesn't match other error types
334+ if IsProtectedHandlerError (doubleWrappedErr ) {
335+ t .Errorf ("IsProtectedHandlerError should not match handler exists error" )
336+ }
337+ })
338+
339+ t .Run ("IsProtectedHandlerError with wrapped error" , func (t * testing.T ) {
340+ // Create a protected handler error
341+ protectedErr := ErrProtectedHandler ("protected-notification" )
342+
343+ // Wrap it
344+ wrappedErr := fmt .Errorf ("unregister failed: %w" , protectedErr )
345+
346+ // Should still be detected through wrapping
347+ if ! IsProtectedHandlerError (wrappedErr ) {
348+ t .Errorf ("IsProtectedHandlerError should detect wrapped error" )
349+ }
350+
351+ // Verify it doesn't match other error types
352+ if IsHandlerExistsError (wrappedErr ) {
353+ t .Errorf ("IsHandlerExistsError should not match protected handler error" )
354+ }
355+ })
356+
357+ t .Run ("IsVoidProcessorError with wrapped error" , func (t * testing.T ) {
358+ // Create a void processor error
359+ voidErr := ErrVoidProcessorRegister ("test-notification" )
360+
361+ // Wrap it multiple times
362+ wrappedErr := fmt .Errorf ("register failed: %w" , voidErr )
363+ doubleWrappedErr := fmt .Errorf ("processor error: %w" , wrappedErr )
364+
365+ // Should still be detected through wrapping
366+ if ! IsVoidProcessorError (doubleWrappedErr ) {
367+ t .Errorf ("IsVoidProcessorError should detect wrapped error" )
368+ }
369+ })
370+
371+ t .Run ("IsHandlerNilError with wrapped error" , func (t * testing.T ) {
372+ // Wrap the nil handler error
373+ wrappedErr := fmt .Errorf ("validation failed: %w" , ErrHandlerNil )
374+
375+ // Should still be detected through wrapping
376+ if ! IsHandlerNilError (wrappedErr ) {
377+ t .Errorf ("IsHandlerNilError should detect wrapped error" )
378+ }
379+ })
380+
381+ t .Run ("Error functions return false for non-matching errors" , func (t * testing.T ) {
382+ // Create a different error
383+ otherErr := fmt .Errorf ("some other error" )
384+
385+ if IsHandlerExistsError (otherErr ) {
386+ t .Errorf ("IsHandlerExistsError should return false for non-matching error" )
387+ }
388+ if IsProtectedHandlerError (otherErr ) {
389+ t .Errorf ("IsProtectedHandlerError should return false for non-matching error" )
390+ }
391+ if IsVoidProcessorError (otherErr ) {
392+ t .Errorf ("IsVoidProcessorError should return false for non-matching error" )
393+ }
394+ if IsHandlerNilError (otherErr ) {
395+ t .Errorf ("IsHandlerNilError should return false for non-matching error" )
396+ }
397+ })
398+ }
0 commit comments