diff --git a/.travis.yml b/.travis.yml
index 06c39f4..25e19ee 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,4 +2,5 @@
script: "./script/cibuild"
gemfile: "this/does/not/exist"
rvm:
- - "1.8.7"
\ No newline at end of file
+ - "1.8.7"
+ - "1.9.3"
diff --git a/Gemfile.lock b/Gemfile.lock
index 07416a0..f63f5ca 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -3,7 +3,7 @@ GEM
specs:
addressable (2.3.5)
ansi (1.4.3)
- boxen (1.4.2)
+ boxen (1.5.2)
ansi (~> 1.4)
hiera (~> 1.0)
highline (~> 1.6)
@@ -17,9 +17,9 @@ GEM
puppetlabs_spec_helper (~> 0.4)
rspec-puppet (~> 0.1)
diff-lcs (1.2.4)
- facter (1.7.1)
- faraday (0.8.7)
- multipart-post (~> 1.1)
+ facter (1.7.2)
+ faraday (0.8.8)
+ multipart-post (~> 1.2.0)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
hashie (2.0.5)
@@ -28,26 +28,26 @@ GEM
highline (1.6.19)
json (1.8.0)
json_pure (1.8.0)
- librarian-puppet (0.9.9)
+ librarian-puppet (0.9.10)
json
thor (~> 0.15)
metaclass (0.0.1)
mocha (0.14.0)
metaclass (~> 0.0.1)
- multi_json (1.7.7)
+ multi_json (1.7.9)
multipart-post (1.2.0)
netrc (0.7.7)
- octokit (1.24.0)
+ octokit (1.25.0)
addressable (~> 2.2)
faraday (~> 0.8)
faraday_middleware (~> 0.9)
hashie (~> 2.0)
multi_json (~> 1.3)
netrc (~> 0.7.7)
- puppet (3.2.2)
+ puppet (3.2.4)
facter (~> 1.6)
hiera (~> 1.0)
- rgen (~> 0.6)
+ rgen (~> 0.6.5)
puppet-lint (0.3.2)
puppetlabs_spec_helper (0.4.1)
mocha (>= 0.10.5)
@@ -56,14 +56,14 @@ GEM
rspec-puppet (>= 0.1.1)
rake (10.1.0)
rgen (0.6.5)
- rspec (2.13.0)
- rspec-core (~> 2.13.0)
- rspec-expectations (~> 2.13.0)
- rspec-mocks (~> 2.13.0)
- rspec-core (2.13.1)
- rspec-expectations (2.13.0)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.2)
diff-lcs (>= 1.1.3, < 2.0)
- rspec-mocks (2.13.1)
+ rspec-mocks (2.14.3)
rspec-puppet (0.1.6)
rspec
thor (0.18.1)
diff --git a/README.md b/README.md
index fa1382b..a21f17d 100644
--- a/README.md
+++ b/README.md
@@ -20,3 +20,6 @@ postgresql::db { 'mydb': }
* `sysctl`
*Note: Boxen runs most services on non-standard ports as to not collide with existing local installs. Boxen Postgresql runs on 15432 as opposed to the standard 5432.*
+
+Then write some code. Run `script/cibuild` to test it. Check the `script`
+directory for other useful tools.
diff --git a/manifests/config.pp b/manifests/config.pp
index 3cdf047..fba6022 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -1,3 +1,8 @@
+# Internal: Configure postgresql.
+#
+# Examples
+#
+# include postgresql::config
class postgresql::config {
require boxen::config
diff --git a/manifests/db.pp b/manifests/db.pp
index 097c2f0..de930b7 100644
--- a/manifests/db.pp
+++ b/manifests/db.pp
@@ -1,3 +1,8 @@
+# Creates a new postgresql database.
+#
+# Usage:
+#
+# postgresql::db { 'mydb': }
define postgresql::db($ensure = present) {
require postgresql
@@ -6,7 +11,7 @@
'createdb',
"-p${postgresql::config::port}",
'-E UTF-8',
- "-O ${::luser}",
+ "-O ${::boxen_user}",
$name
], ' '),
require => Exec['wait-for-postgresql'],
diff --git a/manifests/init.pp b/manifests/init.pp
index 485b8d8..5908f42 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,3 +1,8 @@
+# Public: Install and configure postgresql from homebrew.
+#
+# Examples
+#
+# include postgresql
class postgresql {
include postgresql::config
include homebrew
diff --git a/spec/classes/postgresql_config_spec.rb b/spec/classes/postgresql_config_spec.rb
new file mode 100644
index 0000000..8eff9b8
--- /dev/null
+++ b/spec/classes/postgresql_config_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe 'postgresql::config' do
+ let(:facts) { default_test_facts }
+
+ it do
+ should include_class('boxen::config')
+ end
+end
diff --git a/spec/classes/postgresql_spec.rb b/spec/classes/postgresql_spec.rb
new file mode 100644
index 0000000..448626a
--- /dev/null
+++ b/spec/classes/postgresql_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe 'postgresql' do
+ let(:facts) { default_test_facts }
+
+ it do
+ should include_class('postgresql::config')
+ should include_class('homebrew')
+ should include_class('sysctl')
+
+ ['data', 'log'].each do |dir|
+ should contain_file("/test/boxen/#{dir}/postgresql").with({
+ :ensure => 'directory',
+ })
+ end
+
+ should contain_file('/Library/LaunchDaemons/dev.postgresql.plist').with({
+ :content => File.read('spec/fixtures/dev.postgresql.plist'),
+ :group => 'wheel',
+ :notify => 'Service[dev.postgresql]',
+ :owner => 'root',
+ })
+
+ should contain_sysctl__set('kern.sysv.shmmax').with({
+ :value => 1610612736
+ })
+
+ should contain_sysctl__set('kern.sysv.shmall').with({
+ :value => 393216
+ })
+
+ should contain_homebrew__formula('postgresql').
+ with_before('Package[boxen/brews/postgresql]')
+
+ should contain_package('boxen/brews/postgresql').with({
+ :ensure => '9.2.4-boxen2',
+ :notify => 'Service[dev.postgresql]'
+ })
+
+ should contain_exec('init-postgresql-db').with({
+ :command => 'initdb -E UTF-8 /test/boxen/data/postgresql',
+ :creates => '/test/boxen/data/postgresql/PG_VERSION',
+ :require => 'Package[boxen/brews/postgresql]'
+ })
+
+ should contain_service('dev.postgresql').with({
+ :ensure => 'running',
+ :require => 'Exec[init-postgresql-db]'
+ })
+
+ should contain_service('com.boxen.postgresql').with({
+ :ensure => nil,
+ :before => 'Service[dev.postgresql]'
+ })
+
+ should contain_file('/test/boxen/env.d/postgresql.sh').with({
+ :content => File.read('spec/fixtures/postgresql.sh'),
+ :require => 'File[/test/boxen/env.d]'
+ })
+
+ should contain_exec('wait-for-postgresql').with({
+ :command => 'while ! nc -z localhost 15432; do sleep 1; done',
+ :provider => 'shell',
+ :timeout => 30,
+ :unless => 'nc -z localhost 15432',
+ :require => 'Service[dev.postgresql]'
+ })
+ end
+end
diff --git a/spec/defines/postgresql_db_spec.rb b/spec/defines/postgresql_db_spec.rb
new file mode 100644
index 0000000..5304638
--- /dev/null
+++ b/spec/defines/postgresql_db_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe "postgresql::db" do
+ let(:facts) { default_test_facts }
+ let(:title) { 'testdb' }
+
+ it do
+ should include_class("postgresql")
+
+ should contain_exec("postgresql-db-#{title}").with({
+ :command => "createdb -p15432 -E UTF-8 -O testuser #{title}",
+ :require => 'Exec[wait-for-postgresql]',
+ :unless => "psql -aA -p15432 -t -l | cut -d \\| -f 1 | grep -w '#{title}'"
+ })
+ end
+end
diff --git a/spec/fixtures/Puppetfile b/spec/fixtures/Puppetfile
new file mode 100644
index 0000000..81de176
--- /dev/null
+++ b/spec/fixtures/Puppetfile
@@ -0,0 +1,5 @@
+mod 'boxen', '3.0.2', :github_tarball => 'boxen/puppet-boxen'
+mod 'homebrew', '1.4.1', :github_tarball => "boxen/puppet-homebrew"
+mod 'respository', '2.2.0', :github_tarball => "boxen/puppet-repository"
+mod 'stdlib', '4.1.0', :github_tarball => "puppetlabs/puppetlabs-stdlib"
+mod 'sysctl', '1.0.0', :github_tarball => "boxen/puppet-sysctl"
diff --git a/spec/fixtures/dev.postgresql.plist b/spec/fixtures/dev.postgresql.plist
new file mode 100644
index 0000000..d061eac
--- /dev/null
+++ b/spec/fixtures/dev.postgresql.plist
@@ -0,0 +1,46 @@
+
+
+
+
+ Label
+ dev.postgresql
+
+ Boxen
+
+ Description
+ A tolerably okay relational database.
+
+ Port
+ 15432
+
+
+ ProgramArguments
+
+ /test/boxen/homebrew/bin/postgres
+ -p
+ 15432
+ -D
+ /test/boxen/data/postgresql
+ -r
+ /test/boxen/log/postgresql/server.log
+
+
+ RunAtLoad
+
+
+ KeepAlive
+
+
+ UserName
+ testuser
+
+ WorkingDirectory
+ /test/boxen/data/postgresql
+
+ StandardErrorPath
+ /test/boxen/log/postgresql/console.log
+
+ StandardOutPath
+ /test/boxen/log/postgresql/console.log
+
+
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
diff --git a/spec/fixtures/modules/postgresql/manifests b/spec/fixtures/modules/postgresql/manifests
new file mode 120000
index 0000000..373b992
--- /dev/null
+++ b/spec/fixtures/modules/postgresql/manifests
@@ -0,0 +1 @@
+../../../../manifests
\ No newline at end of file
diff --git a/spec/fixtures/modules/postgresql/templates b/spec/fixtures/modules/postgresql/templates
new file mode 120000
index 0000000..f8a06d1
--- /dev/null
+++ b/spec/fixtures/modules/postgresql/templates
@@ -0,0 +1 @@
+../../../../templates
\ No newline at end of file
diff --git a/spec/fixtures/postgresql.sh b/spec/fixtures/postgresql.sh
new file mode 100644
index 0000000..4c4b5bf
--- /dev/null
+++ b/spec/fixtures/postgresql.sh
@@ -0,0 +1,10 @@
+# Postgres config vars
+
+export BOXEN_POSTGRESQL_PORT=15432
+export BOXEN_POSTGRESQL_URL="postgres://localhost:$BOXEN_POSTGRESQL_PORT/"
+
+# soft global overrides
+
+[ -z "$PGPORT" ] && {
+ export PGPORT=$BOXEN_POSTGRESQL_PORT
+}
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..f8e08e2
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,15 @@
+require "rspec-puppet"
+
+fixture_path = File.expand_path File.join(__FILE__, "..", "fixtures")
+
+RSpec.configure do |c|
+ c.manifest_dir = File.join(fixture_path, "manifests")
+ c.module_path = File.join(fixture_path, "modules")
+end
+
+def default_test_facts
+ {
+ :boxen_home => "/test/boxen",
+ :boxen_user => "testuser"
+ }
+end
diff --git a/templates/dev.postgresql.plist.erb b/templates/dev.postgresql.plist.erb
index 297c583..a1fd917 100644
--- a/templates/dev.postgresql.plist.erb
+++ b/templates/dev.postgresql.plist.erb
@@ -32,7 +32,7 @@
UserName
- <%= scope.lookupvar "::luser" %>
+ <%= scope.lookupvar "::boxen_user" %>
WorkingDirectory
<%= scope.lookupvar "postgresql::config::datadir" %>
diff --git a/templates/env.sh.erb b/templates/env.sh.erb
index ee10ee7..06f29c0 100644
--- a/templates/env.sh.erb
+++ b/templates/env.sh.erb
@@ -7,4 +7,4 @@ export BOXEN_POSTGRESQL_URL="postgres://localhost:$BOXEN_POSTGRESQL_PORT/"
[ -z "$PGPORT" ] && {
export PGPORT=$BOXEN_POSTGRESQL_PORT
-}
\ No newline at end of file
+}