Skip to content

Commit 0d0bef0

Browse files
committed
gocd#52 chefspec with shared examples for Go server on rhel and debian
we force java to 7 - user does not have to set it anymore removed ubuntu 14.10 and 13.10 from test suites - they are EOF and very similar to LTS anyway
1 parent 92edb55 commit 0d0bef0

9 files changed

+63
-54
lines changed

.kitchen.docker.yml

-30
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ platforms:
2424
- "cd /tmp/fuse ; cat DEBIAN/postinst"
2525
- "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb"
2626
- "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb"
27-
# - name: ubuntu-13.10
28-
# driver:
29-
# provision_command:
30-
# - "apt-get install -y net-tools" # netstat, needed to run specs
31-
# - "apt-get install -y libfuse2"
32-
# - "mkdir -p /tmp/fuse"
33-
# - "cd /tmp/fuse ; apt-get download fuse"
34-
# - "cd /tmp/fuse ; dpkg-deb -x fuse_* ."
35-
# - "cd /tmp/fuse ; dpkg-deb -e fuse_*"
36-
# - "cd /tmp/fuse ; rm fuse_*.deb"
37-
# - "cd /tmp/fuse ; echo '#!/bin/bash\\nexit 0\\n' > DEBIAN/postinst"
38-
# - "cd /tmp/fuse ; cat DEBIAN/postinst"
39-
# - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb"
40-
# - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb"
4127
- name: ubuntu-14.04
4228
driver:
4329
provision_command:
@@ -52,28 +38,12 @@ platforms:
5238
- "cd /tmp/fuse ; cat DEBIAN/postinst"
5339
- "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb"
5440
- "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb"
55-
# - name: ubuntu-14.10
56-
# driver:
57-
# provision_command:
58-
# - "apt-get install -y net-tools" # netstat, needed to run specs
59-
# - "apt-get install -y libfuse2"
60-
# - "mkdir -p /tmp/fuse"
61-
# - "cd /tmp/fuse ; apt-get download fuse"
62-
# - "cd /tmp/fuse ; dpkg-deb -x fuse_* ."
63-
# - "cd /tmp/fuse ; dpkg-deb -e fuse_*"
64-
# - "cd /tmp/fuse ; rm fuse_*.deb"
65-
# - "cd /tmp/fuse ; echo '#!/bin/bash\\nexit 0\\n' > DEBIAN/postinst"
66-
# - "cd /tmp/fuse ; cat DEBIAN/postinst"
67-
# - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb"
68-
# - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb"
6941

7042
suites:
7143
- name: default
7244
run_list:
7345
- recipe[gocd]
7446
attributes:
75-
java:
76-
jdk_version: 7
7747
gocd:
7848
server:
7949
max_mem: '1024m'

.kitchen.openstack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ platforms:
1111
box: 'debian-7.8-bpk-chef-12.4.1'
1212
customize:
1313
server_name: 'kt-go'
14-
flavor: 'p.c1.m1536.d5.e0'
14+
flavor: 'v.c1.m1536.d5.e0'
1515
server_create_timeout: 540
1616
server_active_timeout: 540
1717

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ This cookbook has been tested on the following platforms:
1212
* RedHat >= 6
1313
* Windows - primitive support, but enhancements welcome :)
1414

15+
### Java
16+
17+
Please note that java (>= 7) is needed to run Go server and agents. This cookbook
18+
sets `node['java']['jdk_version']` at `force_default` level but it may not work properly
19+
when you include `java` in node run_list before `gocd` cookbook. The safest approach
20+
is to set java version in node attributes (in a role or environment).
21+
1522
# GoCD Server
1623

1724
gocd::server will install and start a GoCD server.

recipes/agent_linux.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include_recipe 'gocd::repository'
2-
include_recipe "java"
2+
include_recipe "gocd::java"
33

44
package "go-agent" do
55
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately

recipes/java.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# must be early so that java home attrbute gets assigned soon enough
2+
node.force_default['java']['jdk_version'] = '7'
3+
include_recipe 'java'

recipes/server_linux.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include_recipe 'gocd::repository'
2-
include_recipe "java"
2+
include_recipe "gocd::java"
33

44
package "go-server" do
55
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately

spec/go_server_spec.rb

+33-21
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
11
require 'spec_helper'
22

33
describe 'gocd::server' do
4-
describe 'debian' do
5-
let(:chef_run) do
6-
run = ChefSpec::SoloRunner.new do |node|
7-
node.automatic['lsb']['id'] = 'Debian'
8-
node.automatic['platform_family'] = 'debian'
9-
node.automatic['platform'] = 'debian'
10-
node.automatic['os'] = 'linux'
11-
node.normal['java']['jdk_version'] = '7'
12-
end
13-
run.converge(described_recipe)
14-
end
15-
16-
it 'includes apt recipe' do
17-
expect(chef_run).to include_recipe('apt::default')
18-
end
4+
shared_examples_for :server_recipe do
195
it 'includes java recipe' do
206
expect(chef_run).to include_recipe('java::default')
217
end
22-
it 'adds thoughtworks apt repository' do
23-
expect(chef_run).to add_apt_repository('gocd')
24-
end
25-
it 'installs go-server apt package' do
8+
it 'installs go-server package' do
269
expect(chef_run).to install_package('go-server')
2710
end
28-
2911
it 'creates go server configuration in /etc/default/go-server' do
3012
expect(chef_run).to render_file('/etc/default/go-server').with_content { |content|
31-
expect(content).to_not include('java-6-openjdk')
13+
expect(content).to_not include('java-6')
3214
}
3315
end
16+
it 'configures go-server service' do
17+
expect(chef_run).to enable_service('go-server')
18+
expect(chef_run).to start_service('go-server')
19+
end
20+
end
3421

22+
context 'When all attributes are default and platform is debian' do
23+
let(:chef_run) do
24+
run = ChefSpec::SoloRunner.new do |node|
25+
node.automatic['lsb']['id'] = 'Debian'
26+
node.automatic['platform_family'] = 'debian'
27+
node.automatic['platform'] = 'debian'
28+
node.automatic['os'] = 'linux'
29+
end
30+
run.converge(described_recipe)
31+
end
32+
it_behaves_like :server_recipe
33+
it_behaves_like :apt_repository_recipe
34+
end
35+
context 'When all attributes are default and platform is centos' do
36+
let(:chef_run) do
37+
run = ChefSpec::SoloRunner.new do |node|
38+
node.automatic['platform_family'] = 'rhel'
39+
node.automatic['platform'] = 'centos'
40+
node.automatic['os'] = 'linux'
41+
end
42+
run.converge(described_recipe)
43+
end
44+
it_behaves_like :server_recipe
45+
it_behaves_like :yum_repository_recipe
3546
end
47+
#TODO: server on windows
3648
end

spec/shared_examples.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
shared_examples_for :apt_repository_recipe do
2+
it 'includes apt recipe' do
3+
expect(chef_run).to include_recipe('apt')
4+
end
5+
it 'adds gocd apt repository' do
6+
expect(chef_run).to add_apt_repository('gocd')
7+
end
8+
end
9+
shared_examples_for :yum_repository_recipe do
10+
it 'includes yum recipe' do
11+
expect(chef_run).to include_recipe('yum')
12+
end
13+
it 'adds gocd yum repository' do
14+
expect(chef_run).to create_yum_repository('gocd')
15+
end
16+
end

spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
require 'chefspec'
22
require 'chefspec/berkshelf'
3+
require_relative 'shared_examples'
34
ChefSpec::Coverage.start!

0 commit comments

Comments
 (0)