Documentation ¶
Index ¶
- Constants
- func DBURL(name string) string
- func ExecSQL(ctx context.Context, url string, query string) error
- func ExecSQLBatch(ctx context.Context, url string, query string) error
- func GenPhoneCC(cc string) string
- func GenUUID() string
- func SQLRollback(t *testing.T, errMsg string, tx *sql.Tx)
- type DataGen
- type DataGenArgFunc
- type DataGenFunc
- type EmailServer
- type ExpectedCall
- type ExpectedSMS
- type Generator
- type Harness
- func NewHarness(t *testing.T, initSQL, migrationName string) *Harness
- func NewHarnessDebugDB(t *testing.T, initSQL, migrationName string) *Harness
- func NewHarnessWithData(t *testing.T, initSQL string, sqlData interface{}, migrationName string) *Harness
- func NewHarnessWithFlags(t *testing.T, initSQL, migrationName string, fs expflag.FlagSet) *Harness
- func NewStoppedHarness(t *testing.T, initSQL string, sqlData interface{}, migrationName string) *Harness
- func NewStoppedHarnessWithFlags(t *testing.T, initSQL string, sqlData interface{}, migrationName string, ...) *Harness
- func (h *Harness) AddNotificationRule(userID, cmID string, delayMinutes int)
- func (h *Harness) App() *app.App
- func (h *Harness) Close() error
- func (h *Harness) Config() config.Config
- func (h *Harness) CreateAlert(serviceID string, summary string) TestAlert
- func (h *Harness) CreateAlertWithDetails(serviceID, summary, details string) TestAlert
- func (h *Harness) CreateUser() (u *user.User)
- func (h *Harness) Email(id string) string
- func (h *Harness) Escalate(alertID, level int)
- func (h *Harness) EscalateAlertErr(alertID int) (err error)
- func (h *Harness) FastForward(d time.Duration)
- func (h *Harness) GraphQLQuery2(query string) *QLResponse
- func (h *Harness) GraphQLQueryT(t *testing.T, query string) *QLResponse
- func (h *Harness) GraphQLQueryUserT(t *testing.T, userID, query string) *QLResponse
- func (h *Harness) GraphQLQueryUserVarsT(t *testing.T, userID, query, opName string, vars any) *QLResponse
- func (h *Harness) GraphQLToken(userID string) string
- func (h *Harness) IgnoreErrorsWith(substr string)
- func (h *Harness) Migrate(migrationName string)
- func (h *Harness) Phone(id string) string
- func (h *Harness) PhoneCC(cc, id string) string
- func (h *Harness) SMTP() EmailServer
- func (h *Harness) SendMail(from, to, subject, body string)
- func (h *Harness) SetCarrierName(number, name string)
- func (h *Harness) SetConfigValue(id, value string)
- func (h *Harness) SetSystemLimit(id limit.ID, value int)
- func (h *Harness) Slack() SlackServer
- func (h *Harness) Start()
- func (h *Harness) Trigger()
- func (h *Harness) Twilio(t *testing.T) PhoneAssertions
- func (h *Harness) TwilioMessagingService() string
- func (h *Harness) TwilioNumber(id string) string
- func (h *Harness) URL() string
- func (h *Harness) UUID(id string) string
- func (h *Harness) WaitAndAssertOnCallUsers(serviceID string, userIDs ...string)
- type PhoneAssertions
- type PhoneDevice
- type QLPath
- type QLResponse
- type SMSReply
- type SlackAction
- type SlackChannel
- type SlackMessage
- type SlackMessageState
- type SlackServer
- type SlackUser
- type SlackUserGroup
- type TestAlert
Constants ¶
const DefaultGraphQLAdminUserID = "00000000-0000-0000-0000-000000000002"
DefaultGraphQLAdminUserID is the UserID created & used for GraphQL calls by default.
const (
SlackTestSigningSecret = "secret"
)
Variables ¶
This section is empty.
Functions ¶
func ExecSQLBatch ¶
ExecSQLBatch will execute all queries in a transaction by sending them all at once.
func GenPhoneCC ¶
GenPhoneCC will return a random phone number with supplied country code
Types ¶
type DataGen ¶
type DataGen struct {
// contains filtered or unexported fields
}
DataGen handles generating random data for tests. It ties arbitrary ids to generated values so they can be re-used during a test.
func NewDataGen ¶
NewDataGen will create a new data generator. fn should return a new/unique string each time
func (*DataGen) Get ¶
Get returns the value associated with id. The first time an id is provided, a new value is generated. If id is empty, a new value will always be returned.
func (*DataGen) GetWithArg ¶
GetWithArg returns the value associated with id. The first time an id is provided, a new value is generated. If id is empty, a new value will always be returned.
type DataGenArgFunc ¶
func (DataGenArgFunc) Generate ¶
func (d DataGenArgFunc) Generate(a string) string
type DataGenFunc ¶
type DataGenFunc func() string
func (DataGenFunc) Generate ¶
func (d DataGenFunc) Generate(string) string
type EmailServer ¶
type ExpectedCall ¶
type ExpectedCall interface { // ThenPress imitates a user entering a key on the phone. ThenPress(digits string) ExpectedCall // ThenExpect asserts that the message matches ALL keywords (case-insensitive). // // Generally used as ThenPress().ThenExpect() ThenExpect(keywords ...string) ExpectedCall // Body will return the last full spoken message as text. Separate stanzas (e.g. multiple `<Say>`) are // separated by newline. Body() string // Hangup will hangup the active call. Hangup() }
ExpectedCall represents a phone call.
type ExpectedSMS ¶
type ExpectedSMS interface { // ThenReply will respond with an SMS with the given body. ThenReply(body string) SMSReply // Body is the text of the SMS message. Body() string // From is the source number of the SMS message. From() string }
ExpectedSMS represents an SMS message.
type Harness ¶
type Harness struct {
// contains filtered or unexported fields
}
Harness is a helper for smoketests. It deals with assertions, database management, and backend monitoring during tests.
func NewHarness ¶
NewHarness will create a new database, perform `migrateSteps` migrations, inject `initSQL` and return a new Harness bound to the result. It starts a backend process pre-configured to a mock twilio server for monitoring notifications as well.
func NewHarnessDebugDB ¶
NewHarnessDebugDB works like NewHarness, but fails the test immediately after migrations have been run. It is used to debug data & queries from a smoketest.
Note that the now() function will be locked to the init timestamp for inspection.
func NewHarnessWithData ¶
func NewHarnessWithFlags ¶ added in v0.31.0
NewHarnessWithFlags is the same as NewHarness, but allows passing in a set of experimental flags to be used for the test.
func NewStoppedHarness ¶
func NewStoppedHarness(t *testing.T, initSQL string, sqlData interface{}, migrationName string) *Harness
NewStoppedHarness will create a NewHarness, but will not call Start.
func NewStoppedHarnessWithFlags ¶ added in v0.31.0
func NewStoppedHarnessWithFlags(t *testing.T, initSQL string, sqlData interface{}, migrationName string, expFlags expflag.FlagSet) *Harness
NewStoppedHarnessWithFlags is the same as NewStoppedHarness, but allows passing in a set of experimental flags to be used for the test.
func (*Harness) AddNotificationRule ¶
AddNotificationRule will add a notification rule to the database.
func (*Harness) Close ¶
Close terminates any background processes, and drops the testing database. It should be called at the end of all tests (usually with `defer h.Close()`).
func (*Harness) CreateAlert ¶
CreateAlerts will create one or more unacknowledged alerts for a service.
func (*Harness) CreateAlertWithDetails ¶
CreateAlertWithDetails will create a single alert with summary and detailss.
func (*Harness) CreateUser ¶
CreateUser generates a random user.
func (*Harness) EscalateAlertErr ¶ added in v0.31.0
func (*Harness) FastForward ¶
func (*Harness) GraphQLQuery2 ¶
func (h *Harness) GraphQLQuery2(query string) *QLResponse
GraphQLQuery2 will perform a GraphQL2 query against the backend, internally handling authentication. Queries are performed with Admin role.
func (*Harness) GraphQLQueryT ¶
func (h *Harness) GraphQLQueryT(t *testing.T, query string) *QLResponse
GraphQLQueryT will perform a GraphQL query against the backend, internally handling authentication. Queries are performed with Admin role.
func (*Harness) GraphQLQueryUserT ¶
func (h *Harness) GraphQLQueryUserT(t *testing.T, userID, query string) *QLResponse
GraphQLQueryUserT will perform a GraphQL query against the backend, internally handling authentication. Queries are performed with the provided UserID.
func (*Harness) GraphQLQueryUserVarsT ¶ added in v0.33.0
func (h *Harness) GraphQLQueryUserVarsT(t *testing.T, userID, query, opName string, vars any) *QLResponse
GraphQLQueryUserT will perform a GraphQL query against the backend, internally handling authentication. Queries are performed with the provided UserID.
func (*Harness) GraphQLToken ¶ added in v0.32.0
func (*Harness) IgnoreErrorsWith ¶
IgnoreErrorsWith will cause the Harness to ignore backend errors containing the specified substring.
func (*Harness) SMTP ¶
func (h *Harness) SMTP() EmailServer
func (*Harness) SendMail ¶ added in v0.31.0
SendMail will send an email to the backend's SMTP server.
func (*Harness) SetCarrierName ¶
SetCarrierName will set the carrier name for the given phone number.
func (*Harness) SetConfigValue ¶
SetConfigValue will update the config value id (e.g. `General.PublicURL`) to the provided value.
func (*Harness) SetSystemLimit ¶
SetSystemLimit will update the value of a system limit given an id (e.g. `RulesPerSchedule`). TODO repalce SetSystemLimit with new mutation (work anticipated to be done with Admin Config view)
func (*Harness) Slack ¶
func (h *Harness) Slack() SlackServer
func (*Harness) Trigger ¶
func (h *Harness) Trigger()
Trigger will trigger, and wait for, an engine cycle.
func (*Harness) Twilio ¶
func (h *Harness) Twilio(t *testing.T) PhoneAssertions
Twilio will return PhoneAssertions for the given testing context.
func (*Harness) TwilioMessagingService ¶
TwilioMessagingService will return the id and phone numbers for the mock messaging service.
func (*Harness) TwilioNumber ¶
TwilioNumber will return a registered (or register if missing) Twilio number for the given ID. The default FromNumber will always be the empty ID.
func (*Harness) WaitAndAssertOnCallUsers ¶
WaitAndAssertOnCallUsers will ensure the correct set of users as on-call for the given serviceID.
type PhoneAssertions ¶
type PhoneAssertions interface { // Device returns a TwilioDevice for the given number. // // It is safe to call multiple times for the same device. Device(number string) PhoneDevice // WaitAndAssert will fail the test if there are any unexpected messages received within the timeout interval. WaitAndAssert() }
PhoneAssertions is used to assert voice and SMS behavior.
type PhoneDevice ¶
type PhoneDevice interface { // SendSMS will send a message to GoAlert from the device. SendSMS(body string) // ExpectSMS will match against an SMS that matches ALL provided keywords (case-insensitive). // Each call to ExpectSMS results in the requirement that an additional SMS is received. ExpectSMS(keywords ...string) ExpectedSMS // RejectSMS will match against an SMS that matches ALL provided keywords (case-insensitive) and tell the server that delivery failed. RejectSMS(keywords ...string) // ExpectVoice will match against a voice call where the spoken text matches ALL provided keywords (case-insensitive). ExpectVoice(keywords ...string) ExpectedCall // RejectVoice will match against a voice call where the spoken text matches ALL provided keywords (case-insensitive) and tell the server that delivery failed. RejectVoice(keywords ...string) // IgnoreUnexpectedSMS will cause any extra SMS messages (after processing ExpectSMS calls) that match // ALL keywords (case-insensitive) to not fail the test. IgnoreUnexpectedSMS(keywords ...string) // IgnoreUnexpectedVoice will cause any extra voice calls (after processing ExpectVoice) that match // ALL keywords (case-insensitive) to not fail the test. IgnoreUnexpectedVoice(keywords ...string) }
A PhoneDevice immitates a device (i.e. a phone) for testing interactions.
type QLResponse ¶
type QLResponse struct { Data json.RawMessage Errors []struct { Message string Path QLPath Extensions struct { Code string Key string FieldID string } } }
QLResponse is a generic GraphQL response.
type SMSReply ¶
type SMSReply interface { // ThenExpect will match against an SMS that matches ALL provided keywords (case-insensitive). // The message must be received AFTER the reply is sent or the assertion will fail. ThenExpect(keywords ...string) ExpectedSMS }
SMSReply represents a reply to a received SMS message.
type SlackAction ¶
type SlackAction interface { Click() URL() string }
type SlackChannel ¶
type SlackChannel interface { ID() string Name() string ExpectMessage(keywords ...string) SlackMessage ExpectEphemeralMessage(keywords ...string) SlackMessage }
type SlackMessage ¶
type SlackMessage interface { SlackMessageState ExpectUpdate() SlackMessageState // ExpectThreadReply waits and asserts that a non-broadcast thread reply is received. ExpectThreadReply(keywords ...string) // ExpectBroadcastReply waits and asserts that a broadcast thread reply is received. ExpectBroadcastReply(keywords ...string) }
type SlackMessageState ¶
type SlackMessageState interface { // AssertText asserts that the message contains the given keywords. AssertText(keywords ...string) // AssertNotText asserts that the message does not contain the given keywords. AssertNotText(keywords ...string) // AssertColor asserts that the message has the given color bar value. AssertColor(color string) // AssertActions asserts that the message includes the given action buttons. AssertActions(labels ...string) // Action returns the action with the given label. Action(label string) SlackAction }
type SlackServer ¶
type SlackServer interface { Channel(string) SlackChannel User(string) SlackUser UserGroup(string) SlackUserGroup WaitAndAssert() }
type SlackUser ¶ added in v0.31.0
type SlackUser interface { ID() string Name() string ExpectMessage(keywords ...string) SlackMessage }
type SlackUserGroup ¶ added in v0.31.0
type SlackUserGroup interface { ID() string Name() string ErrorChannel() SlackChannel ExpectUsers(names ...string) ExpectUserIDs(ids ...string) }