mock

package
v2.29.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWTParserMock

type JWTParserMock struct {
	// ParseFunc mocks the Parse method.
	ParseFunc func(tokenString string) (*permsdk.EntityData, error)
	// contains filtered or unexported fields
}

JWTParserMock is a mock implementation of authorisation.JWTParser.

func TestSomethingThatUsesJWTParser(t *testing.T) {

	// make and configure a mocked authorisation.JWTParser
	mockedJWTParser := &JWTParserMock{
		ParseFunc: func(tokenString string) (*permsdk.EntityData, error) {
			panic("mock out the Parse method")
		},
	}

	// use mockedJWTParser in code that requires authorisation.JWTParser
	// and then make assertions.

}

func (*JWTParserMock) Parse

func (mock *JWTParserMock) Parse(tokenString string) (*permsdk.EntityData, error)

Parse calls ParseFunc.

func (*JWTParserMock) ParseCalls

func (mock *JWTParserMock) ParseCalls() []struct {
	TokenString string
}

ParseCalls gets all the calls that were made to Parse. Check the length with:

len(mockedJWTParser.ParseCalls())

type MiddlewareMock

type MiddlewareMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func(ctx context.Context) error

	// HealthCheckFunc mocks the HealthCheck method.
	HealthCheckFunc func(ctx context.Context, state *health.CheckState) error

	// IdentityHealthCheckFunc mocks the IdentityHealthCheck method.
	IdentityHealthCheckFunc func(ctx context.Context, state *health.CheckState) error

	// ParseFunc mocks the Parse method.
	ParseFunc func(token string) (*permsdk.EntityData, error)

	// RequireFunc mocks the Require method.
	RequireFunc func(permission string, handlerFunc http.HandlerFunc) http.HandlerFunc

	// RequireWithAttributesFunc mocks the RequireWithAttributes method.
	RequireWithAttributesFunc func(permission string, handlerFunc http.HandlerFunc, getAttributes authorisation.GetAttributesFromRequest) http.HandlerFunc
	// contains filtered or unexported fields
}

MiddlewareMock is a mock implementation of authorisation.Middleware.

func TestSomethingThatUsesMiddleware(t *testing.T) {

	// make and configure a mocked authorisation.Middleware
	mockedMiddleware := &MiddlewareMock{
		CloseFunc: func(ctx context.Context) error {
			panic("mock out the Close method")
		},
		HealthCheckFunc: func(ctx context.Context, state *health.CheckState) error {
			panic("mock out the HealthCheck method")
		},
		IdentityHealthCheckFunc: func(ctx context.Context, state *health.CheckState) error {
			panic("mock out the IdentityHealthCheck method")
		},
		ParseFunc: func(token string) (*permsdk.EntityData, error) {
			panic("mock out the Parse method")
		},
		RequireFunc: func(permission string, handlerFunc http.HandlerFunc) http.HandlerFunc {
			panic("mock out the Require method")
		},
		RequireWithAttributesFunc: func(permission string, handlerFunc http.HandlerFunc, getAttributes authorisation.GetAttributesFromRequest) http.HandlerFunc {
			panic("mock out the RequireWithAttributes method")
		},
	}

	// use mockedMiddleware in code that requires authorisation.Middleware
	// and then make assertions.

}

func (*MiddlewareMock) Close

func (mock *MiddlewareMock) Close(ctx context.Context) error

Close calls CloseFunc.

func (*MiddlewareMock) CloseCalls

func (mock *MiddlewareMock) CloseCalls() []struct {
	Ctx context.Context
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedMiddleware.CloseCalls())

func (*MiddlewareMock) HealthCheck

func (mock *MiddlewareMock) HealthCheck(ctx context.Context, state *health.CheckState) error

HealthCheck calls HealthCheckFunc.

func (*MiddlewareMock) HealthCheckCalls

func (mock *MiddlewareMock) HealthCheckCalls() []struct {
	Ctx   context.Context
	State *health.CheckState
}

HealthCheckCalls gets all the calls that were made to HealthCheck. Check the length with:

len(mockedMiddleware.HealthCheckCalls())

func (*MiddlewareMock) IdentityHealthCheck

func (mock *MiddlewareMock) IdentityHealthCheck(ctx context.Context, state *health.CheckState) error

IdentityHealthCheck calls IdentityHealthCheckFunc.

func (*MiddlewareMock) IdentityHealthCheckCalls

func (mock *MiddlewareMock) IdentityHealthCheckCalls() []struct {
	Ctx   context.Context
	State *health.CheckState
}

IdentityHealthCheckCalls gets all the calls that were made to IdentityHealthCheck. Check the length with:

len(mockedMiddleware.IdentityHealthCheckCalls())

func (*MiddlewareMock) Parse

func (mock *MiddlewareMock) Parse(token string) (*permsdk.EntityData, error)

Parse calls ParseFunc.

func (*MiddlewareMock) ParseCalls

func (mock *MiddlewareMock) ParseCalls() []struct {
	Token string
}

ParseCalls gets all the calls that were made to Parse. Check the length with:

len(mockedMiddleware.ParseCalls())

func (*MiddlewareMock) Require

func (mock *MiddlewareMock) Require(permission string, handlerFunc http.HandlerFunc) http.HandlerFunc

Require calls RequireFunc.

func (*MiddlewareMock) RequireCalls

func (mock *MiddlewareMock) RequireCalls() []struct {
	Permission  string
	HandlerFunc http.HandlerFunc
}

RequireCalls gets all the calls that were made to Require. Check the length with:

len(mockedMiddleware.RequireCalls())

func (*MiddlewareMock) RequireWithAttributes

func (mock *MiddlewareMock) RequireWithAttributes(permission string, handlerFunc http.HandlerFunc, getAttributes authorisation.GetAttributesFromRequest) http.HandlerFunc

RequireWithAttributes calls RequireWithAttributesFunc.

func (*MiddlewareMock) RequireWithAttributesCalls

func (mock *MiddlewareMock) RequireWithAttributesCalls() []struct {
	Permission    string
	HandlerFunc   http.HandlerFunc
	GetAttributes authorisation.GetAttributesFromRequest
}

RequireWithAttributesCalls gets all the calls that were made to RequireWithAttributes. Check the length with:

len(mockedMiddleware.RequireWithAttributesCalls())

type PermissionsCheckerMock

type PermissionsCheckerMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func(ctx context.Context) error

	// HasPermissionFunc mocks the HasPermission method.
	HasPermissionFunc func(ctx context.Context, entityData permsdk.EntityData, permission string, attributes map[string]string) (bool, error)

	// HealthCheckFunc mocks the HealthCheck method.
	HealthCheckFunc func(ctx context.Context, state *health.CheckState) error
	// contains filtered or unexported fields
}

PermissionsCheckerMock is a mock implementation of authorisation.PermissionsChecker.

func TestSomethingThatUsesPermissionsChecker(t *testing.T) {

	// make and configure a mocked authorisation.PermissionsChecker
	mockedPermissionsChecker := &PermissionsCheckerMock{
		CloseFunc: func(ctx context.Context) error {
			panic("mock out the Close method")
		},
		HasPermissionFunc: func(ctx context.Context, entityData permsdk.EntityData, permission string, attributes map[string]string) (bool, error) {
			panic("mock out the HasPermission method")
		},
		HealthCheckFunc: func(ctx context.Context, state *health.CheckState) error {
			panic("mock out the HealthCheck method")
		},
	}

	// use mockedPermissionsChecker in code that requires authorisation.PermissionsChecker
	// and then make assertions.

}

func (*PermissionsCheckerMock) Close

func (mock *PermissionsCheckerMock) Close(ctx context.Context) error

Close calls CloseFunc.

func (*PermissionsCheckerMock) CloseCalls

func (mock *PermissionsCheckerMock) CloseCalls() []struct {
	Ctx context.Context
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedPermissionsChecker.CloseCalls())

func (*PermissionsCheckerMock) HasPermission

func (mock *PermissionsCheckerMock) HasPermission(ctx context.Context, entityData permsdk.EntityData, permission string, attributes map[string]string) (bool, error)

HasPermission calls HasPermissionFunc.

func (*PermissionsCheckerMock) HasPermissionCalls

func (mock *PermissionsCheckerMock) HasPermissionCalls() []struct {
	Ctx        context.Context
	EntityData permsdk.EntityData
	Permission string
	Attributes map[string]string
}

HasPermissionCalls gets all the calls that were made to HasPermission. Check the length with:

len(mockedPermissionsChecker.HasPermissionCalls())

func (*PermissionsCheckerMock) HealthCheck

func (mock *PermissionsCheckerMock) HealthCheck(ctx context.Context, state *health.CheckState) error

HealthCheck calls HealthCheckFunc.

func (*PermissionsCheckerMock) HealthCheckCalls

func (mock *PermissionsCheckerMock) HealthCheckCalls() []struct {
	Ctx   context.Context
	State *health.CheckState
}

HealthCheckCalls gets all the calls that were made to HealthCheck. Check the length with:

len(mockedPermissionsChecker.HealthCheckCalls())

type ZebedeeClientMock

type ZebedeeClientMock struct {
	// CheckTokenIdentityFunc mocks the CheckTokenIdentity method.
	CheckTokenIdentityFunc func(ctx context.Context, token string) (*dprequest.IdentityResponse, error)
	// contains filtered or unexported fields
}

ZebedeeClientMock is a mock implementation of authorisation.ZebedeeClient.

func TestSomethingThatUsesZebedeeClient(t *testing.T) {

	// make and configure a mocked authorisation.ZebedeeClient
	mockedZebedeeClient := &ZebedeeClientMock{
		CheckTokenIdentityFunc: func(ctx context.Context, token string) (*dprequest.IdentityResponse, error) {
			panic("mock out the CheckTokenIdentity method")
		},
	}

	// use mockedZebedeeClient in code that requires authorisation.ZebedeeClient
	// and then make assertions.

}

func (*ZebedeeClientMock) CheckTokenIdentity

func (mock *ZebedeeClientMock) CheckTokenIdentity(ctx context.Context, token string) (*dprequest.IdentityResponse, error)

CheckTokenIdentity calls CheckTokenIdentityFunc.

func (*ZebedeeClientMock) CheckTokenIdentityCalls

func (mock *ZebedeeClientMock) CheckTokenIdentityCalls() []struct {
	Ctx   context.Context
	Token string
}

CheckTokenIdentityCalls gets all the calls that were made to CheckTokenIdentity. Check the length with:

len(mockedZebedeeClient.CheckTokenIdentityCalls())

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL