Documentation ¶
Index ¶
- type Config
- type DurableStore
- func (s *DurableStore) Connect(ctx context.Context) error
- func (s *DurableStore) Disconnect(ctx context.Context) error
- func (s *DurableStore) GetLatestState(ctx context.Context, persistenceID string) (*egopb.DurableState, error)
- func (s *DurableStore) Ping(ctx context.Context) error
- func (s *DurableStore) WriteState(ctx context.Context, state *egopb.DurableState) error
- type SchemaUtils
- type TestContainer
- type TestDB
- func (c TestDB) Count(ctx context.Context, tableName string) (int, error)
- func (c TestDB) CreateSchema(ctx context.Context, schemaName string) error
- func (c TestDB) DropSchema(ctx context.Context, schemaName string) error
- func (c TestDB) DropTable(ctx context.Context, tableName string) error
- func (c TestDB) SchemaExists(ctx context.Context, schemaName string) (bool, error)
- func (c TestDB) TableExists(ctx context.Context, tableName string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { DBHost string // DBHost represents the database host DBPort int // DBPort is the database port DBName string // DBName is the database name DBUser string // DBUser is the database user used to connect DBPassword string // DBPassword is the database password DBSchema string // DBSchema represents the database schema }
Config defines the postgres events store configuration
type DurableStore ¶
type DurableStore struct {
// contains filtered or unexported fields
}
DurableStore implements the DurableStore interface and helps persist events in a database database
func NewDurableStore ¶
func NewDurableStore(config *Config) *DurableStore
NewDurableStore creates a new instance of StateStore
func (*DurableStore) Connect ¶
func (s *DurableStore) Connect(ctx context.Context) error
Connect connects to the underlying postgres database
func (*DurableStore) Disconnect ¶
func (s *DurableStore) Disconnect(ctx context.Context) error
Disconnect disconnects from the underlying postgres database
func (*DurableStore) GetLatestState ¶
func (s *DurableStore) GetLatestState(ctx context.Context, persistenceID string) (*egopb.DurableState, error)
GetLatestState fetches the latest durable state of a persistenceID
func (*DurableStore) Ping ¶
func (s *DurableStore) Ping(ctx context.Context) error
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DurableStore) WriteState ¶
func (s *DurableStore) WriteState(ctx context.Context, state *egopb.DurableState) error
WriteState writes a durable state into the underlying postgres database
type SchemaUtils ¶
type SchemaUtils struct {
// contains filtered or unexported fields
}
SchemaUtils help create the various test tables in unit/integration tests
func NewSchemaUtils ¶
func NewSchemaUtils(db *TestDB) *SchemaUtils
NewSchemaUtils creates an instance of SchemaUtils
func (SchemaUtils) CreateTable ¶
func (d SchemaUtils) CreateTable(ctx context.Context) error
CreateTable creates the event store table used for unit tests
type TestContainer ¶
type TestContainer struct {
// contains filtered or unexported fields
}
TestContainer helps creates a database docker container to run unit tests
func NewTestContainer ¶
func NewTestContainer(dbName, dbUser, dbPassword string) *TestContainer
NewTestContainer create a database test container useful for unit and integration tests This function will exit when there is an error.Call this function inside your SetupTest to create the container before each test.
func (TestContainer) Cleanup ¶
func (c TestContainer) Cleanup()
Cleanup frees the resource by removing a container and linked volumes from docker. Call this function inside your TearDownSuite to clean-up resources after each test
func (TestContainer) GetTestDB ¶
func (c TestContainer) GetTestDB() *TestDB
GetTestDB returns a database TestDB that can be used in the tests to perform some database queries
func (TestContainer) Host ¶
func (c TestContainer) Host() string
Host return the host of the test container
func (TestContainer) Port ¶
func (c TestContainer) Port() int
Port return the port of the test container
func (TestContainer) Schema ¶
func (c TestContainer) Schema() string
Schema return the test schema of the test container
type TestDB ¶
type TestDB struct {
// contains filtered or unexported fields
}
TestDB is used in test to perform some database queries
func (TestDB) Count ¶
Count utility function to help count the number of rows in a database table. tableName is in the format: <schemaName.tableName>. e.g: public.users It returns -1 when there is an error
func (TestDB) CreateSchema ¶
CreateSchema helps create a test schema in a database database
func (TestDB) DropSchema ¶
DropSchema utility function to drop a database schema
func (TestDB) SchemaExists ¶
SchemaExists helps check the existence of a database schema. Very useful when implementing tests