Home / Function/ TestErrorUnwrap() — gin Function Reference

TestErrorUnwrap() — gin Function Reference

Architecture documentation for the TestErrorUnwrap() function in errors_test.go from the gin codebase.

Entity Profile

Relationship Graph

Source Code

errors_test.go lines 116–140

func TestErrorUnwrap(t *testing.T) {
	innerErr := TestErr("some error")

	// 2 layers of wrapping : use 'fmt.Errorf("%w")' to wrap a gin.Error{}, which itself wraps innerErr
	err := fmt.Errorf("wrapped: %w", &Error{
		Err:  innerErr,
		Type: ErrorTypeAny,
	})

	// check that 'errors.Is()' and 'errors.As()' behave as expected :
	require.ErrorIs(t, err, innerErr)
	var testErr TestErr
	require.ErrorAs(t, err, &testErr)

	// Test non-pointer usage of gin.Error
	errNonPointer := Error{
		Err:  innerErr,
		Type: ErrorTypeAny,
	}
	wrappedErr := fmt.Errorf("wrapped: %w", errNonPointer)
	// Check that 'errors.Is()' and 'errors.As()' behave as expected for non-pointer usage
	require.ErrorIs(t, wrappedErr, innerErr)
	var testErrNonPointer TestErr
	require.ErrorAs(t, wrappedErr, &testErrNonPointer)
}

Domain

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free