postgres

package
v1.30.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package postgres provides Ginkgo/Gomega assertions over the Postgres data plane: test data setup, recovery mode checks, and helper query strings.

Callers that also import tests/utils/postgres should alias one of the two (e.g. pgasserts for this package, postgres for the primitive layer).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertApplicationDatabaseConnection

func AssertApplicationDatabaseConnection(
	env *environment.TestingEnvironment,
	namespace,
	clusterName,
	appUser,
	appDB,
	appPassword,
	appSecretName string,
)

AssertApplicationDatabaseConnection verifies that the cluster can be reached via its read-write service using the application user. When appPassword is empty, it is read from appSecretName (or the auto-generated <cluster>-app secret if appSecretName is empty).

func AssertConnection

func AssertConnection(
	env *environment.TestingEnvironment,
	namespace string,
	service string,
	dbname string,
	user string,
	password string,
)

AssertConnection opens a forwarded psql connection to a service, asserting that a basic SELECT 1 succeeds within RetryTimeout.

func AssertCreateTestData

func AssertCreateTestData(env *environment.TestingEnvironment, tl TableLocator)

AssertCreateTestData creates a small table at the given TableLocator. When DatabaseName or Tablespace are empty they default to AppDBName and the default tablespace.

func AssertCreateTestDataLargeObject

func AssertCreateTestDataLargeObject(
	env *environment.TestingEnvironment,
	namespace, clusterName string,
	oid int,
	data string,
)

AssertCreateTestDataLargeObject creates an image table containing a large object with the given oid and data.

func AssertCreationOfTestDataForTargetDB

func AssertCreationOfTestDataForTargetDB(
	env *environment.TestingEnvironment,
	namespace,
	clusterName,
	targetDBName,
	tableName string,
)

AssertCreationOfTestDataForTargetDB creates a target database with the application user as owner, then creates a placeholder table inside it and grants SELECT on every public table to pg_monitor.

func AssertDataExpectedCount

func AssertDataExpectedCount(
	env *environment.TestingEnvironment,
	tl TableLocator,
	expectedValue int,
)

AssertDataExpectedCount verifies that the named table has exactly expectedValue rows.

func AssertLargeObjectValue

func AssertLargeObjectValue(
	env *environment.TestingEnvironment,
	testTimeouts map[timeouts.Timeout]int,
	namespace, clusterName string,
	oid int,
	data string,
)

AssertLargeObjectValue checks that the large object identified by oid in the cluster's app database eventually returns the expected decoded data.

func AssertPgRecoveryMode

func AssertPgRecoveryMode(env *environment.TestingEnvironment, pod *corev1.Pod, expectedValue bool)

AssertPgRecoveryMode verifies whether the pod is in recovery mode.

func BoolPGOutput

func BoolPGOutput(expectedValue bool) string

BoolPGOutput translates a Go bool into the textual representation Postgres returns from a boolean expression ("t" or "f").

func DatabaseExistsQuery

func DatabaseExistsQuery(dbName string) string

DatabaseExistsQuery builds a SELECT EXISTS query for the named database.

func ExtensionExistsQuery

func ExtensionExistsQuery(extName string) string

ExtensionExistsQuery builds a SELECT EXISTS query for the named extension.

func FDWExistsQuery

func FDWExistsQuery(fdwName string) string

FDWExistsQuery builds a SELECT EXISTS query for the named foreign data wrapper.

func ForeignServerExistsQuery

func ForeignServerExistsQuery(serverName string) string

ForeignServerExistsQuery builds a SELECT EXISTS query for the named foreign server.

func InsertRecordIntoTable

func InsertRecordIntoTable(tableName string, value int, conn *sql.DB)

InsertRecordIntoTable inserts a single integer value into the named table over an open *sql.DB connection.

func QueryMatchExpectationPredicate

func QueryMatchExpectationPredicate(
	env *environment.TestingEnvironment,
	pod *corev1.Pod,
	dbname exec.DatabaseName,
	query string,
	expectedOutput string,
) func(g Gomega)

QueryMatchExpectationPredicate returns a Gomega predicate that runs the query inside the given pod and checks the trimmed output equals expectedOutput.

func RoleExistsQuery

func RoleExistsQuery(roleName string) string

RoleExistsQuery builds a SELECT EXISTS query for the named pg_role.

func SchemaExistsQuery

func SchemaExistsQuery(namespaceName string) string

SchemaExistsQuery builds a SELECT EXISTS query for the named schema.

Types

type TableLocator

type TableLocator struct {
	Namespace    string
	ClusterName  string
	DatabaseName string
	TableName    string
	Tablespace   string
}

TableLocator identifies a table inside a database within a cluster.

Jump to

Keyboard shortcuts

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