Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
script: "./script/cibuild"
gemfile: "this/does/not/exist"
rvm:
- "1.8.7"
- "1.8.7"
- "1.9.3"
32 changes: 16 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Internal: Configure postgresql.
#
# Examples
#
# include postgresql::config
class postgresql::config {
require boxen::config

Expand Down
7 changes: 6 additions & 1 deletion manifests/db.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Creates a new postgresql database.
#
# Usage:
#
# postgresql::db { 'mydb': }
define postgresql::db($ensure = present) {
require postgresql

Expand All @@ -6,7 +11,7 @@
'createdb',
"-p${postgresql::config::port}",
'-E UTF-8',
"-O ${::luser}",
"-O ${::boxen_user}",
$name
], ' '),
require => Exec['wait-for-postgresql'],
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Public: Install and configure postgresql from homebrew.
#
# Examples
#
# include postgresql
class postgresql {
include postgresql::config
include homebrew
Expand Down
9 changes: 9 additions & 0 deletions spec/classes/postgresql_config_spec.rb
Original file line number Diff line number Diff line change
@@ -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
69 changes: 69 additions & 0 deletions spec/classes/postgresql_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/defines/postgresql_db_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/fixtures/Puppetfile
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 46 additions & 0 deletions spec/fixtures/dev.postgresql.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>

<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.postgresql</string>

<key>Boxen</key>
<dict>
<key>Description</key>
<string>A tolerably okay relational database.</string>

<key>Port</key>
<integer>15432</integer>
</dict>

<key>ProgramArguments</key>
<array>
<string>/test/boxen/homebrew/bin/postgres</string>
<string>-p</string>
<string>15432</string>
<string>-D</string>
<string>/test/boxen/data/postgresql</string>
<string>-r</string>
<string>/test/boxen/log/postgresql/server.log</string>
</array>

<key>RunAtLoad</key>
<true />

<key>KeepAlive</key>
<true />

<key>UserName</key>
<string>testuser</string>

<key>WorkingDirectory</key>
<string>/test/boxen/data/postgresql</string>

<key>StandardErrorPath</key>
<string>/test/boxen/log/postgresql/console.log</string>

<key>StandardOutPath</key>
<string>/test/boxen/log/postgresql/console.log</string>
</dict>
</plist>
Empty file added spec/fixtures/manifests/site.pp
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/modules/postgresql/manifests
1 change: 1 addition & 0 deletions spec/fixtures/modules/postgresql/templates
10 changes: 10 additions & 0 deletions spec/fixtures/postgresql.sh
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion templates/dev.postgresql.plist.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<true />

<key>UserName</key>
<string><%= scope.lookupvar "::luser" %></string>
<string><%= scope.lookupvar "::boxen_user" %></string>

<key>WorkingDirectory</key>
<string><%= scope.lookupvar "postgresql::config::datadir" %></string>
Expand Down
2 changes: 1 addition & 1 deletion templates/env.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export BOXEN_POSTGRESQL_URL="postgres://localhost:$BOXEN_POSTGRESQL_PORT/"

[ -z "$PGPORT" ] && {
export PGPORT=$BOXEN_POSTGRESQL_PORT
}
}