Documentation
¶
Overview ¶
Package pgtest is the PostgreSQL server the Go modules' PostgreSQL tests share (the postgres module's own and the Agent Framework integration's cross-language tests): it starts or finds the server, makes the roles, and creates databases migrated as the .NET library migrates them. It is a module of its own (Go 1.26), with the store's own PostgreSQL tests, so the store's module requires no container library. For tests only; nothing else imports it.
The schema is never reimplemented here. Each test database is migrated by running the .NET migrator's own scripts (src/AgentExperience.Storage.Postgres/Migrations/*.sql) in name order, one transaction per script, as the owner role, which is what ExperienceSchemaMigrator.MigrateAsync does. The application role's privileges are the contract's sql/application-role-privileges.sql then, from contract 1.4, sql/application-role-privileges-1.4.sql (the injection table's), both modes (row-level security on, what a contract 1.x port runs against).
The server comes from PGHOST (with PGPORT, PGUSER, PGPASSWORD: a superuser connection) when set, else from a Testcontainers postgres container (AGENTEXPERIENCE_POSTGRES_MAJOR, default 16). With neither, the tests skip, unless AGENTEXPERIENCE_REQUIRE_POSTGRES=1, when they fail. testcontainers-go applies TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX to every image it starts, the Reaper's (Ryuk) included, and recognises the Reaper by its name's suffix, so a prefix (CI's Docker Hub mirror) needs no workaround here, unlike testcontainers-python (python/tests/_postgres.py).
Index ¶
- Constants
- func ApplicationRolePrivileges(t *testing.T, role string) []string
- func CreateDatabase(t *testing.T, admin Server, label string) string
- func CreateDatabaseWith(t *testing.T, admin Server, label string, privileges []string) string
- func DatabaseName(label string) string
- func PrivilegesOf(t *testing.T, role, file string) []string
- func Run(m *testing.M) int
- type Server
Constants ¶
const ( OwnerRole = "contract_owner" ApplicationRole = "contract_app" RolePassword = "contract-role-password" )
The roles every test database uses.
const ( PrivilegesFile = "application-role-privileges.sql" Privileges14File = "application-role-privileges-1.4.sql" )
The contract's privileges files: 1.0's, and 1.4's for the injection table.
Variables ¶
This section is empty.
Functions ¶
func ApplicationRolePrivileges ¶
ApplicationRolePrivileges are the statements of the contract's two privileges files for role (a plain identifier), the 1.0 file then the 1.4 file: what the .NET privileges call grants.
func CreateDatabase ¶
CreateDatabase is a fresh database, migrated by the .NET scripts and with the application role's privileges, dropped when the test ends (after the stores that use it close). Give each module's labels their own prefix: a server may be shared.
func CreateDatabaseWith ¶
CreateDatabaseWith is CreateDatabase with the application role given exactly privileges: PrivilegesOf the 1.0 file alone, say, for a schema whose role was never granted the injection table.
func DatabaseName ¶
DatabaseName is a unique, valid database name for a label: a readable prefix and a hash of the whole label.
func PrivilegesOf ¶
PrivilegesOf are the statements of one contract privileges file (under contract/sql/) for role (a plain identifier): those under "-- mode: always", then those under "-- mode: row-level-security".
Types ¶
type Server ¶
Server is a PostgreSQL server and its superuser.
func (Server) Application ¶
Application is a connection string to database as the application role.
func (Server) ConnString ¶
ConnString is a connection string to database as user.