Coder Social home page Coder Social logo

pgtester's Introduction

PgTester Build Status Dependency Status

A handy gem to help with testing postgresql related scripts or anything PostgreSQL related.

Installation

Add this line to your application's Gemfile (source https://rubygems.org):

gem 'pg_tester'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pg_tester

Usage

Initialize a PgTester instance:

require 'pg_tester'

psql = PgTester.new({

  port:             '312',
  host:             'localhost',
  db_name:          'testpostgresql',
  user_name:        'testpostgresql',
  data_dir:         '/tmp/',
  initdb_path:      '/usr/local/bin/initdb',
  pgctl_path:       '/usr/local/bin/which pg_ctl',
  createuser_path:  '/usr/local/bin/which createuser',
  createdb_path:    '/usr/local/bin/which createdb',
  })

Case 1

Create a test PostgreSQL cluster in /tmp, connect as testpostgresql user and database name testpostgresql, and run queries against the test database:

psql.setup 
result = psql.exec(query)
# ... do some expectation on result

Remember to teardown the database to stop PostgreSQL:

psql.teardown # Cluster is torn down and dir in /tmp deleted

Case 2

Execute the block and teardown database after block execution:

psql.exec(query) do |result|
  # ... do some expectation on result
end

Case 3

Pass custom arguments and execute query in block:

PgTester.new({
  port:             '312',
  data_dir:         '/tmp/',
}).exec(query) { |result| # some expectation }

Case 4

Use inside rspec specs:

context 'run query in block' do
  it 'should run exec query in a block' do
    PgTester.new().exec('SELECT 2') do |result|
      expect(result.getvalue(0,0)).to eq("2")
    end
  end

  it 'should run exec query in a curly block' do
    PgTester.new().exec('SELECT 3') { |result| expect(result.getvalue(0,0)).to eq("3") }
  end
end

Tests

You can run the tests by doing

bundle exec rspec

Contributing

Pull requests are welcome!

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

pgtester's People

Contributors

msftgits avatar negul avatar unindented 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

Watchers

 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

pgtester's Issues

bin/console is too generic

I recommend you change the name of the bin/console executable to bin/pgtester to avoid conflicts with other "console" executables.

Should pg_tester work in Linux?

Sorry for my ignorance but I am not able to use pg_tester in Linux. It fails when starting the server. I tred to manually run the same command, i.e.:

 /usr/bin/pg_ctl start -o '-p 6433' -D /tmp/pg_tester`

And I obtain the following error message:

could not create lock file "/var/run/postgresql/.s.PGSQL.6433.lock": Permission denied

Intuitively, I would expect something like that; an unprivileged user typically should be able to write there. So the question is - is there any way to run pg_tester without root / postgres account? Or what amendments should I make to my user environment that will not be an open security hole?

Thanks for any hints on this problem.

P.S. My colleagues are happily using pg_tester in macOS.

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.