handler

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: GPL-3.0 Imports: 29 Imported by: 0

Documentation

Overview

Package handler contains the logic of the server.

It contains sub-packages for the different use-cases (creating, editing, deleting...). The handler package contains interfaces for the sub-packages to access the store (store_interfaces.go). The handler package contains functions for the sub-packages to retrieve templates from the template package (template.go). The handler package contains functions for the sub-packages to access data from the context (context.go).

Testing the handlers: The handler packages provides functions, mocks and dummy-data for the sub-packages to test the handlers. The functions are in the files starting with testing_*.go

Index

Constants

View Source
const (
	ErrInvalidTestSequenceVersionTitle = "Invalid test sequence version."
	ErrInvalidTestSequenceVersion      = "Your client tried to access an invalid version " +
		"of a test sequence. If you believe this is a bug please contact us via our " +
		IssueTracker + "."
)

Error-messages for retrieving sequence versions from the request

View Source
const IssueTracker = "<a href='https://gitlab.com/stp-team/systemtestportal-webapp/issues'>issue tracker</a>"

IssueTracker is a html link to the issue board of the stp-repository

Variables

View Source
var DummyGroup = &group.Group{
	Name:        "Dummy Group Name",
	Description: "Desc",
	Visibility:  visibility.Public,
}

DummyGroup is a group for testing purposes

View Source
var DummyMembership = &project.UserMembership{
	User:        "acc_name",
	Role:        "Supervisor",
	MemberSince: time.Now().UTC().Round(time.Second),
}

DummyMembership represents a membership that is used for testing purposes The user has the role "Supervisor" so he ca

View Source
var DummyProject = &project.Project{
	Name:        "DuckDuckGo.com",
	Description: "Test the online search engine DuckDuckGo.com",
	Visibility:  visibility.Public,
	Owner:       "default",
	Variants: map[string]*project.Variant{
		"Chrome": {
			Name: "Chrome",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Firefox": {
			Name: "Firefox",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Microsoft Edge": {
			Name: "Microsoft Edge",
			Versions: []project.Version{
				0: {Name: "1.0.2"},
				1: {Name: "2.0.2"},
				2: {Name: "3.0.1"},
			},
		},
	},
	UserMembers: map[id.ActorID]project.UserMembership{
		id.ActorID(DummyUser.Name): *DummyMembership,
	},
	Roles:        DummyRoles,
	CreationDate: time.Now().UTC().Round(time.Second),
}

DummyProject contains a project for testing purposes

View Source
var DummyProjectInternal = &project.Project{
	Name:        "DuckDuckGo.com",
	Description: "Test the online search engine DuckDuckGo.com",
	Visibility:  visibility.Internal,
	Owner:       "default",
	Variants: map[string]*project.Variant{
		"Chrome": {
			Name: "Chrome",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Firefox": {
			Name: "Firefox",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Microsoft Edge": {
			Name: "Microsoft Edge",
			Versions: []project.Version{
				0: {Name: "1.0.2"},
				1: {Name: "2.0.2"},
				2: {Name: "3.0.1"},
			},
		},
	},
	UserMembers: map[id.ActorID]project.UserMembership{
		id.ActorID(DummyUser.Name): *DummyMembership,
	},
	Roles:        DummyRoles,
	CreationDate: time.Now().UTC().Round(time.Second),
}

DummyProjectInternal contains an internal project for testing purposes

View Source
var DummyProjectPrivate = &project.Project{
	Name:        "DuckDuckGo.com",
	Description: "Test the online search engine DuckDuckGo.com",
	Visibility:  visibility.Private,
	Owner:       "default",
	Variants: map[string]*project.Variant{
		"Chrome": {
			Name: "Chrome",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Firefox": {
			Name: "Firefox",
			Versions: []project.Version{
				0: {Name: "1.0.1"},
				1: {Name: "2.0.1"},
				2: {Name: "3.0.5"},
			},
		},
		"Microsoft Edge": {
			Name: "Microsoft Edge",
			Versions: []project.Version{
				0: {Name: "1.0.2"},
				1: {Name: "2.0.2"},
				2: {Name: "3.0.1"},
			},
		},
	},
	UserMembers: map[id.ActorID]project.UserMembership{
		id.ActorID(DummyUser.Name): *DummyMembership,
	},
	Roles:        DummyRoles,
	CreationDate: time.Now().UTC().Round(time.Second),
}

DummyProjectPrivate contains a project for testing purposes

View Source
var DummyRoles = map[project.RoleName]*project.Role{
	"Supervisor": {
		Name: "Supervisor",
		Permissions: project.Permissions{
			DisplayPermissions: project.DisplayPermissions{
				DisplayProject: true,
			},
			ExecutionPermissions: project.ExecutionPermissions{
				Execute: true,
			},
			CasePermissions: project.CasePermissions{
				CreateCase:    true,
				EditCase:      true,
				DeleteCase:    true,
				AssignCase:    true,
				DuplicateCase: true,
			},
			SequencePermissions: project.SequencePermissions{
				CreateSequence:    true,
				EditSequence:      true,
				DeleteSequence:    true,
				DuplicateSequence: true,
				AssignSequence:    true,
			},
			MemberPermissions: project.MemberPermissions{
				EditMembers: true,
			},
			SettingsPermissions: project.SettingsPermissions{
				EditProject:     true,
				DeleteProject:   true,
				EditPermissions: true,
			},
		},
	},
	"Manager": {
		Name: "Manager",
		Permissions: project.Permissions{
			DisplayPermissions: project.DisplayPermissions{
				DisplayProject: true,
			},
			ExecutionPermissions: project.ExecutionPermissions{
				Execute: true,
			},
			CasePermissions: project.CasePermissions{
				CreateCase:    true,
				EditCase:      true,
				DeleteCase:    true,
				AssignCase:    true,
				DuplicateCase: true,
			},
			SequencePermissions: project.SequencePermissions{
				CreateSequence:    true,
				EditSequence:      true,
				DeleteSequence:    true,
				DuplicateSequence: true,
				AssignSequence:    true,
			},
			MemberPermissions: project.MemberPermissions{
				EditMembers: false,
			},
			SettingsPermissions: project.SettingsPermissions{
				EditProject:     false,
				DeleteProject:   false,
				EditPermissions: false,
			},
		},
	},
	"Tester": {
		Name: "Tester",
		Permissions: project.Permissions{
			DisplayPermissions: project.DisplayPermissions{
				DisplayProject: true,
			},
			ExecutionPermissions: project.ExecutionPermissions{
				Execute: true,
			},
			CasePermissions: project.CasePermissions{
				CreateCase:    false,
				EditCase:      false,
				DeleteCase:    false,
				AssignCase:    false,
				DuplicateCase: false,
			},
			SequencePermissions: project.SequencePermissions{
				CreateSequence:    false,
				EditSequence:      false,
				DuplicateSequence: false,
				DeleteSequence:    false,
				AssignSequence:    false,
			},
			MemberPermissions: project.MemberPermissions{
				EditMembers: false,
			},
			SettingsPermissions: project.SettingsPermissions{
				EditProject:     false,
				DeleteProject:   false,
				EditPermissions: false,
			},
		},
	},
}

DummyRoles are dummy roles for testing purposes

View Source
var DummyTestCase = &test.Case{
	Name: "Test Case 1",
	TestCaseVersions: []test.CaseVersion{
		{
			Description: "First Test Case",
			Variants:    map[string]*project.Variant{},
			Steps: []test.Step{
				{
					Index:          1,
					Action:         "Open the application",
					ExpectedResult: "The main screen should show",
				},
				{
					Index:          2,
					Action:         "Open the login page",
					ExpectedResult: "The login page should show",
				},
				{
					Index:          3,
					Action:         "Login with the test login",
					ExpectedResult: "The login should succeed",
				},
			},
		},
	},
	Project: DummyProject.ID(),
}

DummyTestCase is a test case for testing purposes

View Source
var DummyTestCaseSUTVersions = &test.Case{
	Name: "Test Case 1",
	TestCaseVersions: []test.CaseVersion{
		{
			Description: "First Test Case",
			Variants: map[string]*project.Variant{
				"Chrome": {
					Name: "Chrome",
					Versions: []project.Version{
						0: {Name: "1.0.1"},
						1: {Name: "2.0.1"},
						2: {Name: "3.0.5"},
					},
				},
				"Firefox": {
					Name: "Firefox",
					Versions: []project.Version{
						0: {Name: "1.0.1"},
						1: {Name: "2.0.1"},
						2: {Name: "3.0.5"},
					},
				},
				"Microsoft Edge": {
					Name: "Microsoft Edge",
					Versions: []project.Version{
						0: {Name: "1.0.2"},
						1: {Name: "2.0.2"},
						2: {Name: "3.0.1"},
					},
				},
			},
			Steps: []test.Step{
				{
					Index:          1,
					Action:         "Open the application",
					ExpectedResult: "The main screen should show",
				},
				{
					Index:          2,
					Action:         "Open the login page",
					ExpectedResult: "The login page should show",
				},
				{
					Index:          3,
					Action:         "Login with the test login",
					ExpectedResult: "The login should succeed",
				},
			},
		},
	},
	Project: DummyProject.ID(),
}

DummyTestCaseSUTVersions is a test case for testing purposes that contains sut-versions

View Source
var DummyTestSequence = &test.Sequence{
	Name:   "test-sequence-1",
	Labels: []project.Label{},
	SequenceVersions: []test.SequenceVersion{
		dummyTestSequenceVersion,
	},
}

DummyTestSequence is a sequence for testing purposes

View Source
var DummyTestSequenceJSON string

DummyTestSequenceJSON is sequence in json for testing purposes

View Source
var DummyUser = &user.User{
	DisplayName: "DisplayName",
	Name:        "acc_name",
	EMail:       "test@example.com",
}

DummyUser is a user for testing purposes

View Source
var DummyUserUnauthorized = &user.User{
	DisplayName: "DisplayName",
	Name:        "unauthorized",
	EMail:       "un@authorized.com",
}

DummyUserUnauthorized is a user that is is not authorized to send requests because he is not a member of a project

View Source
var EmptyCtx = &testContext{make(map[interface{}]interface{})}

EmptyCtx is an empty context for testing purpses

View Source
var ErrTest = errors.New("error was injected by a test to check reaction")

ErrTest is an error that can be used if your test needs to

View Source
var NoParams = url.Values{}

NoParams is simply an empty set of parameters for a request.

Functions

func AssertResponse added in v1.0.0

func AssertResponse(t *testing.T, tested http.HandlerFunc, r *http.Request,
	matchers ...ResponseMatcher)

AssertResponse sends given request to given tested handler and runs given ResponseMatchers on it.

func EmptyRequest added in v1.0.0

func EmptyRequest(method string) *http.Request

EmptyRequest creates a simple test request with no parameters and no context attached to it.

func GetBaseTree added in v1.0.0

func GetBaseTree() templates.LoadedTemplate

GetBaseTree returns a loaded base template containing only utility function used by the templates.

func GetComments added in v1.0.0

func GetComments(r *http.Request) []*comment.Comment

GetComments gets the comments from a given request if they were stored there by middleware. If the comment slice is nil or not contained in the request, nil will be returned.

func GetLatestTestCaseVersion added in v1.0.0

func GetLatestTestCaseVersion(r *http.Request, tc *test.Case) (*test.CaseVersion, error)

GetLatestTestCaseVersion gets the version of a testcase from a request. If the request doesn't contain a version number the latest is assumed. If the number send by the request is not the latest version an error is returned.

func GetNoSideBarTree added in v1.0.0

func GetNoSideBarTree() templates.LoadedTemplate

GetNoSideBarTree returns a loaded template structure for a view not containing the sidebar.

func GetPrintTree added in v1.0.0

func GetPrintTree() templates.LoadedTemplate

GetPrintTree returns a loaded template structure for a print view .

func GetSideBarTree added in v1.0.0

func GetSideBarTree() templates.LoadedTemplate

GetSideBarTree returns a loaded template structure for a view containing the sidebar.

func GetTestCaseVersion added in v1.0.0

func GetTestCaseVersion(r *http.Request, tc *test.Case) (*test.CaseVersion, error)

GetTestCaseVersion gets the version of a testcase from a request. If the request doesn't contain a version number the latest is assumed. If the number send by the request is out of the range of possible versions an error is returned.

func GetTestCases added in v1.0.0

func GetTestCases(tg TestCaseGetter, ids ...id.TestID) ([]test.Case, error)

GetTestCases returns the testcase objects of the given ids

func GetTestSequenceVersion added in v1.0.0

func GetTestSequenceVersion(r *http.Request, ts *test.Sequence) (*test.SequenceVersion, error)

GetTestSequenceVersion gets the version of a testsequence from a request. If the request doesn't contain a version number the latest is assumed. If the number send by the request is out of the range of possible versions an error is returned.

func GetVersion added in v1.0.0

func GetVersion(r *http.Request, defaultVersion int) int

GetVersion gets the version field from a request. Returns defaultVersion if the version is empty. Returns -1 if the version is not an integer.

func InvalidRequest added in v1.0.0

func InvalidRequest(r *http.Request) errors.HandlerError

InvalidRequest returns an error describing that the request contained no or invalid information.

func InvalidTCVersion

func InvalidTCVersion() errors.HandlerError

InvalidTCVersion returns an ErrorMessage describing that the test case version is not valid

func InvalidVisibility

func InvalidVisibility() errors.HandlerError

InvalidVisibility returns an ErrorMessage describing that a value is not valid.

func NewFragmentRequest added in v1.0.0

func NewFragmentRequest(ctx context.Context, method string, params url.Values, body string) *http.Request

NewFragmentRequest is used to create a request for testing.

func NewRequest added in v1.0.0

func NewRequest(ctx context.Context, method string, params url.Values, body string) *http.Request

NewRequest is used to create a request for testing.

func PrintTmpl added in v1.0.0

func PrintTmpl(ctx context.Context, template *template.Template, w io.Writer, r *http.Request)

PrintTmpl prints given template with given context into given writer. If an error occurs, an error response is written to the writer instead of the executed template's content.

If the given writer was a http.ResponseWriter the status code http.StatusInternalServerError will be written to its header if an error occurred.

func SimpleContext added in v1.0.0

func SimpleContext(values map[interface{}]interface{}) context.Context

SimpleContext returns a context made of given map. It is a very simple implementation of a context.Context.

func SimpleFragmentRequest added in v1.0.0

func SimpleFragmentRequest(ctx context.Context, method string, params url.Values) *http.Request

SimpleFragmentRequest is used to create a simple request for testing.

func SimpleRequest added in v1.0.0

func SimpleRequest(ctx context.Context, method string, params url.Values) *http.Request

SimpleRequest is used to create a simple request for testing.

func StringToInt added in v1.0.0

func StringToInt(s string) int

StringToInt gets a string and converts it to int. Returns -1 if the string cannot be converted to an int.

func Suite added in v1.0.0

func Suite(t *testing.T, tests ...TestHandler)

Suite runs several handlers test as sub tests of the current test.

func UnauthorizedAccess added in v1.0.0

func UnauthorizedAccess(r *http.Request) errors.HandlerError

UnauthorizedAccess returns an ErrorMessage describing that the user is not authorized

Types

type ActorExistenceCheckerMock added in v1.0.0

type ActorExistenceCheckerMock struct {
	CallerMock

	Exst bool
	// contains filtered or unexported fields
}

ActorExistenceCheckerMock mocks the ActorExistenceChecker

func (*ActorExistenceCheckerMock) Exists added in v1.0.0

func (m *ActorExistenceCheckerMock) Exists(id id.ActorID) (bool, error)

Exists mocks checking for the existence of an actor

type AuthMock added in v1.0.0

type AuthMock struct {
	GivenIdentifier string
	GivenPassword   string
	// contains filtered or unexported fields
}

AuthMock mocks the Auth interface

func NewAuthMock added in v1.0.0

func NewAuthMock(returnedUser *user.User, returnedError error, accept bool) *AuthMock

NewAuthMock creates a new Auth mock

func (*AuthMock) Validate added in v1.0.0

func (a *AuthMock) Validate(identifier string, password string) (*user.User, bool, error)

Validate is a mock method

type CallerCounterMock added in v1.0.0

type CallerCounterMock interface {
	// Calls returns the number of calls made to the mock.
	Calls() int
}

CallerCounterMock is an interface for the CallerMock to count the calls made to the mock

type CallerMock added in v1.0.0

type CallerMock struct {
	Called int
}

CallerMock mocks the Caller

func (*CallerMock) Calls added in v1.0.0

func (m *CallerMock) Calls() int

Calls returns the number of calls made to the mock.

type CaseAdderMock added in v1.0.0

type CaseAdderMock struct {
	CallerMock
	*test.Case
	Err error
}

CaseAdderMock is a mock of the CaseAdder

func (*CaseAdderMock) Add added in v1.0.0

func (m *CaseAdderMock) Add(testCase *test.Case) error

Add mocks adding a case to the store

type CaseDeleterMock added in v1.0.0

type CaseDeleterMock struct {
	CallerMock
	id.TestID
}

CaseDeleterMock mocks the CaseDeleter

func (*CaseDeleterMock) Delete added in v1.0.0

func (m *CaseDeleterMock) Delete(caseID id.TestID) error

Delete mocks deleting a case from the store

type CaseGetterMock added in v1.0.0

type CaseGetterMock struct {
	CallerMock
	CaseID id.TestID
}

CaseGetterMock mocks the CaseGetter

func (*CaseGetterMock) Get added in v1.0.0

func (m *CaseGetterMock) Get(caseID id.TestID) (*test.Case, bool, error)

Get mocks the retrieval of a case from a test id

type CaseListerMock added in v1.0.0

type CaseListerMock struct {
	CallerMock
	Project id.ProjectID
	Err     error
}

CaseListerMock mocks the CaseLister

func (*CaseListerMock) List added in v1.0.0

func (m *CaseListerMock) List(projectID id.ProjectID) ([]*test.Case, error)

List mocks listing cases

type CaseProtocolAdderMock added in v1.1.0

type CaseProtocolAdderMock struct {
	CallerMock
	CaseExecutionProtocol test.CaseExecutionProtocol
	Err                   error
}

CaseProtocolAdderMock mocks the CaseProtocolAdder interface

func (*CaseProtocolAdderMock) AddCaseProtocol added in v1.1.0

func (caseProtocolAdderMock *CaseProtocolAdderMock) AddCaseProtocol(r *test.CaseExecutionProtocol) (err error)

AddCaseProtocol mocks adding a case protocol to the store

type CaseProtocolGetterMock added in v1.1.0

type CaseProtocolGetterMock struct {
	CallerMock
	CaseExecutionProtocol test.CaseExecutionProtocol
	ProtocolID            id.ProtocolID
	Err                   error
}

CaseProtocolGetterMock mocks the CaseProtocolGetter interface

func (*CaseProtocolGetterMock) GetCaseExecutionProtocol added in v1.1.0

func (caseProtocolGetterMock *CaseProtocolGetterMock) GetCaseExecutionProtocol(protocolID id.ProtocolID) (
	test.CaseExecutionProtocol, error)

GetCaseExecutionProtocol mocks getting a case protocol from the session

type CaseProtocolListerMock added in v1.0.0

type CaseProtocolListerMock struct {
	CallerMock

	Protocols []test.CaseExecutionProtocol
	Err       error
	// contains filtered or unexported fields
}

CaseProtocolListerMock mocks the CaseProtocolsLister

func (*CaseProtocolListerMock) GetCaseExecutionProtocols added in v1.0.0

func (m *CaseProtocolListerMock) GetCaseExecutionProtocols(testCaseID id.TestID) ([]test.CaseExecutionProtocol, error)

GetCaseExecutionProtocols mocks retrieving protocols of a case

type CaseProtocolRenamerMock added in v1.0.0

type CaseProtocolRenamerMock struct {
	CallerMock
	Old id.TestID
	New id.TestID
}

CaseProtocolRenamerMock mocks the CaseProtocolRenamer

func (*CaseProtocolRenamerMock) HandleCaseRename added in v1.0.0

func (m *CaseProtocolRenamerMock) HandleCaseRename(old, new id.TestID) error

HandleCaseRename mocks renaming a test

type CaseProtocolStoreMock added in v1.1.0

type CaseProtocolStoreMock struct {
	CallerMock
	TestCaseID             id.TestID
	CaseExecutionProtocols []test.CaseExecutionProtocol
	CaseProtocolAdderMock
	CaseProtocolGetterMock
	Err error
}

CaseProtocolStoreMock mocks the CaseProtocolStore interface

func (*CaseProtocolStoreMock) GetCaseExecutionProtocols added in v1.1.0

func (caseProtocolStoreMock *CaseProtocolStoreMock) GetCaseExecutionProtocols(testCaseID id.TestID) (
	[]test.CaseExecutionProtocol, error)

GetCaseExecutionProtocols mocks getting all protocol of a case

type CaseRenamerMock added in v1.0.0

type CaseRenamerMock struct {
	CallerMock
	Old id.TestID
	New id.TestID
}

CaseRenamerMock mocks the CaseRenamer

func (*CaseRenamerMock) Rename added in v1.0.0

func (m *CaseRenamerMock) Rename(old, new id.TestID) error

Rename mocks the renaming of a test

type CaseSessionGetterMock added in v1.1.0

type CaseSessionGetterMock struct {
	CallerMock
	CaseExecutionProtocol *test.CaseExecutionProtocol
	Err                   error
}

CaseSessionGetterMock mocks the CaseSessionGetter interface

func (*CaseSessionGetterMock) GetCurrentCaseProtocol added in v1.1.0

func (csgm *CaseSessionGetterMock) GetCurrentCaseProtocol(r *http.Request) (*test.CaseExecutionProtocol, error)

GetCurrentCaseProtocol mocks getting the current case protocol

type CaseSessionMock added in v1.1.0

type CaseSessionMock struct {
	CallerMock
	CaseSessionUpdaterMock
	TimeSessionMock
	Err error
}

CaseSessionMock mocks the CaseSession interface

func (*CaseSessionMock) RemoveCurrentCaseProtocol added in v1.1.0

func (csm *CaseSessionMock) RemoveCurrentCaseProtocol(w http.ResponseWriter, r *http.Request) error

RemoveCurrentCaseProtocol mocks removing the current case protocol from the session

type CaseSessionSetterMock added in v1.1.0

type CaseSessionSetterMock struct {
	CallerMock
	Err error
}

CaseSessionSetterMock mocks the CaseSessionSetter interface

func (*CaseSessionSetterMock) SetCurrentCaseProtocol added in v1.1.0

func (cssm *CaseSessionSetterMock) SetCurrentCaseProtocol(w http.ResponseWriter, r *http.Request,
	protocol *test.CaseExecutionProtocol) error

SetCurrentCaseProtocol mocks setting the current case protocol

type CaseSessionUpdaterMock added in v1.1.0

type CaseSessionUpdaterMock struct {
	CallerMock
	CaseSessionGetterMock
	CaseSessionSetterMock
}

CaseSessionUpdaterMock mocks the CaseSessionUpdater interface

type CaseUpdaterMock added in v1.0.0

type CaseUpdaterMock struct {
	CaseDeleterMock
	CaseAdderMock
	CaseRenamerMock
}

CaseUpdaterMock mocks the CaseUpdater

type CommentAdder added in v0.10.0

type CommentAdder interface {
	// Add stores a comment for the given test case, project and container
	Add(c *comment.Comment) error
}

CommentAdder is used to store a comment to the store

type CommentAdderMock added in v1.0.0

type CommentAdderMock struct {
	CallerMock
	Comment *comment.Comment
}

CommentAdderMock mocks the CommentAdder

func (*CommentAdderMock) Add added in v1.0.0

Add mocks adding a comment to the store

type ContextEntities added in v1.0.0

type ContextEntities struct {
	User        *user.User
	ContainerID id.ActorID
	Project     *project.Project
	Case        *test.Case
	Sequence    *test.Sequence
	Err         error
}

ContextEntities contains every entity that a handler could need for handling requests. These are entities like the project, user, case, sequence etc.

func GetContextEntities added in v1.0.0

func GetContextEntities(r *http.Request) *ContextEntities

GetContextEntities returns all entities that are in the request. Entities are a project, user case, sequence or container. If an entity could not be retrieved, the entity is nil.

Any error that occurs while retrieving the entities is logged. The Err in the ContextEntities is an InvalidRequest error.

type GroupAdder added in v0.8.0

type GroupAdder interface {
	// Add stores a group in the system
	Add(group *group.Group) error
}

GroupAdder is used to add groups to the storage.

type GroupAdderMock added in v1.0.0

type GroupAdderMock struct {
	CallerMock

	Err error
	// contains filtered or unexported fields
}

GroupAdderMock mocks the GroupAdder

func (*GroupAdderMock) Add added in v1.0.0

func (m *GroupAdderMock) Add(group *group.Group) error

Add mocks adding a group to the store

type GroupLister added in v0.8.0

type GroupLister interface {
	// List returns a list of groups in the system
	List() ([]*group.Group, error)
}

GroupLister is used to list all groups in the system.

type GroupListerMock added in v1.0.0

type GroupListerMock struct {
	CallerMock
	Groups []*group.Group
	Err    error
}

GroupListerMock mocks the GroupLister

func (*GroupListerMock) List added in v1.0.0

func (m *GroupListerMock) List() ([]*group.Group, error)

List mocks listing groups

type ProjectAdder added in v0.8.0

type ProjectAdder interface {
	// Add stores a new project. The first argument is used to identify the container for the project
	Add(*project.Project) error
}

ProjectAdder is used to add projects to the storage.

type ProjectAdderMock added in v1.0.0

type ProjectAdderMock struct {
	CallerMock
	*project.Project
	Err error
}

ProjectAdderMock mocks the ProjectAdder

func (*ProjectAdderMock) Add added in v1.0.0

func (p *ProjectAdderMock) Add(pr *project.Project) error

Add mocks adding a project to the store

type ProjectDeleter added in v0.10.0

type ProjectDeleter interface {
	// Delete removes an existing project. The first argument is used to identify the container
	// and the second to identify the project
	Delete(projectID id.ProjectID) error
}

ProjectDeleter is used to delete the reference of an existing project from storage

type ProjectDeleterMock added in v1.0.0

type ProjectDeleterMock struct {
	CallerMock
	id.ProjectID
	Err error
}

ProjectDeleterMock mocks the ProjectDeleter

func (*ProjectDeleterMock) Delete added in v1.0.0

func (m *ProjectDeleterMock) Delete(projectID id.ProjectID) error

Delete mocks deleting a project from the store

type ProjectExistenceMock added in v1.0.0

type ProjectExistenceMock struct {
	CallerMock
	id.ProjectID
	Exst bool
}

ProjectExistenceMock mocks the ProjectExistenceChecker

func (*ProjectExistenceMock) Exists added in v1.0.0

func (m *ProjectExistenceMock) Exists(id id.ProjectID) (bool, error)

Exists mocks checking for the existence of a project

type ProjectLister added in v0.8.0

type ProjectLister interface {
	// List returns a list of projects in the system
	List() ([]*project.Project, error)
	// ListForOwner returns the projects for an owner
	ListForOwner(id.ActorID) ([]*project.Project, error)
	// ListForMember returns all projects where the actor is a member
	ListForMember(id.ActorID) ([]*project.Project, error)
	// ListForActor returns all projects that the actor has access to
	ListForActor(id.ActorID) ([]*project.Project, error)
	// ListAll returns all projects in the system
	ListAll() ([]*project.Project, error)
	// ListPublic returns all public projects in the system
	ListPublic() ([]*project.Project, error)
	// ListInternal returns all internal projects in the system
	ListInternal() ([]*project.Project, error)
	// ListPrivate returns all private projects for an actor
	ListPrivate(id.ActorID) ([]*project.Project, error)
}

ProjectLister is used to list all projects in the system.

type ProjectListerMock added in v1.0.0

type ProjectListerMock struct {
	CallerMock
	Projects []*project.Project
	Err      error
}

ProjectListerMock mocks the ProjectLister

func (*ProjectListerMock) List added in v1.0.0

func (m *ProjectListerMock) List() ([]*project.Project, error)

List mocks listing projects

func (*ProjectListerMock) ListAll added in v1.1.0

func (m *ProjectListerMock) ListAll() ([]*project.Project, error)

ListAll mocks listing projects

func (*ProjectListerMock) ListForActor added in v1.1.0

func (m *ProjectListerMock) ListForActor(actor id.ActorID) ([]*project.Project, error)

ListForActor mocks listing all projects that the actor has access to

func (*ProjectListerMock) ListForMember added in v1.1.0

func (m *ProjectListerMock) ListForMember(owner id.ActorID) ([]*project.Project, error)

ListForMember mocks listing projects where the actor is a member

func (*ProjectListerMock) ListForOwner added in v1.1.0

func (m *ProjectListerMock) ListForOwner(owner id.ActorID) ([]*project.Project, error)

ListForOwner mocks listing projects for an owner

func (*ProjectListerMock) ListInternal added in v1.1.0

func (m *ProjectListerMock) ListInternal() ([]*project.Project, error)

ListInternal mocks listing internal projects

func (*ProjectListerMock) ListPrivate added in v1.1.0

func (m *ProjectListerMock) ListPrivate(actor id.ActorID) ([]*project.Project, error)

ListPrivate mocks listing private projects

func (*ProjectListerMock) ListPublic added in v1.1.0

func (m *ProjectListerMock) ListPublic() ([]*project.Project, error)

List mocks listing projects

type ProtocolCaseRenamer added in v1.0.0

type ProtocolCaseRenamer interface {
	// HandleCaseRename updates the protocol store after a test case has been renamed
	HandleCaseRename(old, new id.TestID) error
}

ProtocolCaseRenamer is used to handle renames.

type ProtocolListerMock added in v1.1.0

type ProtocolListerMock struct {
	CallerMock
	TestVersionID id.TestVersionID
	ProtocolIDs   []id.ProtocolID
	Err           error
}

ProtocolListerMock mocks the ProtocolLister interface

func (*ProtocolListerMock) GetTestVersionProtocols added in v1.1.0

func (protocolListerMock *ProtocolListerMock) GetTestVersionProtocols(testVersionID id.TestVersionID) ([]id.ProtocolID,
	error)

GetTestVersionProtocols mocks getting the protocols of a test version

type RegisterServerMock added in v1.0.0

type RegisterServerMock struct {
	GetUserIDIn     id.ActorID
	GetUserMailIn   string
	GetUserUserOut  *user.User
	GetUserFoundOut bool
	AddUserUserIn   *user.PasswordUser
	AddUserErrorOut error
}

RegisterServerMock mocks the RegisterServer

func (*RegisterServerMock) Add added in v1.0.0

Add mocks adding a user to the store

func (*RegisterServerMock) Get added in v1.0.0

func (usm *RegisterServerMock) Get(id id.ActorID) (*user.User, bool, error)

Get mocks the retrieval of the user from a given id

func (*RegisterServerMock) GetByMail added in v1.0.0

func (usm *RegisterServerMock) GetByMail(mail string) (*user.User, bool, error)

GetByMail mocks the retrieval of the user from a given mail

type ResponseMatcher added in v1.0.0

type ResponseMatcher func(t *testing.T, r *http.Response)

ResponseMatcher is used to check a condition on a response that a handler gave.

func HasBody added in v1.0.0

func HasBody(expectedBody string) ResponseMatcher

HasBody is a matcher that test if the response has given body or not. Whitespace will be trimmed from the body and given string.

func HasCalls added in v1.0.0

func HasCalls(mock CallerCounterMock, number int) ResponseMatcher

HasCalls is a simple matcher that checks whether given mock has a certain number of calls.

func HasStatus added in v1.0.0

func HasStatus(expectedStatus int) ResponseMatcher

HasStatus is a simple matcher that checks whether teh response has given status code.

func Matches added in v1.0.0

func Matches(matchers ...ResponseMatcher) []ResponseMatcher

Matches is a utility method to get a ResponseMatcher array the easy way.

type SequenceAdderMock added in v1.0.0

type SequenceAdderMock struct {
	CallerMock
	TestSequence *test.Sequence
	Err          error
}

SequenceAdderMock mocks the SequenceAdder

func (*SequenceAdderMock) Add added in v1.0.0

func (m *SequenceAdderMock) Add(testSequence *test.Sequence) error

Add mocks adding a sequence to the store

type SequenceDeletionMock added in v1.0.0

type SequenceDeletionMock struct {
	CallerMock
	ID id.TestID
}

SequenceDeletionMock mocks the SequenceDeleter

func (*SequenceDeletionMock) Delete added in v1.0.0

func (m *SequenceDeletionMock) Delete(sequenceID id.TestID) error

Delete mocks deleting a sequence from the store

type SequenceListerMock added in v1.0.0

type SequenceListerMock struct {
	CallerMock
	Project id.ProjectID
	Err     error
}

SequenceListerMock mocks the SequenceLister

func (*SequenceListerMock) List added in v1.0.0

func (m *SequenceListerMock) List(projectID id.ProjectID) ([]*test.Sequence, error)

List mocks listing sequences

type SequenceProtocolAdderMock added in v1.1.0

type SequenceProtocolAdderMock struct {
	CallerMock
	SequenceExecutionProtocol *test.SequenceExecutionProtocol
	Err                       error
}

SequenceProtocolAdderMock mocks the SequenceProtocolAdder interface

func (*SequenceProtocolAdderMock) AddSequenceProtocol added in v1.1.0

func (sequenceProtocolAdderMock *SequenceProtocolAdderMock) AddSequenceProtocol(
	r *test.SequenceExecutionProtocol) error

AddSequenceProtocol mocks adding a sequence protocol to the store

type SequenceProtocolListerMock added in v1.0.0

type SequenceProtocolListerMock struct {
	CallerMock

	Protocols []test.SequenceExecutionProtocol
	Err       error
	// contains filtered or unexported fields
}

SequenceProtocolListerMock mocks the SequenceProtocolLister

func (*SequenceProtocolListerMock) GetSequenceExecutionProtocols added in v1.0.0

func (m *SequenceProtocolListerMock) GetSequenceExecutionProtocols(sequenceID id.TestID) (
	[]test.SequenceExecutionProtocol, error,
)

GetSequenceExecutionProtocols mocks retrieving protocols of a sequence

type SequenceRenameHandler added in v1.0.0

type SequenceRenameHandler interface {
	// HandlerSequenceRename allows dependents to handle renames of test sequences
	HandleSequenceRename(old, new id.TestID) error
}

SequenceRenameHandler defines an interface clients need to fulfill to handle renames of test sequences

type SequenceRenameHandlerMock added in v1.0.0

type SequenceRenameHandlerMock struct {
	CallerMock
	// contains filtered or unexported fields
}

SequenceRenameHandlerMock mocks the SequenceRenameHandler

func (*SequenceRenameHandlerMock) HandleSequenceRename added in v1.0.0

func (srh *SequenceRenameHandlerMock) HandleSequenceRename(old, new id.TestID) error

HandleSequenceRename mocks renaming a sequence

type SequenceRenamerMock added in v1.0.0

type SequenceRenamerMock struct {
	CallerMock
	// contains filtered or unexported fields
}

SequenceRenamerMock mocks the SequenceRenamer

func (*SequenceRenamerMock) Rename added in v1.0.0

func (m *SequenceRenamerMock) Rename(old, new id.TestID) error

Rename mocks renaming a sequence

type SequenceSessionGetterMock added in v1.1.0

type SequenceSessionGetterMock struct {
	CallerMock
	SeqExecProtocol *test.SequenceExecutionProtocol
}

SequenceSessionGetterMock mocks the SequenceSessionGetter interface

func (*SequenceSessionGetterMock) GetCurrentSequenceProtocol added in v1.1.0

func (ssgm *SequenceSessionGetterMock) GetCurrentSequenceProtocol(r *http.Request) (*test.SequenceExecutionProtocol,
	error)

GetCurrentSequenceProtocol mocks getting the current sequence protocol

type SequenceSessionMock added in v1.1.0

SequenceSessionMock mocks the SequenceSession interface

func (*SequenceSessionMock) RemoveCurrentSequenceProtocol added in v1.1.0

func (sequenceSessionMock *SequenceSessionMock) RemoveCurrentSequenceProtocol(w http.ResponseWriter,
	r *http.Request) error

RemoveCurrentSequenceProtocol mocks removing the current sequence protocol from the session

type SequenceSessionSetterMock added in v1.1.0

type SequenceSessionSetterMock struct {
	CallerMock
	Err error
}

SequenceSessionSetterMock mocks the SequenceSessionSetter interface

func (*SequenceSessionSetterMock) SetCurrentSequenceProtocol added in v1.1.0

func (sequenceSessionSetterMock *SequenceSessionSetterMock) SetCurrentSequenceProtocol(w http.ResponseWriter,
	r *http.Request, protocol *test.SequenceExecutionProtocol) error

SetCurrentSequenceProtocol mocks setting the current sequence protocol

type SequenceUpdaterMock added in v1.0.0

type SequenceUpdaterMock struct {
	SequenceAdderMock
	SequenceRenamerMock
	SequenceDeletionMock
}

SequenceUpdaterMock mocks the SequenceUpdater

type TestCaseAdder added in v0.8.0

type TestCaseAdder interface {
	// Add stores a test case for the given project under the given container
	Add(testCase *test.Case) error
}

TestCaseAdder provides everything needed to add a testcase to a storage.

type TestCaseDeleter added in v0.8.0

type TestCaseDeleter interface {
	// Delete removes the test case with the given ID for the given project under the given container
	Delete(caseID id.TestID) error
}

TestCaseDeleter provides everything needed to remove a testcase to a storage.

type TestCaseGetter added in v0.8.0

type TestCaseGetter interface {
	// Get returns the test case with the given ID for the given project under the given container
	Get(caseID id.TestID) (*test.Case, bool, error)
}

TestCaseGetter is used to get testcases from the store.

type TestCaseLister added in v0.8.0

type TestCaseLister interface {
	// List returns a list of test cases for the given project under the given container
	List(projectID id.ProjectID) ([]*test.Case, error)
}

TestCaseLister is used to list all testcases for a specific project.

type TestCaseProtocolLister added in v0.10.0

type TestCaseProtocolLister interface {
	// GetCaseExecutionProtocols gets the protocols for the testcase with given id,
	// which is part of the project with given id.
	GetCaseExecutionProtocols(testCaseID id.TestID) ([]test.CaseExecutionProtocol, error)
}

TestCaseProtocolLister is used to list testcase execution protocols.

type TestCaseRenamer added in v1.0.0

type TestCaseRenamer interface {
	// Rename changes the name of a given test case to the new name
	Rename(old, new id.TestID) error
}

TestCaseRenamer provides a function for renaming a test case

type TestCaseUpdater added in v0.8.0

type TestCaseUpdater interface {
	TestCaseDeleter
	TestCaseAdder
	TestCaseRenamer
}

TestCaseUpdater contains every method needed to update a testcase.

type TestExistenceCheckerMock added in v1.0.0

type TestExistenceCheckerMock struct {
	CallerMock
	CaseID id.TestID
}

TestExistenceCheckerMock mocks the TestExistenceChecker

func (*TestExistenceCheckerMock) Exists added in v1.0.0

func (m *TestExistenceCheckerMock) Exists(id id.TestID) (bool, error)

Exists mocks checking for the existence of a test

type TestHandler

type TestHandler interface {
	// Name returned the name of the test.
	Name() string
	// Tested returns the handler that will be tested.
	Tested() http.HandlerFunc
	// Requests returns the request that will be send to the
	// handler during the test.
	Requests() []*http.Request
	// Checks returns a number of checks that need to be performed
	// on the response the handler gave during the test.
	Checks() []ResponseMatcher
	// SetUp prepared the test.
	SetUp()
}

TestHandler is a simple test for a handler.

func CreateTest added in v1.0.0

func CreateTest(name string, setUp TestSetUp, rs ...*http.Request) TestHandler

CreateTest is used to create a simple test for a handler.

type TestSequenceAdder added in v0.8.0

type TestSequenceAdder interface {
	// Add stores a test sequence for the given project under the given container
	Add(testSequence *test.Sequence) error
}

TestSequenceAdder is used to add testsequences to the storage.

type TestSequenceDeleter added in v0.8.0

type TestSequenceDeleter interface {
	// Delete removes the testsequence with the given ID for the given project under the given container
	Delete(sequenceID id.TestID) error
}

TestSequenceDeleter is used to delete testsequences from the storage.

type TestSequenceLister added in v0.8.0

type TestSequenceLister interface {
	// List returns a list of test sequences for the given project under the given container
	List(projectID id.ProjectID) ([]*test.Sequence, error)
}

TestSequenceLister is used to list all testsequences for a specific project.

type TestSequenceProtocolLister added in v0.10.0

type TestSequenceProtocolLister interface {
	// GetSequenceExecutionProtocols gets the protocols for the testsequence with given id,
	// which is part of the project with given id.
	GetSequenceExecutionProtocols(sequenceID id.TestID) ([]test.SequenceExecutionProtocol, error)
}

TestSequenceProtocolLister is used to list testsequence execution protocols.

type TestSequenceRenamer added in v1.0.0

type TestSequenceRenamer interface {
	// Rename changes the name of a given test sequence to the new name
	Rename(old, new id.TestID) error
}

TestSequenceRenamer provides a function for renaming a test case

type TestSequenceUpdater added in v0.8.0

type TestSequenceUpdater interface {
	TestSequenceAdder
	TestSequenceRenamer
	TestSequenceDeleter
}

TestSequenceUpdater is used to update testsequences in the storage.

type TestSetUp added in v1.0.0

type TestSetUp func() (http.HandlerFunc, []ResponseMatcher)

TestSetUp sets up a test by creating the tested handler and matchers that need to be fulfilled by the response the handler gives.

func ExpectResponse added in v1.0.0

func ExpectResponse(tested http.HandlerFunc, matchers ...ResponseMatcher) TestSetUp

ExpectResponse is a simple setup method that can be used if there is no shared data between the matchers and the handler itself.

type TimeSessionMock added in v1.1.0

type TimeSessionMock struct {
	CallerMock
	Duration *duration.Duration
	Err      error
}

TimeSessionMock mocks the TimeSession interface

func (*TimeSessionMock) GetDuration added in v1.1.0

func (tsm *TimeSessionMock) GetDuration(r *http.Request) (*duration.Duration, error)

GetDuration mocks getting the duration from the session

func (*TimeSessionMock) SetDuration added in v1.1.0

func (tsm *TimeSessionMock) SetDuration(w http.ResponseWriter, r *http.Request, duration *duration.Duration) error

SetDuration mocks setting the duration

type UserLister added in v0.8.0

type UserLister interface {
	// List returns a list of users in the system
	List() ([]*user.User, error)
}

UserLister is used to list all users in the system.

type UserListerMock added in v1.0.0

type UserListerMock struct {
	CallerMock
	Users []*user.User
	Err   error
}

UserListerMock mocks the UserLister

func (*UserListerMock) List added in v1.0.0

func (m *UserListerMock) List() ([]*user.User, error)

List mocks listing users

type UserRetrieverMock added in v1.1.0

type UserRetrieverMock struct {
	CallerMock
	User      *user.User
	UserFound bool
	Err       error
}

UserRetrieverMock mocks the UserRetriever interface

func (*UserRetrieverMock) Get added in v1.1.0

func (userRetrieverMock *UserRetrieverMock) Get(userID id.ActorID) (*user.User, bool, error)

Get mocks getting a user

Directories

Path Synopsis
Package assignment handles the assigning of tests to users.
Package assignment handles the assigning of tests to users.
Package creation contains the logic to create or add elements.
Package creation contains the logic to create or add elements.
Package deletion contains the logic for deleting or removing elements.
Package deletion contains the logic for deleting or removing elements.
Package display contains the logic for showing the templates for entities of the system, e.g.
Package display contains the logic for showing the templates for entities of the system, e.g.
Package duplication handles duplicating elements (e.g.
Package duplication handles duplicating elements (e.g.
Package execution handles the execution of cases and sequences.
Package execution handles the execution of cases and sequences.
Package json contains functions to serve and receive data as json.
Package json contains functions to serve and receive data as json.
Package list contains the logic for listing elements and everything that comes with listing, like filtering, sorting, etc.
Package list contains the logic for listing elements and everything that comes with listing, like filtering, sorting, etc.
Package printing contains the logic for printing elements of the system.
Package printing contains the logic for printing elements of the system.
Package update contains the logic for updating elements in the system (cases/sequences/projects...).
Package update contains the logic for updating elements in the system (cases/sequences/projects...).
Package usersession contains the logic for usersession handling.
Package usersession contains the logic for usersession handling.

Jump to

Keyboard shortcuts

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