github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/errors/access_test.go (about)

     1  package errors
     2  
     3  import "testing"
     4  
     5  func TestAccessErrorBlank(t *testing.T) {
     6  	var err error = Access()
     7  	assert(t, "access error", err.Error())
     8  	assert(t, true, IsCallError(err))
     9  	assert(t, true, IsContextError(err))
    10  	assert(t, true, IsAccessError(err))
    11  	assert(t, false, IsAccessForbidden(err))
    12  	assert(t, false, IsAuthorizationInvalid(err))
    13  	assert(t, nil, Unwrap(err))
    14  }
    15  
    16  func TestAccessErrorNoDesc(t *testing.T) {
    17  	var err error = Access().Wrap(N("foo").Desc(ErrEntityNotFound))
    18  	assert(t, "access: foo: not found", err.Error())
    19  }
    20  
    21  func TestAccessDeniedEmpty(t *testing.T) {
    22  	var err error = AccessForbidden()
    23  	assert(t, "access forbidden", err.Error())
    24  	assert(t, true, IsCallError(err))
    25  	assert(t, true, IsContextError(err))
    26  	assert(t, true, IsAccessError(err))
    27  	assert(t, true, IsAccessForbidden(err))
    28  	assert(t, false, IsAuthorizationInvalid(err))
    29  	assert(t, nil, Unwrap(err))
    30  }
    31  
    32  func TestAccessDeniedEntity(t *testing.T) {
    33  	var err error = AccessForbidden().Wrap(N("foo"))
    34  	assert(t, "access forbidden: foo", err.Error())
    35  	assert(t, true, IsAccessError(err))
    36  	assert(t, true, IsAccessForbidden(err))
    37  	assertNotEqual(t, nil, UnwrapDescriptor(err))
    38  	assert(t, ErrAccessForbidden, UnwrapDescriptor(err))
    39  }
    40  
    41  func TestIsAccessDenied(t *testing.T) {
    42  	var err error = ErrAccessForbidden
    43  	assert(t, "forbidden", err.Error())
    44  	assert(t, true, IsAccessForbidden(err))
    45  	assert(t, true, IsAccessError(err))
    46  }