https://github.com/half0wl/mockgres
A simple server implementing basic Postgres protocol for testing purposes.
https://github.com/half0wl/mockgres
postgres postgresql testing
Last synced: 9 months ago
JSON representation
A simple server implementing basic Postgres protocol for testing purposes.
- Host: GitHub
- URL: https://github.com/half0wl/mockgres
- Owner: half0wl
- Created: 2025-09-08T01:04:24.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-08T01:26:15.000Z (10 months ago)
- Last Synced: 2025-09-18T21:40:47.840Z (10 months ago)
- Topics: postgres, postgresql, testing
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mockgres
A stupidly simple mock Postgres server for testing purposes.
```
# Run the server:
PORT=6666 go run ./main.go
starting mock server on port 6666
waiting for conn on port 6666...
conn from 127.0.0.1:56372
startup message length: 78
proto: 0x30000
regular startup message (protocol 3.0)
startup parameters: "user\x00test\x00database\x00foobar\x00application_name\x00psql\x00client_encoding\x00UTF8\x00\x00"
user: test, database: foobar
requesting password authentication
received password: "test"
Authentication successful
handshake complete, ready
conn established
received query: "select 1;"
received query: <....>
handling \dt
# From psql:
psql 'postgresql://test:test@0.0.0.0:6666/foobar?sslmode=disable'
psql (17.6, server 14.0)
Type "help" for help.
foobar=> select 1;
SELECT 0
foobar=> \dt
List of relations
Schema | Name | Type | Owner
--------+------------+-------+-------
public | test_table | table | test
(1 row)
```
The main use case for this is the `--intentionally-borked` flag which
simulates a Postgres server that unexpectedly closes connections with
a TCP RST packet on any query:
```
# Run server with --intentionally-borked flag:
PORT=6666 go run ./main.go --intentionally-borked
starting mock server on port 6666
--intentionally-borked is on, will send RST on any query!
...
received query: "select 1;"
query recv, sending RST as --intentionally-borked is on
waiting 2 seconds before forcing RST close
forcing RST close on conn!
query error: conn forcibly closed with RST
...
# From psql:
psql 'postgresql://test:test@0.0.0.0:6666/foobar?sslmode=disable'
psql (17.6, server 14.0)
Type "help" for help.
foobar=> select 1;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
The connection to the server was lost. Attempting reset: Failed.
```
SSL Mode is not supported. You should also be able to connect to this with any
Postgres client/library.