Documentation ¶
Index ¶
- func GetCorrelationIDFromRequest(r *http.Request) string
- type App
- func (app *App) DispatchEvent(token string, corelationID string, topic string, payload interface{})
- func (app *App) GetConnectionString() string
- func (app *App) Initialize(routeSpecifiers []RouteSpecifier)
- func (app *App) Logger(module string) *zerolog.Logger
- func (app *App) MigrateDB()
- func (app *App) NewExecutionContext(uow *repository.UnitOfWork, token *security.JwtToken, correlationID string, ...) microappCtx.ExecutionContext
- func (app *App) NewExecutionContextWithCustomToken(uow *repository.UnitOfWork, tenantID uuid.UUID, userID uuid.UUID, ...) microappCtx.ExecutionContext
- func (app *App) NewExecutionContextWithSystemToken(uow *repository.UnitOfWork, correlationID string, action string) microappCtx.ExecutionContext
- func (app *App) NewUnitOfWork(readOnly bool) *repository.UnitOfWork
- func (app *App) Start()
- func (app *App) StartSecure(securityCert string, securityKey string)
- func (app *App) Stop()
- type RouteSpecifier
- type TestApp
- func (testApp *TestApp) AddAssociations(entity interface{}, associationName string, associations ...interface{}) error
- func (testApp *TestApp) AssertEqualWithFieldsToCheck(t *testing.T, expected interface{}, actual interface{}, fieldsToChk []string, ...)
- func (testApp *TestApp) AssertEqualWithFieldsToIgnore(t *testing.T, expected interface{}, actual interface{}, ...)
- func (testApp *TestApp) AssertErrorResponse(t *testing.T, response *httptest.ResponseRecorder, expectedErrorKey string, ...)
- func (testApp *TestApp) AssertXTotalCount(t *testing.T, response *httptest.ResponseRecorder, expectedXTotalCount int)
- func (testApp *TestApp) CallAPI(httpMethod string, apiURL string, token string, req interface{}) *httptest.ResponseRecorder
- func (testApp *TestApp) Check(t *testing.T, name string, expected, actual interface{}, failNow bool)
- func (testApp *TestApp) CheckResponseCode(t *testing.T, expected, actual int)
- func (testApp *TestApp) ExecuteRequest(req *http.Request) *httptest.ResponseRecorder
- func (testApp *TestApp) GetAdminToken(tenantID string, userID string, scope []string) string
- func (testApp *TestApp) GetAll(out interface{}, preloads []string, whereClause string, ...) error
- func (testApp *TestApp) GetByID(out interface{}, preloads []string, id string) error
- func (testApp *TestApp) GetFullAdminToken(tenantID string, userID string, username string, name string, ...) string
- func (testApp *TestApp) GetFullToken(tenantID string, userID string, username string, name string, ...) string
- func (testApp *TestApp) GetStandardAdminToken(tenantID string, userID string, username string, name string, scope []string) string
- func (testApp *TestApp) GetStandardToken(tenantID string, userID string, username string, name string, scope []string) string
- func (testApp *TestApp) GetToken(tenantID string, userID string, scope []string) string
- func (testApp *TestApp) Initialize()
- func (testApp *TestApp) PrepareEmptyTables()
- func (testApp *TestApp) SaveToDB(entity interface{}) error
- func (testApp *TestApp) SetControllerRouteProviderAndInitialize(controllerRouteProvider func(*App) []RouteSpecifier)
- func (testApp *TestApp) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCorrelationIDFromRequest ¶
GetCorrelationIDFromRequest returns correlationId from request header
Types ¶
type App ¶
type App struct { Name string Config *config.Config DB *gorm.DB Router *mux.Router // contains filtered or unexported fields }
App structure for tenant microservice
func New ¶
func New(appName string, appConfigDefaults map[string]interface{}, appLog zerolog.Logger, appDB *gorm.DB, appEventDispatcher event.Dispatcher) *App
New creates a new microApp
func NewWithEnvValues ¶
NewWithEnvValues creates a new application with environment variable values for initializing database, event dispatcher and logger.
func (*App) DispatchEvent ¶
DispatchEvent delegates to eventDispatcher.
func (*App) GetConnectionString ¶
GetConnectionString gets database connection string
func (*App) Initialize ¶
func (app *App) Initialize(routeSpecifiers []RouteSpecifier)
Initialize initializes properties of the app
func (*App) MigrateDB ¶
func (app *App) MigrateDB()
MigrateDB Looks for migrations directory and runs the migrations scripts in that directory
func (*App) NewExecutionContext ¶
func (app *App) NewExecutionContext(uow *repository.UnitOfWork, token *security.JwtToken, correlationID string, action string) microappCtx.ExecutionContext
NewExecutionContext creates new exectuion context
func (*App) NewExecutionContextWithCustomToken ¶
func (app *App) NewExecutionContextWithCustomToken(uow *repository.UnitOfWork, tenantID uuid.UUID, userID uuid.UUID, username string, correlationID string, action string) microappCtx.ExecutionContext
NewExecutionContextWithCustomToken creates new exectuion context with custom made token
func (*App) NewExecutionContextWithSystemToken ¶
func (app *App) NewExecutionContextWithSystemToken(uow *repository.UnitOfWork, correlationID string, action string) microappCtx.ExecutionContext
NewExecutionContextWithSystemToken creates new exectuion context with sys default token
func (*App) NewUnitOfWork ¶
func (app *App) NewUnitOfWork(readOnly bool) *repository.UnitOfWork
NewUnitOfWork creates new UnitOfWork
func (*App) StartSecure ¶
StartSecure starts https server and listens to the requests
type RouteSpecifier ¶
RouteSpecifier should be implemented by the class that sets routes for the API endpoints
type TestApp ¶
type TestApp struct {
// contains filtered or unexported fields
}
TestApp Provides convinience methods for test
func NewTestApp ¶
func NewTestApp(appName string, controllerRouteProvider func(*App) []RouteSpecifier, dbInitializer func(db *gorm.DB), verbose bool) *TestApp
NewTestApp returns new instance of TestApp
func (*TestApp) AddAssociations ¶
func (testApp *TestApp) AddAssociations(entity interface{}, associationName string, associations ...interface{}) error
AddAssociations adds associations to the given entity
func (*TestApp) AssertEqualWithFieldsToCheck ¶
func (testApp *TestApp) AssertEqualWithFieldsToCheck(t *testing.T, expected interface{}, actual interface{}, fieldsToChk []string, mapOfExpectedToActualField map[string]string)
AssertEqualWithFieldsToCheck asserts whether two objects are equal
func (*TestApp) AssertEqualWithFieldsToIgnore ¶
func (testApp *TestApp) AssertEqualWithFieldsToIgnore(t *testing.T, expected interface{}, actual interface{}, fieldsToIgnore []string, mapOfExpectedToActualField map[string]string)
AssertEqualWithFieldsToIgnore asserts whether two objects are equal
func (*TestApp) AssertErrorResponse ¶
func (testApp *TestApp) AssertErrorResponse(t *testing.T, response *httptest.ResponseRecorder, expectedErrorKey string, expectedErrorField string, expectedError string)
AssertErrorResponse checks if the http response contains expected errorKey, errorField and errorMessage
func (*TestApp) AssertXTotalCount ¶
func (testApp *TestApp) AssertXTotalCount(t *testing.T, response *httptest.ResponseRecorder, expectedXTotalCount int)
AssertXTotalCount checks if the http response header contains expected x-total-count
func (*TestApp) CallAPI ¶
func (testApp *TestApp) CallAPI(httpMethod string, apiURL string, token string, req interface{}) *httptest.ResponseRecorder
CallAPI invokes http API
func (*TestApp) Check ¶
func (testApp *TestApp) Check(t *testing.T, name string, expected, actual interface{}, failNow bool)
Check checks whether the expected and actual value matches
func (*TestApp) CheckResponseCode ¶
CheckResponseCode checks if the http response is as expected
func (*TestApp) ExecuteRequest ¶
func (testApp *TestApp) ExecuteRequest(req *http.Request) *httptest.ResponseRecorder
ExecuteRequest executes the http request
func (*TestApp) GetAdminToken ¶
GetAdminToken returns a test token
func (*TestApp) GetAll ¶
func (testApp *TestApp) GetAll(out interface{}, preloads []string, whereClause string, whereParams []interface{}, orderBy string) error
GetAll gets all from DB
func (*TestApp) GetFullAdminToken ¶
func (testApp *TestApp) GetFullAdminToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string) string
GetFullAdminToken returns a test token with all the fields along with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.
func (*TestApp) GetFullToken ¶
func (testApp *TestApp) GetFullToken(tenantID string, userID string, username string, name string, externalID string, externalIDType string, scope []string) string
GetFullToken returns a test token with all the fields along with different external IDs for types such as Appliance, Session, User. These external IDs are used with REST api is invoked from another REST API service as opposed to the getting hit from UI by the user.
func (*TestApp) GetStandardAdminToken ¶
func (testApp *TestApp) GetStandardAdminToken(tenantID string, userID string, username string, name string, scope []string) string
GetStandardAdminToken returns a test admin token with all standard fields.
func (*TestApp) GetStandardToken ¶
func (testApp *TestApp) GetStandardToken(tenantID string, userID string, username string, name string, scope []string) string
GetStandardToken returns a test token with all standard fields
func (*TestApp) Initialize ¶
func (testApp *TestApp) Initialize()
Initialize prepares the app for testing
func (*TestApp) PrepareEmptyTables ¶
func (testApp *TestApp) PrepareEmptyTables()
PrepareEmptyTables clears all table of data
func (*TestApp) SetControllerRouteProviderAndInitialize ¶
func (testApp *TestApp) SetControllerRouteProviderAndInitialize(controllerRouteProvider func(*App) []RouteSpecifier)
SetControllerRouteProviderAndInitialize sets the controllerRouteProvider and initializes application