GithubHelp home page GithubHelp logo

pgmock's Introduction

pgmock

pgmock provides the ability to mock a PostgreSQL server.

See pgmock_test.go for example usage.

pgmockproxy

pgmockproxy is a PostgreSQL proxy that logs the messages back and forth between the PostgreSQL client and server. This can aid in building a mocking script by running commands against a real server to observe the results. It can also be used to debug applications that speak the PostgreSQL wire protocol without needing to use a tool like Wireshark.

Example usage:

$ pgmockproxy -remote "/private/tmp/.s.PGSQL.5432"
F {"Type":"StartupMessage","ProtocolVersion":196608,"Parameters":{"application_name":"psql","client_encoding":"UTF8","database":"jack","user":"jack"}}
B {"Type":0,"Salt":[0,0,0,0],"SASLAuthMechanisms":null,"SASLData":null}
B {"Type":"ParameterStatus","Name":"application_name","Value":"psql"}
B {"Type":"ParameterStatus","Name":"client_encoding","Value":"UTF8"}
B {"Type":"ParameterStatus","Name":"DateStyle","Value":"ISO, MDY"}
B {"Type":"ParameterStatus","Name":"integer_datetimes","Value":"on"}
B {"Type":"ParameterStatus","Name":"IntervalStyle","Value":"postgres"}
B {"Type":"ParameterStatus","Name":"is_superuser","Value":"on"}
B {"Type":"ParameterStatus","Name":"server_encoding","Value":"UTF8"}
B {"Type":"ParameterStatus","Name":"server_version","Value":"11.5"}
B {"Type":"ParameterStatus","Name":"session_authorization","Value":"jack"}
B {"Type":"ParameterStatus","Name":"standard_conforming_strings","Value":"on"}
B {"Type":"ParameterStatus","Name":"TimeZone","Value":"US/Central"}
B {"Type":"BackendKeyData","ProcessID":31007,"SecretKey":1013083042}
B {"Type":"ReadyForQuery","TxStatus":"I"}
F {"Type":"Query","String":"select generate_series(1,5);"}
B {"Type":"RowDescription","Fields":[{"Name":"generate_series","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":23,"DataTypeSize":4,"TypeModifier":-1,"Format":0}]}
B {"Type":"DataRow","Values":[{"text":"1"}]}
B {"Type":"DataRow","Values":[{"text":"2"}]}
B {"Type":"DataRow","Values":[{"text":"3"}]}
B {"Type":"DataRow","Values":[{"text":"4"}]}
B {"Type":"DataRow","Values":[{"text":"5"}]}
B {"Type":"CommandComplete","CommandTag":"SELECT 5"}
B {"Type":"ReadyForQuery","TxStatus":"I"}
F {"Type":"Terminate"}

pgmock's People

Contributors

jackc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pgmock's Issues

Instructions for setup?

Hi,

I saw a demo of this project recently and I am a big fan. I'd like to use it to view the messages/queries being passed to a Postgres server. Do you have instructions for how to get this setup for that use case?

โค๏ธ ๐Ÿ’™ ๐Ÿ’œ ๐Ÿ’š ๐Ÿ’›

Delete dependencies on older versions

I want to delete dependencies on github.com/satori/go.uuid because it is vulnerable.

# master branch of https://github.com/jackc/pgx
$ pwd
/home/go/src/github.com/pgx
$ go mod graph | grep satori
github.com/jackc/[email protected] github.com/satori/[email protected]
github.com/jackc/pgx/[email protected] github.com/satori/[email protected]
github.com/jackc/[email protected] github.com/satori/[email protected]
github.com/jackc/pgx/[email protected] github.com/satori/[email protected]
github.com/jackc/[email protected] github.com/satori/[email protected]
github.com/jackc/pgx/[email protected] github.com/satori/[email protected]

But, maybe we cannot do that because there are cyclic dependencies between modules as below(this is part of go mod graph outputs) .

github.com/jackc/pgx/v4 ->
github.com/jackc/[email protected] ->
github.com/jackc/[email protected] ->
github.com/jackc/[email protected] ->
github.com/jackc/[email protected] ->
github.com/satori/[email protected]

github.com/jackc/pgmock depends on github.com/jackc/pgconn, and vice versa.
github.com/jackc/pgx depends on github.com/jackc/pgtype, and vice versa.

I don't fully understand, but I think we cannot delete dependencies on older versions completely even if update module like #5.

Am I right?
If yes, do you have any plan to resolve this?

Related Issues:

proxy cannot work, exit with unexpected EOF

my local postgres serve on port 7432, and psql can connect to it:

 psql -h localhost -p 7432 -U postgres postgres
Password for user postgres: 
psql (13.3, server 12.6)

but use proxy:

 go run pgmockproxy/main.go --listen=localhost:15432 --remote=localhost:7432

and psql -h localhost -p 15432 -U postgres postgres
result:

F {"Type":"SSLRequest","ProtocolVersion":0,"Parameters":null}
2021/07/02 23:21:29 unexpected EOF
Exiting.

can't figure out what's wrong here, please help, thanks.

Can't get pgmockproxy to start

Setup:

Get a postgres server running:

$ docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres

Run the proxy:

./pgproxy -listen 127.0.0.1:5433 -remote 127.0.0.1:5432

Connect to the proxy. (work around issue with SSL jackc/pgproto3#15):

psql "sslmode=disable host=localhost port=5433 user=postgres"

Result:

$ ./pgproxy -listen 127.0.0.1:5433 -remote 127.0.0.1:5432
F {"Type":"StartupMessage","ProtocolVersion":196608,"Parameters":{"application_name":"psql","client_encoding":"UTF8","database":"postgres","user":"postgres"}}
B {"Salt":[12,118,255,169]}
2021/05/14 16:21:52 EOF

This differs dramatically from what can be seen in the readme. So far I've yet to find an obvious explanation for what is going on :(

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.