api

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2022 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataLookupHandlerFunc added in v1.0.0

func DataLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.HandlerFunc

DataLookupHandlerFunc returns a http handler function handling search api requests.

func SearchHandlerFunc

func SearchHandlerFunc(queryBuilder QueryBuilder, elasticSearchClient ElasticSearcher, transformer ResponseTransformer) http.HandlerFunc

SearchHandlerFunc returns a http handler function handling search api requests.

func SearchReleasesHandlerFunc

func SearchReleasesHandlerFunc(validator QueryParamValidator, builder ReleaseQueryBuilder, searcher ElasticSearcher, transformer ResponseTransformer) http.HandlerFunc

SearchReleasesHandlerFunc returns a http handler function handling release calendar search api requests.

func SetupData added in v1.0.0

func SetupData() error

SetupData loads templates for use by the timeseries lookup handler and should be done only once

func SetupTimeseries added in v1.0.0

func SetupTimeseries() error

SetupTimeseries loads templates for use by the timeseries lookup handler and should be done only once

func TimeseriesLookupHandlerFunc added in v1.0.0

func TimeseriesLookupHandlerFunc(elasticSearchClient ElasticSearcher) http.HandlerFunc

TimeseriesLookupHandlerFunc returns a http handler function handling search api requests.

Types

type AuthHandler

type AuthHandler interface {
	Require(required auth.Permissions, handler http.HandlerFunc) http.HandlerFunc
}

AuthHandler provides authorisation checks on requests

type AuthHandlerMock

type AuthHandlerMock struct {
	// RequireFunc mocks the Require method.
	RequireFunc func(required auth.Permissions, handler http.HandlerFunc) http.HandlerFunc
	// contains filtered or unexported fields
}

AuthHandlerMock is a mock implementation of AuthHandler.

func TestSomethingThatUsesAuthHandler(t *testing.T) {

	// make and configure a mocked AuthHandler
	mockedAuthHandler := &AuthHandlerMock{
		RequireFunc: func(required auth.Permissions, handler http.HandlerFunc) http.HandlerFunc {
			panic("mock out the Require method")
		},
	}

	// use mockedAuthHandler in code that requires AuthHandler
	// and then make assertions.

}

func (*AuthHandlerMock) Require

func (mock *AuthHandlerMock) Require(required auth.Permissions, handler http.HandlerFunc) http.HandlerFunc

Require calls RequireFunc.

func (*AuthHandlerMock) RequireCalls

func (mock *AuthHandlerMock) RequireCalls() []struct {
	Required auth.Permissions
	Handler  http.HandlerFunc
}

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

len(mockedAuthHandler.RequireCalls())

type CreateIndexResponse

type CreateIndexResponse struct {
	IndexName string
}

type DpElasticSearcher

type DpElasticSearcher interface {
	CreateIndex(ctx context.Context, indexName string, indexSettings []byte) error
}

DpElasticSearcher provides an interface for the dp-elasticsearch functionality

type DpElasticSearcherMock

type DpElasticSearcherMock struct {
	// CreateIndexFunc mocks the CreateIndex method.
	CreateIndexFunc func(ctx context.Context, indexName string, indexSettings []byte) error
	// contains filtered or unexported fields
}

DpElasticSearcherMock is a mock implementation of DpElasticSearcher.

func TestSomethingThatUsesDpElasticSearcher(t *testing.T) {

	// make and configure a mocked DpElasticSearcher
	mockedDpElasticSearcher := &DpElasticSearcherMock{
		CreateIndexFunc: func(ctx context.Context, indexName string, indexSettings []byte) error {
			panic("mock out the CreateIndex method")
		},
	}

	// use mockedDpElasticSearcher in code that requires DpElasticSearcher
	// and then make assertions.

}

func (*DpElasticSearcherMock) CreateIndex

func (mock *DpElasticSearcherMock) CreateIndex(ctx context.Context, indexName string, indexSettings []byte) error

CreateIndex calls CreateIndexFunc.

func (*DpElasticSearcherMock) CreateIndexCalls

func (mock *DpElasticSearcherMock) CreateIndexCalls() []struct {
	Ctx           context.Context
	IndexName     string
	IndexSettings []byte
}

CreateIndexCalls gets all the calls that were made to CreateIndex. Check the length with:

len(mockedDpElasticSearcher.CreateIndexCalls())

type ElasticSearcher

type ElasticSearcher interface {
	Search(ctx context.Context, index string, docType string, request []byte) ([]byte, error)
	MultiSearch(ctx context.Context, index string, docType string, request []byte) ([]byte, error)
}

ElasticSearcher provides client methods for the elasticsearch package - now deprecated, due to be replaced with the methods in dp-elasticsearch

type ElasticSearcherMock

type ElasticSearcherMock struct {
	// MultiSearchFunc mocks the MultiSearch method.
	MultiSearchFunc func(ctx context.Context, index string, docType string, request []byte) ([]byte, error)

	// SearchFunc mocks the Search method.
	SearchFunc func(ctx context.Context, index string, docType string, request []byte) ([]byte, error)
	// contains filtered or unexported fields
}

ElasticSearcherMock is a mock implementation of ElasticSearcher.

func TestSomethingThatUsesElasticSearcher(t *testing.T) {

	// make and configure a mocked ElasticSearcher
	mockedElasticSearcher := &ElasticSearcherMock{
		MultiSearchFunc: func(ctx context.Context, index string, docType string, request []byte) ([]byte, error) {
			panic("mock out the MultiSearch method")
		},
		SearchFunc: func(ctx context.Context, index string, docType string, request []byte) ([]byte, error) {
			panic("mock out the Search method")
		},
	}

	// use mockedElasticSearcher in code that requires ElasticSearcher
	// and then make assertions.

}

func (*ElasticSearcherMock) MultiSearch

func (mock *ElasticSearcherMock) MultiSearch(ctx context.Context, index string, docType string, request []byte) ([]byte, error)

MultiSearch calls MultiSearchFunc.

func (*ElasticSearcherMock) MultiSearchCalls

func (mock *ElasticSearcherMock) MultiSearchCalls() []struct {
	Ctx     context.Context
	Index   string
	DocType string
	Request []byte
}

MultiSearchCalls gets all the calls that were made to MultiSearch. Check the length with:

len(mockedElasticSearcher.MultiSearchCalls())

func (*ElasticSearcherMock) Search

func (mock *ElasticSearcherMock) Search(ctx context.Context, index string, docType string, request []byte) ([]byte, error)

Search calls SearchFunc.

func (*ElasticSearcherMock) SearchCalls

func (mock *ElasticSearcherMock) SearchCalls() []struct {
	Ctx     context.Context
	Index   string
	DocType string
	Request []byte
}

SearchCalls gets all the calls that were made to Search. Check the length with:

len(mockedElasticSearcher.SearchCalls())

type QueryBuilder

type QueryBuilder interface {
	BuildSearchQuery(ctx context.Context, q, contentTypes, sort string, topics []string, limit, offset int) ([]byte, error)
}

QueryBuilder provides methods for the search package

type QueryBuilderMock

type QueryBuilderMock struct {
	// BuildSearchQueryFunc mocks the BuildSearchQuery method.
	BuildSearchQueryFunc func(ctx context.Context, q string, contentTypes string, sort string, topics []string, limit int, offset int) ([]byte, error)
	// contains filtered or unexported fields
}

QueryBuilderMock is a mock implementation of QueryBuilder.

func TestSomethingThatUsesQueryBuilder(t *testing.T) {

	// make and configure a mocked QueryBuilder
	mockedQueryBuilder := &QueryBuilderMock{
		BuildSearchQueryFunc: func(ctx context.Context, q string, contentTypes string, sort string, topics []string, limit int, offset int) ([]byte, error) {
			panic("mock out the BuildSearchQuery method")
		},
	}

	// use mockedQueryBuilder in code that requires QueryBuilder
	// and then make assertions.

}

func (*QueryBuilderMock) BuildSearchQuery

func (mock *QueryBuilderMock) BuildSearchQuery(ctx context.Context, q string, contentTypes string, sort string, topics []string, limit int, offset int) ([]byte, error)

BuildSearchQuery calls BuildSearchQueryFunc.

func (*QueryBuilderMock) BuildSearchQueryCalls

func (mock *QueryBuilderMock) BuildSearchQueryCalls() []struct {
	Ctx          context.Context
	Q            string
	ContentTypes string
	Sort         string
	Topics       []string
	Limit        int
	Offset       int
}

BuildSearchQueryCalls gets all the calls that were made to BuildSearchQuery. Check the length with:

len(mockedQueryBuilder.BuildSearchQueryCalls())

type QueryParamValidator

type QueryParamValidator interface {
	Validate(ctx context.Context, name, value string) (interface{}, error)
}

QueryParamValidator provides an interface to validate api query parameters (used for /search/releases)

type QueryParamValidatorMock

type QueryParamValidatorMock struct {
	// ValidateFunc mocks the Validate method.
	ValidateFunc func(ctx context.Context, name string, value string) (interface{}, error)
	// contains filtered or unexported fields
}

QueryParamValidatorMock is a mock implementation of QueryParamValidator.

func TestSomethingThatUsesQueryParamValidator(t *testing.T) {

	// make and configure a mocked QueryParamValidator
	mockedQueryParamValidator := &QueryParamValidatorMock{
		ValidateFunc: func(ctx context.Context, name string, value string) (interface{}, error) {
			panic("mock out the Validate method")
		},
	}

	// use mockedQueryParamValidator in code that requires QueryParamValidator
	// and then make assertions.

}

func (*QueryParamValidatorMock) Validate

func (mock *QueryParamValidatorMock) Validate(ctx context.Context, name string, value string) (interface{}, error)

Validate calls ValidateFunc.

func (*QueryParamValidatorMock) ValidateCalls

func (mock *QueryParamValidatorMock) ValidateCalls() []struct {
	Ctx   context.Context
	Name  string
	Value string
}

ValidateCalls gets all the calls that were made to Validate. Check the length with:

len(mockedQueryParamValidator.ValidateCalls())

type ReleaseQueryBuilder

type ReleaseQueryBuilder interface {
	BuildSearchQuery(ctx context.Context, request query.ReleaseSearchRequest) ([]byte, error)
}

ReleaseQueryBuilder provides an interface to build a search query for the Release content type

type ReleaseQueryBuilderMock

type ReleaseQueryBuilderMock struct {
	// BuildSearchQueryFunc mocks the BuildSearchQuery method.
	BuildSearchQueryFunc func(ctx context.Context, request query.ReleaseSearchRequest) ([]byte, error)
	// contains filtered or unexported fields
}

ReleaseQueryBuilderMock is a mock implementation of ReleaseQueryBuilder.

func TestSomethingThatUsesReleaseQueryBuilder(t *testing.T) {

	// make and configure a mocked ReleaseQueryBuilder
	mockedReleaseQueryBuilder := &ReleaseQueryBuilderMock{
		BuildSearchQueryFunc: func(ctx context.Context, request query.ReleaseSearchRequest) ([]byte, error) {
			panic("mock out the BuildSearchQuery method")
		},
	}

	// use mockedReleaseQueryBuilder in code that requires ReleaseQueryBuilder
	// and then make assertions.

}

func (*ReleaseQueryBuilderMock) BuildSearchQuery

func (mock *ReleaseQueryBuilderMock) BuildSearchQuery(ctx context.Context, request query.ReleaseSearchRequest) ([]byte, error)

BuildSearchQuery calls BuildSearchQueryFunc.

func (*ReleaseQueryBuilderMock) BuildSearchQueryCalls

func (mock *ReleaseQueryBuilderMock) BuildSearchQueryCalls() []struct {
	Ctx     context.Context
	Request query.ReleaseSearchRequest
}

BuildSearchQueryCalls gets all the calls that were made to BuildSearchQuery. Check the length with:

len(mockedReleaseQueryBuilder.BuildSearchQueryCalls())

type ResponseTransformer

type ResponseTransformer interface {
	TransformSearchResponse(ctx context.Context, responseData []byte, query string, highlight bool) ([]byte, error)
}

ResponseTransformer provides methods for the transform package

type ResponseTransformerMock

type ResponseTransformerMock struct {
	// TransformSearchResponseFunc mocks the TransformSearchResponse method.
	TransformSearchResponseFunc func(ctx context.Context, responseData []byte, queryMoqParam string, highlight bool) ([]byte, error)
	// contains filtered or unexported fields
}

ResponseTransformerMock is a mock implementation of ResponseTransformer.

func TestSomethingThatUsesResponseTransformer(t *testing.T) {

	// make and configure a mocked ResponseTransformer
	mockedResponseTransformer := &ResponseTransformerMock{
		TransformSearchResponseFunc: func(ctx context.Context, responseData []byte, queryMoqParam string, highlight bool) ([]byte, error) {
			panic("mock out the TransformSearchResponse method")
		},
	}

	// use mockedResponseTransformer in code that requires ResponseTransformer
	// and then make assertions.

}

func (*ResponseTransformerMock) TransformSearchResponse

func (mock *ResponseTransformerMock) TransformSearchResponse(ctx context.Context, responseData []byte, queryMoqParam string, highlight bool) ([]byte, error)

TransformSearchResponse calls TransformSearchResponseFunc.

func (*ResponseTransformerMock) TransformSearchResponseCalls

func (mock *ResponseTransformerMock) TransformSearchResponseCalls() []struct {
	Ctx           context.Context
	ResponseData  []byte
	QueryMoqParam string
	Highlight     bool
}

TransformSearchResponseCalls gets all the calls that were made to TransformSearchResponse. Check the length with:

len(mockedResponseTransformer.TransformSearchResponseCalls())

type SearchAPI

type SearchAPI struct {
	Router       *mux.Router
	QueryBuilder QueryBuilder

	Transformer ResponseTransformer
	// contains filtered or unexported fields
}

SearchAPI provides an API around elasticseach

func NewSearchAPI

func NewSearchAPI(router *mux.Router, dpESClient DpElasticSearcher, deprecatedESClient ElasticSearcher, queryBuilder QueryBuilder, transformer ResponseTransformer, permissions AuthHandler) (*SearchAPI, error)

NewSearchAPI returns a new Search API struct after registering the routes

func (*SearchAPI) AddSearchReleaseAPI

func (a *SearchAPI) AddSearchReleaseAPI(validator QueryParamValidator, builder ReleaseQueryBuilder, searcher ElasticSearcher, transformer ResponseTransformer) *SearchAPI

func (SearchAPI) CreateSearchIndexHandlerFunc

func (a SearchAPI) CreateSearchIndexHandlerFunc(w http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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