vit

package
v1.202405300917.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestEmail       = "123@123.com"
	TestEmail2      = "124@124.com"
	TestServicePort = 10000

	App1PkgPath = "github.com/voedger/voedger/pkg/vit/app1pkg"
)

Variables

View Source
var (
	DefaultTestTime = time.UnixMilli(testTimeMillis) // 2022-04-11 11:54:46 +0300 MSK
	//go:embed schemaTestApp1.vsql
	SchemaTestApp1FS embed.FS
	//go:embed schemaTestApp2.vsql
	SchemaTestApp2FS embed.FS

	DefaultTestAppEnginesPool = appparts.PoolSize(10, 10, 20)

	TestAppDeploymentDescriptor = appparts.AppDeploymentDescriptor{
		NumParts:         10,
		EnginePoolSize:   DefaultTestAppEnginesPool,
		NumAppWorkspaces: istructs.DefaultNumAppWorkspaces,
	}
)
View Source
var (
	QNameApp1_TestWSKind                     = appdef.NewQName(app1PkgName, "test_ws")
	QNameApp1_TestWSKind_another             = appdef.NewQName(app1PkgName, "test_ws_another")
	QNameTestView                            = appdef.NewQName(app1PkgName, "View")
	QNameApp1_TestEmailVerificationDoc       = appdef.NewQName(app1PkgName, "Doc")
	QNameApp1_DocConstraints                 = appdef.NewQName(app1PkgName, "DocConstraints")
	QNameApp1_DocConstraintsString           = appdef.NewQName(app1PkgName, "DocConstraintsString")
	QNameApp1_DocConstraintsFewUniques       = appdef.NewQName(app1PkgName, "DocConstraintsFewUniques")
	QNameApp1_DocConstraintsOldAndNewUniques = appdef.NewQName(app1PkgName, "DocConstraintsOldAndNewUniques")
	QNameApp1_CDocCategory                   = appdef.NewQName(app1PkgName, "category")
	QNameCmdRated                            = appdef.NewQName(app1PkgName, "RatedCmd")
	QNameQryRated                            = appdef.NewQName(app1PkgName, "RatedQry")
	QNameODoc1                               = appdef.NewQName(app1PkgName, "odoc1")
	QNameODoc2                               = appdef.NewQName(app1PkgName, "odoc2")
	TestSMTPCfg                              = smtp.Cfg{
		Username: "username@gmail.com",
	}

	// BLOBMaxSize 5
	SharedConfig_App1 = NewSharedVITConfig(
		WithApp(istructs.AppQName_test1_app1, ProvideApp1,
			WithWorkspaceTemplate(QNameApp1_TestWSKind, "test_template", sys_test_template.TestTemplateFS),
			WithUserLogin("login", "pwd"),
			WithUserLogin(TestEmail, "1"),
			WithUserLogin(TestEmail2, "1"),
			WithChildWorkspace(QNameApp1_TestWSKind, "test_ws", "test_template", "", "login", map[string]interface{}{"IntFld": 42},
				WithChild(QNameApp1_TestWSKind, "test_ws2", "test_template", "", "login", map[string]interface{}{"IntFld": 42},
					WithSubject(TestEmail, istructs.SubjectKind_User, []appdef.QName{iauthnz.QNameRoleWorkspaceOwner}))),
			WithChildWorkspace(QNameApp1_TestWSKind_another, "test_ws_another", "", "", "login", map[string]interface{}{}),
		),
		WithApp(istructs.AppQName_test1_app2, ProvideApp2, WithUserLogin("login", "1")),
		WithVVMConfig(func(cfg *vvm.VVMConfig) {

			cfg.Routes["/grafana"] = fmt.Sprintf("http://127.0.0.1:%d", TestServicePort)
			cfg.RoutesRewrite["/grafana-rewrite"] = fmt.Sprintf("http://127.0.0.1:%d/rewritten", TestServicePort)
			cfg.RouteDefault = fmt.Sprintf("http://127.0.0.1:%d/not-found", TestServicePort)
			cfg.RouteDomains["localhost"] = fmt.Sprintf("http://127.0.0.1:%d", TestServicePort)

			const app1_BLOBMaxSize = 5
			cfg.BLOBMaxSize = app1_BLOBMaxSize
		}),
		WithCleanup(func(_ *VIT) {
			MockCmdExec = func(input string, args istructs.ExecCommandArgs) error { panic("") }
			MockQryExec = func(input string, callback istructs.ExecQueryCallback) error { panic("") }
		}),
	)
	MockQryExec func(input string, callback istructs.ExecQueryCallback) error
	MockCmdExec func(input string, args istructs.ExecCommandArgs) error
)

Functions

func DoNotFailOnTimeout

func DoNotFailOnTimeout() signInOptFunc

func TestDeadline

func TestDeadline() time.Time

func TestRestartPreservingStorage

func TestRestartPreservingStorage(t *testing.T, cfg *VITConfig, testBeforeRestart, testAfterRestart func(t *testing.T, vit *VIT))

calls testBeforeRestart() then stops then VIT, then launches new VIT on the same config but with storage from previous VIT then calls testAfterRestart() with the new VIT cfg must be owned

func WithApp

func WithApp(appQName istructs.AppQName, updater apps.AppBuilder, appOpts ...AppOptFunc) vitConfigOptFunc

func WithCleanup

func WithCleanup(cleanup func(*VIT)) vitConfigOptFunc

func WithClusterID

func WithClusterID(clusterID istructs.ClusterID) signUpOptFunc

func WithInit

func WithInit(initFunc func()) vitConfigOptFunc

func WithPostInit

func WithPostInit(postInitFunc func(vit *VIT)) vitConfigOptFunc

func WithReqOpt

func WithReqOpt(reqOpt coreutils.ReqOptFunc) signUpOptFunc

func WithVVMConfig

func WithVVMConfig(configurer func(cfg *vvm.VVMConfig)) vitConfigOptFunc

Types

type AppOptFunc

type AppOptFunc func(app *app, cfg *vvm.VVMConfig)

func WithBuilder

func WithBuilder(builder apps.AppBuilder) AppOptFunc

func WithChildWorkspace

func WithChildWorkspace(wsKind appdef.QName, name, templateName string, templateParams string, ownerLoginName string, wsInitData map[string]interface{}, opts ...PostConstructFunc) AppOptFunc

func WithUserLogin

func WithUserLogin(name, pwd string, opts ...PostConstructFunc) AppOptFunc

at MainCluster

func WithVerifiedValue

func WithVerifiedValue(docQName appdef.QName, fieldName string, desiredValue string) AppOptFunc

func WithWorkspaceTemplate

func WithWorkspaceTemplate(wsKind appdef.QName, templateName string, templateFS coreutils.EmbedFS) AppOptFunc

type AppWorkspace

type AppWorkspace struct {
	WorkspaceDescriptor
	Owner *Principal // потому что токены принципала обновляются, когда меняется время
}

func DummyWS

func DummyWS(wsKind appdef.QName, wsid istructs.WSID, ownerPrn *Principal) *AppWorkspace

func (*AppWorkspace) AppQName

func (a *AppWorkspace) AppQName() istructs.AppQName

type BLOB

type BLOB struct {
	Content  []byte
	Name     string
	MimeType string
}

type Login

type Login struct {
	Name, Pwd         string
	PseudoProfileWSID istructs.WSID
	AppQName          istructs.AppQName
	// contains filtered or unexported fields
}

func NewLogin

func NewLogin(name, pwd string, appQName istructs.AppQName, subjectKind istructs.SubjectKindType, clusterID istructs.ClusterID) Login

type PostConstructFunc

type PostConstructFunc func(intf interface{})

func WithChild

func WithChild(wsKind appdef.QName, name, templateName string, templateParams string, ownerLoginName string, wsInitData map[string]interface{}, opts ...PostConstructFunc) PostConstructFunc

func WithDoc

func WithDoc(name appdef.QName, data map[string]interface{}) PostConstructFunc

func WithDocWithVerifiedFields

func WithDocWithVerifiedFields(name appdef.QName, dataFactory func(verifiedValues map[string]string) map[string]interface{}) PostConstructFunc

func WithSubject

func WithSubject(login string, subjectKind istructs.SubjectKindType, roles []appdef.QName) PostConstructFunc

type Principal

type Principal struct {
	Login
	Token       string
	ProfileWSID istructs.WSID
}

func (*Principal) GetAppQName

func (p *Principal) GetAppQName() istructs.AppQName

func (*Principal) GetWSID

func (p *Principal) GetWSID() istructs.WSID

type VIT

type VIT struct {
	T testing.TB
	*vvm.VoedgerVM
	*vvm.VVMConfig
	// contains filtered or unexported fields
}

Voedger Integration Test

func NewVIT

func NewVIT(t testing.TB, vitCfg *VITConfig, opts ...vitOptFunc) (vit *VIT)

func NewVITLocalCassandra

func NewVITLocalCassandra(tb testing.TB, vitCfg *VITConfig, opts ...vitOptFunc) (vit *VIT)

func (*VIT) CaptureEmail

func (vit *VIT) CaptureEmail() (msg smtptest.Message)

CaptureEmail waits for and returns the next sent email no emails during testEmailsAwaitingTimeout -> test failed an email was sent but CaptureEmail is not called -> test will be failed on VIT.TearDown()

func (*VIT) CreateWorkspace

func (vit *VIT) CreateWorkspace(wsp WSParams, owner *Principal, opts ...coreutils.ReqOptFunc) *AppWorkspace

func (*VIT) Func

func (vit *VIT) Func(url string, body string, opts ...coreutils.ReqOptFunc) *coreutils.FuncResponse

func (*VIT) GetAny

func (vit *VIT) GetAny(entity string, ws *AppWorkspace) istructs.RecordID

func (*VIT) GetBLOB

func (vit *VIT) GetBLOB(appQName istructs.AppQName, wsid istructs.WSID, blobID istructs.RecordID, token string) *BLOB

func (*VIT) GetCDocChildWorkspace

func (vit *VIT) GetCDocChildWorkspace(ws *AppWorkspace) (cdoc map[string]interface{}, id int64)

func (*VIT) GetCDocLoginID

func (vit *VIT) GetCDocLoginID(login Login) int64

func (*VIT) GetCDocWSKind

func (vit *VIT) GetCDocWSKind(ws *AppWorkspace) (cdoc map[string]interface{}, id int64)

func (*VIT) GetPrincipal

func (vit *VIT) GetPrincipal(appQName istructs.AppQName, login string) *Principal

func (*VIT) GetSystemPrincipal

func (vit *VIT) GetSystemPrincipal(appQName istructs.AppQName) *Principal

func (*VIT) InitChildWorkspace

func (vit *VIT) InitChildWorkspace(wsd WSParams, ownerIntf interface{}, opts ...coreutils.ReqOptFunc)

owner could be *vit.Principal or *vit.AppWorkspace

func (*VIT) MetricsRequest

func (vit *VIT) MetricsRequest(client coreutils.IHTTPClient, opts ...coreutils.ReqOptFunc) (resp string)

func (*VIT) MetricsServicePort

func (vit *VIT) MetricsServicePort() int

func (*VIT) MockBuckets

func (vit *VIT) MockBuckets(appQName istructs.AppQName, rateLimitName string, bs irates.BucketState)

sets `bs` as state of Buckets for `rateLimitName` in `appQName` will be automatically restored on vit.TearDown() to the state the Bucket was before MockBuckets() call

func (*VIT) NextName

func (vit *VIT) NextName() string

func (*VIT) NextNumber

func (vit *VIT) NextNumber() int

func (*VIT) Now

func (vit *VIT) Now() time.Time

func (*VIT) POST

func (vit *VIT) POST(relativeURL string, body string, opts ...coreutils.ReqOptFunc) *coreutils.HTTPResponse

func (*VIT) PostApp

func (vit *VIT) PostApp(appQName istructs.AppQName, wsid istructs.WSID, funcName string, body string, opts ...coreutils.ReqOptFunc) *coreutils.FuncResponse

func (*VIT) PostProfile

func (vit *VIT) PostProfile(prn *Principal, funcName string, body string, opts ...coreutils.ReqOptFunc) *coreutils.FuncResponse

func (*VIT) PostWS

func (vit *VIT) PostWS(ws *AppWorkspace, funcName string, body string, opts ...coreutils.ReqOptFunc) *coreutils.FuncResponse

func (*VIT) PostWSSys

func (vit *VIT) PostWSSys(ws *AppWorkspace, funcName string, body string, opts ...coreutils.ReqOptFunc) *coreutils.FuncResponse

PostWSSys is PostWS authorized by the System Token

func (*VIT) ReadBLOB

func (vit *VIT) ReadBLOB(appQName istructs.AppQName, wsid istructs.WSID, blobID istructs.RecordID, optFuncs ...coreutils.ReqOptFunc) *coreutils.HTTPResponse

func (*VIT) Restart

func (vit *VIT) Restart()

func (*VIT) SetMemStorageGetDelay

func (vit *VIT) SetMemStorageGetDelay(delay time.Duration)

sets delay on IAppStorage.Get() in mem implementation will be automatically reset to 0 on TearDown

func (*VIT) SetMemStoragePutDelay

func (vit *VIT) SetMemStoragePutDelay(delay time.Duration)

sets delay on IAppStorage.Put() in mem implementation will be automatically reset to 0 on TearDown

func (*VIT) SetNow

func (vit *VIT) SetNow(now time.Time)

func (*VIT) SignIn

func (vit *VIT) SignIn(login Login, optFuncs ...signInOptFunc) (prn *Principal)

func (*VIT) SignUp

func (vit *VIT) SignUp(loginName, pwd string, appQName istructs.AppQName, opts ...signUpOptFunc) Login

func (*VIT) SignUpDevice

func (vit *VIT) SignUpDevice(loginName, pwd string, appQName istructs.AppQName, opts ...signUpOptFunc) Login

func (*VIT) SubscribeForN10n

func (vit *VIT) SubscribeForN10n(ws *AppWorkspace, projectionQName appdef.QName) federation.OffsetsChan

func (*VIT) SubscribeForN10nProjectionKey

func (vit *VIT) SubscribeForN10nProjectionKey(pk in10n.ProjectionKey) federation.OffsetsChan

will be unsubscribed automatically on vit.TearDown()

func (*VIT) SubscribeForN10nUnsubscribe

func (vit *VIT) SubscribeForN10nUnsubscribe(pk in10n.ProjectionKey) (offsetsChan federation.OffsetsChan, unsubscribe func())

func (*VIT) TearDown

func (vit *VIT) TearDown()

func (*VIT) TimeAdd

func (vit *VIT) TimeAdd(dur time.Duration)

func (*VIT) UploadBLOB

func (vit *VIT) UploadBLOB(appQName istructs.AppQName, wsid istructs.WSID, blobName string, blobMimeType string, blobContent []byte,
	opts ...coreutils.ReqOptFunc) (blobID istructs.RecordID)

func (*VIT) UploadBLOBs

func (vit *VIT) UploadBLOBs(appQName istructs.AppQName, wsid istructs.WSID, blobs []coreutils.BLOB, opts ...coreutils.ReqOptFunc) (blobIDs []istructs.RecordID)

func (*VIT) WS

func (vit *VIT) WS(appQName istructs.AppQName, wsName string) *AppWorkspace

func (*VIT) WaitFor

func (vit *VIT) WaitFor(consumer func() *coreutils.FuncResponse) *coreutils.FuncResponse

func (*VIT) WaitForChildWorkspace

func (vit *VIT) WaitForChildWorkspace(parentWS *AppWorkspace, wsName string) (ws *AppWorkspace)

func (*VIT) WaitForWorkspace

func (vit *VIT) WaitForWorkspace(wsName string, owner *Principal) (ws *AppWorkspace)

type VITConfig

type VITConfig struct {
	// contains filtered or unexported fields
}

func NewOwnVITConfig

func NewOwnVITConfig(opts ...vitConfigOptFunc) VITConfig

func NewSharedVITConfig

func NewSharedVITConfig(opts ...vitConfigOptFunc) VITConfig

type WSParams

type WSParams struct {
	Name           string
	TemplateName   string
	TemplateParams string
	Kind           appdef.QName
	InitDataJSON   string

	ClusterID istructs.ClusterID
	// contains filtered or unexported fields
}

func SimpleWSParams

func SimpleWSParams(wsName string) WSParams

type WorkspaceDescriptor

type WorkspaceDescriptor struct {
	WSParams
	WSID    istructs.WSID
	WSError string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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