From 6f567bba980c85649aee7b095002d174341c8272 Mon Sep 17 00:00:00 2001 From: Jack A Ross Date: Wed, 3 Aug 2016 18:36:55 -0400 Subject: [PATCH 1/2] Adds `nib dbconsole service` command to `nib` binary The intention is to launch a database REPL console, such as `psql` in the context of the service. --- bin/nib | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/nib b/bin/nib index 25b3a6f..feaacf7 100755 --- a/bin/nib +++ b/bin/nib @@ -78,6 +78,22 @@ command :console do |c| end end +desc 'Start a Database REPL session for the given service' +long_desc <<-"DESC" + This command, for now, will simply run the file supplied at $pwd/bin/dbconsole. + We recommend someting as simple as: + + #! /bin/sh\n + psql "$@" +DESC +arg :service +arg :command, %i(optional multiple) +command :dbconsole do |c| + c.action do |global, options, args| + Nib::Run.execute(args.insert(1, './bin/dbconsole')) + end +end + desc 'Connect to a running byebug server for a given service' long_desc 'This command requires a little extra setup. From baed4da4b9aad602cd52bb759592eefcc1c722a9 Mon Sep 17 00:00:00 2001 From: Jack A Ross Date: Wed, 3 Aug 2016 18:37:19 -0400 Subject: [PATCH 2/2] Adds rudimentary tests for `nib dbconsole` command --- spec/dummy/rails/bin/dbconsole | 3 +++ spec/integration/dbconsole_spec.rb | 4 ++++ spec/unit/dbconsole_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100755 spec/dummy/rails/bin/dbconsole create mode 100644 spec/integration/dbconsole_spec.rb create mode 100644 spec/unit/dbconsole_spec.rb diff --git a/spec/dummy/rails/bin/dbconsole b/spec/dummy/rails/bin/dbconsole new file mode 100755 index 0000000..4fe2a40 --- /dev/null +++ b/spec/dummy/rails/bin/dbconsole @@ -0,0 +1,3 @@ +#! /bin/sh + +echo 'Running psql (or some other db repl)' diff --git a/spec/integration/dbconsole_spec.rb b/spec/integration/dbconsole_spec.rb new file mode 100644 index 0000000..b9c0e79 --- /dev/null +++ b/spec/integration/dbconsole_spec.rb @@ -0,0 +1,4 @@ +RSpec.describe command('cd spec/dummy/rails && nibtest dbconsole web') do + its(:stdout) { should match(/psql/) } + its(:exit_status) { should eq 0 } +end diff --git a/spec/unit/dbconsole_spec.rb b/spec/unit/dbconsole_spec.rb new file mode 100644 index 0000000..0d18b8f --- /dev/null +++ b/spec/unit/dbconsole_spec.rb @@ -0,0 +1,22 @@ +RSpec.describe 'dbconsole' do + let(:service) { 'web' } + let(:command) { './bin/dbconsole -c \'SELECT * FROM foo;\'' } + + subject { Nib::Run.new(service, command) } + + it 'executes ./bin/dbconsole' do + expect(subject.script).to match( + %r{ + docker-compose + .* + run + .* + --rm + .* + #{service} + .* + \./bin/dbconsole\s-c\s'SELECT\s\*\sFROM\sfoo;' + }x + ) + end +end