{"modulePath":"github.com/newstack-cloud/deploy-cli-sdk","version":"v0.10.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package testutils\n\n## Functions\n\n```go\nfunc InstanceCreatesFromEngine(eng engine.DeployEngine) int\n```\nInstanceCreatesFromEngine returns how many times CreateBlueprintInstance was called on the test engine. Returns 0 if the engine is not a test engine.\n\n```go\nfunc InstanceUpdatesFromEngine(eng engine.DeployEngine) []string\n```\nInstanceUpdatesFromEngine returns the instance IDs UpdateBlueprintInstance was called with on the test engine, in order. Returns nil if the engine is not a test engine.\n\n```go\nfunc Key(model *teatest.TestModel, key string)\n```\nKey is a generic helper function to send any single key message to the model.\n\n```go\nfunc KeyBackspace(model *teatest.TestModel)\n```\nKeyBackspace is a helper function to send a backspace key message to the model.\n\n```go\nfunc KeyDown(model *teatest.TestModel)\n```\nKeyDown is a helper function to send a key down message to the model.\n\n```go\nfunc KeyEnd(model *teatest.TestModel)\n```\nKeyEnd is a helper function to send an end key message to the model.\n\n```go\nfunc KeyEnter(model *teatest.TestModel)\n```\nKeyEnter is a helper function to send a key enter message to the model.\n\n```go\nfunc KeyEscape(model *teatest.TestModel)\n```\nKeyEscape is a helper function to send an escape key message to the model.\n\n```go\nfunc KeyHome(model *teatest.TestModel)\n```\nKeyHome is a helper function to send a home key message to the model.\n\n```go\nfunc KeyJ(model *teatest.TestModel)\n```\nKeyJ is a helper function to send a 'j' key message to the model (vim down).\n\n```go\nfunc KeyK(model *teatest.TestModel)\n```\nKeyK is a helper function to send a 'k' key message to the model (vim up).\n\n```go\nfunc KeyLeft(model *teatest.TestModel)\n```\nKeyLeft is a helper function to send a key left message to the model.\n\n```go\nfunc KeyPageDown(model *teatest.TestModel)\n```\nKeyPageDown is a helper function to send a page down key message to the model.\n\n```go\nfunc KeyPageUp(model *teatest.TestModel)\n```\nKeyPageUp is a helper function to send a page up key message to the model.\n\n```go\nfunc KeyQ(model *teatest.TestModel)\n```\nKeyQ is a helper function to send a key q message to the model.\n\n```go\nfunc KeyRight(model *teatest.TestModel)\n```\nKeyRight is a helper function to send a key right message to the model.\n\n```go\nfunc KeyS(model *teatest.TestModel)\n```\nKeyS is a helper function to send a 's' key message to the model.\n\n```go\nfunc KeyTab(model *teatest.TestModel)\n```\nKeyTab is a helper function to send a tab key message to the model.\n\n```go\nfunc KeyUp(model *teatest.TestModel)\n```\nKeyUp is a helper function to send a key up message to the model.\n\n```go\nfunc LastApplyReconciliationPayloadFromEngine(eng engine.DeployEngine) *types.ApplyReconciliationPayload\n```\nLastApplyReconciliationPayloadFromEngine returns the last ApplyReconciliation payload received by the test engine. Returns nil if the engine is not a test engine, or if no reconciliation has been applied.\n\n```go\nfunc LastChangesetPayloadFromEngine(eng engine.DeployEngine) *types.CreateChangesetPayload\n```\nLastChangesetPayloadFromEngine returns the last CreateChangeset payload received by the test engine. Returns nil if the engine is not a test engine, or if no changes were staged.\n\n```go\nfunc LastValidationPayloadFromEngine(eng engine.DeployEngine) *types.CreateBlueprintValidationPayload\n```\nLastValidationPayloadFromEngine returns the last CreateBlueprintValidation payload received by the test engine, if any. Returns nil if the engine is not a test engine, or if no validation has been created.\n\n```go\nfunc NewSaveBuffer() *safeBuffer\n```\nNewSaveBuffer creates a new buffer that can be used to capture output from TUI apps in headless mode in a thread-safe manner.\n\n```go\nfunc NewTestDeployEngine(stubValidationEvents []*types.BlueprintValidationEvent) engine.DeployEngine\n```\n\n```go\nfunc NewTestDeployEngineForInspect(\n\tinstanceState *state.InstanceState,\n\tdeploymentEvents []*types.BlueprintInstanceEvent,\n) engine.DeployEngine\n```\nNewTestDeployEngineForInspect creates a test deploy engine for inspect scenarios. If deploymentEvents is nil, no streaming will occur (static view mode). If deploymentEvents is non-nil, events will be streamed (in-progress mode).\n\n```go\nfunc NewTestDeployEngineForInspectNotFound() engine.DeployEngine\n```\nNewTestDeployEngineForInspectNotFound creates a test deploy engine for inspect scenarios where the instance is not found.\n\n```go\nfunc NewTestDeployEngineForList(instances []state.InstanceSummary) engine.DeployEngine\n```\nNewTestDeployEngineForList creates a test deploy engine for list scenarios.\n\n```go\nfunc NewTestDeployEngineForListError() engine.DeployEngine\n```\nNewTestDeployEngineForListError creates a test deploy engine that returns an error on list.\n\n```go\nfunc NewTestDeployEngineWithChangesetFetchError(err error) engine.DeployEngine\n```\nNewTestDeployEngineWithChangesetFetchError creates a test deploy engine that returns an error on GetChangeset, simulating a change set that cannot be read back.\n\n```go\nfunc NewTestDeployEngineWithDeployment(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n\tinstanceState *state.InstanceState,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithDeployment creates a test deploy engine with deployment event support.\n\n```go\nfunc NewTestDeployEngineWithDeploymentAndChangeset(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n\tinstanceState *state.InstanceState,\n\tchangesetChanges *changes.BlueprintChanges,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithDeploymentAndChangeset creates a test deploy engine with deployment event support and changeset changes that can be fetched via GetChangeset.\n\n```go\nfunc NewTestDeployEngineWithDeploymentError(err error) engine.DeployEngine\n```\nNewTestDeployEngineWithDeploymentError creates a test deploy engine that returns an error on CreateBlueprintInstance or UpdateBlueprintInstance.\n\n```go\nfunc NewTestDeployEngineWithDestroyError(err error) engine.DeployEngine\n```\nNewTestDeployEngineWithDestroyError creates a test deploy engine that returns an error on DestroyBlueprintInstance calls.\n\n```go\nfunc NewTestDeployEngineWithInstanceCreatedAfterLookup(\n\tstubStagingEvents []*types.ChangeStagingEvent,\n\tchangesetID string,\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceState *state.InstanceState,\n\tinstanceName string,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithInstanceCreatedAfterLookup creates a test deploy engine for staging and deploying a name that another deploy takes in between: the first lookup of instanceName reports it as not found, and later lookups find instanceState.\n\n```go\nfunc NewTestDeployEngineWithInstanceLookupError(err error) engine.DeployEngine\n```\nNewTestDeployEngineWithInstanceLookupError creates a test deploy engine whose GetBlueprintInstance fails with err, for an engine that cannot be reached.\n\n```go\nfunc NewTestDeployEngineWithMissingChangeset(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n\tinstanceState *state.InstanceState,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithMissingChangeset creates a test deploy engine for which GetChangeset finds nothing, simulating a change set ID that does not exist.\n\n```go\nfunc NewTestDeployEngineWithNoInstanceState(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithNoInstanceState creates a test deploy engine that returns an error when GetBlueprintInstance is called (simulating no instance state available).\n\n```go\nfunc NewTestDeployEngineWithStaging(\n\tstubStagingEvents []*types.ChangeStagingEvent,\n\tchangesetID string,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithStaging creates a test deploy engine with staging event support.\n\n```go\nfunc NewTestDeployEngineWithStagingAndDeployment(\n\tstubStagingEvents []*types.ChangeStagingEvent,\n\tchangesetID string,\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceState *state.InstanceState,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithStagingAndDeployment creates a test deploy engine for staging changes and then deploying them: staging streams stubStagingEvents for changesetID, and the deployment streams stubDeploymentEvents for instanceState, which GetBlueprintInstance also returns for any ID or name.\n\n```go\nfunc NewTestDeployEngineWithStagingError(err error) engine.DeployEngine\n```\nNewTestDeployEngineWithStagingError creates a test deploy engine that returns an error on CreateChangeset.\n\n```go\nfunc NewTestDeployEngineWithStreamError(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n\tinstanceState *state.InstanceState,\n\tstreamErr error,\n\tstreamErrDelay time.Duration,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithStreamError creates a test deploy engine that streams the given deployment events and then, after streamErrDelay, reports an error on the error channel the way the client does when a deployment fails mid-run. The delay gives the streamed events time to be processed first, and a delay longer than the model's error poll window exercises an error that arrives after a poll has expired.\n\n```go\nfunc NewTestDeployEngineWithUnknownInstanceName(\n\tstubDeploymentEvents []*types.BlueprintInstanceEvent,\n\tinstanceID string,\n\tinstanceState *state.InstanceState,\n\tunknownInstanceName string,\n) engine.DeployEngine\n```\nNewTestDeployEngineWithUnknownInstanceName creates a test deploy engine for deploying a new instance by name: GetBlueprintInstance returns a 404 client error for unknownInstanceName, and the deployment creates instanceState.\n\n```go\nfunc WaitFor(t *testing.T, output io.Reader, condition func(output []byte) bool)\n```\nWaitFor is a helper function to wait for a condition to be true with a pre-defined check interval (20ms) and timeout duration (10 seconds).\n\n```go\nfunc WaitForContains(t *testing.T, output io.Reader, text string)\n```\nWaitForContains is a helper function to wait for a string to be present in the output.\n\n```go\nfunc WaitForContainsAll(t *testing.T, output io.Reader, texts ...string)\n```\nWaitForContainsAll is a helper function to wait for all strings to be present in the output.\n\n","path":"github.com/newstack-cloud/deploy-cli-sdk/testutils","name":"testutils","synopsis":"","isRedistributable":true}
