Commit fd71502

mo khan <mo@mokhan.ca>
2015-05-08 03:10:53
add build-essential and tests for postgres.
1 parent d42b00b
recipes/default.rb
@@ -1,4 +1,5 @@
 include_recipe "apt"
+include_recipe "build-essential"
 include_recipe "mokhan-myface::user"
 include_recipe "mokhan-myface::aws"
 include_recipe "mokhan-myface::monit"
recipes/postgres.rb
@@ -0,0 +1,33 @@
+include_recipe "postgresql::server"
+include_recipe "postgresql::contrib"
+include_recipe "database::postgresql"
+
+database = node['postgres']["database"]
+username = node['postgres']['username']
+password = node['postgres']["password"]
+host = node['postgres']['host']
+
+postgresql_connection_info = {
+  host: host,
+  port: 5432,
+  username: 'postgres',
+  password: node['postgresql']['password']['postgres'],
+}
+
+postgresql_database_user username do
+  connection postgresql_connection_info
+  password password
+  action :create
+end
+
+postgresql_database database do
+  connection postgresql_connection_info
+  action :create
+end
+
+postgresql_database_user username do
+  connection postgresql_connection_info
+  database_name database
+  privileges [:all]
+  action :grant
+end
spec/postgres_spec.rb
@@ -0,0 +1,33 @@
+describe "mokhan-myface::postgres" do
+  subject do
+    ChefSpec::SoloRunner.new do |node|
+      node.set["postgres"]["database"] = database_name
+      node.set["postgres"]["host"] = database_host
+      node.set["postgres"]["username"] = database_user
+      node.set["postgresql"]["password"]['postgres'] = database_password
+      node.set["postgresql"]["config"] = {}
+    end.converge(described_recipe)
+  end
+
+  let(:database_name) { FFaker::Internet.user_name }
+  let(:database_host) { "localhost" }
+  let(:database_user) { FFaker::Internet.user_name }
+  let(:database_password) { "password" }
+
+  before :each do
+    stub_command('ls /recovery.conf').and_return(true)
+  end
+
+  it 'creates the specified database' do
+    expect(subject).to create_postgresql_database(database_name)
+  end
+
+  it 'creates the database user' do
+    expect(subject).to create_postgresql_database_user(database_user)
+  end
+
+  it 'grants all privileges to the database user' do
+    expect(subject).to grant_postgresql_database_user(database_user)
+      .with_privileges([:all])
+  end
+end
.kitchen.yml
@@ -18,4 +18,5 @@ suites:
       - recipe[mokhan-myface::unicorn]
       - recipe[mokhan-myface::nodejs]
       - recipe[mokhan-myface::rbenv]
+      - recipe[mokhan-myface::postgres]
     attributes:
Berksfile.lock
@@ -5,5 +5,17 @@ DEPENDENCIES
 
 GRAPH
   apt (2.7.0)
+  build-essential (2.2.3)
+  chef-sugar (3.1.0)
+  database (4.0.6)
+    postgresql (>= 1.0.0)
   mokhan-myface (0.1.0)
     apt (>= 0.0.0)
+    build-essential (>= 0.0.0)
+    database (>= 0.0.0)
+  openssl (4.0.0)
+    chef-sugar (>= 0.0.0)
+  postgresql (3.4.18)
+    apt (>= 1.9.0)
+    build-essential (>= 0.0.0)
+    openssl (~> 4.0.0)
metadata.rb
@@ -7,3 +7,5 @@ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
 version          '0.1.0'
 
 depends "apt"
+depends "build-essential"
+depends "database"