hubcap 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+ require 'rubygems'
3
+ require 'capistrano'
4
+
5
+ class Hubcap::TestHub < Test::Unit::TestCase
6
+
7
+ def test_hub
8
+ hub = Hubcap.hub { application('example') }
9
+ assert_equal(hub, hub.hub)
10
+ end
11
+
12
+
13
+ def test_history
14
+ hub = Hubcap.hub { application('example') }
15
+ assert_equal([], hub.history)
16
+ end
17
+
18
+
19
+ def test_configure_capistrano_in_agnostic_mode
20
+ hub = Hubcap.hub {
21
+ application('a') {
22
+ group('g') {
23
+ role(:baseline)
24
+ server('s') { role(:everything) }
25
+ }
26
+ }
27
+ }
28
+
29
+ cap = Capistrano::Configuration.new
30
+ cap.set(:hubcap_agnostic, true)
31
+ hub.configure_capistrano(cap)
32
+
33
+ assert_equal(hub, cap.hubcap)
34
+ assert_not_nil(cap.find_task('servers:list'))
35
+ assert_not_nil(cap.find_task('puppet:check'))
36
+ assert_nil(cap.find_task('deploy:setup'))
37
+ assert_equal('s', cap.roles[:baseline].servers.first.host)
38
+ assert_equal('s', cap.roles[:everything].servers.first.host)
39
+ end
40
+
41
+
42
+ def test_configure_capistrano_in_application_mode
43
+ hub = Hubcap.hub {
44
+ application('a', :recipes => 'deploy') {
45
+ group('g') {
46
+ cap_set(:branch, 'deploy')
47
+ role(:baseline)
48
+ server('s') { role(:everything) }
49
+ }
50
+ }
51
+ }
52
+
53
+ cap = Capistrano::Configuration.new
54
+ cap.set(:hubcap_agnostic, false)
55
+ hub.configure_capistrano(cap)
56
+
57
+ assert_equal('deploy', cap.branch)
58
+ assert_not_nil(cap.find_task('deploy:setup'))
59
+ end
60
+
61
+
62
+ def test_configure_capistrano_in_application_mode_with_two_applications
63
+ hub = Hubcap.hub {
64
+ role(:baseline)
65
+ application('a1') { server('s1') }
66
+ application('a2') { server('s2') }
67
+ }
68
+
69
+ cap = Capistrano::Configuration.new
70
+ cap.set(:hubcap_agnostic, false)
71
+ assert_raises(Hubcap::ApplicationModeError::TooManyApplications) {
72
+ hub.configure_capistrano(cap)
73
+ }
74
+ end
75
+
76
+
77
+ def test_configure_capistrano_in_application_mode_with_no_applications
78
+ hub = Hubcap.hub { server('s1') { role(:baseline) } }
79
+
80
+ cap = Capistrano::Configuration.new
81
+ cap.set(:hubcap_agnostic, false)
82
+ assert_raises(Hubcap::ApplicationModeError::NoApplications) {
83
+ hub.configure_capistrano(cap)
84
+ }
85
+ end
86
+
87
+
88
+ def test_configure_capistrano_in_application_mode_with_no_applications
89
+ hub = Hubcap.hub {
90
+ cap_set(:foo => 'bar')
91
+ server('s1') {
92
+ cap_set(:foo => 'baz')
93
+ role(:baseline)
94
+ }
95
+ }
96
+
97
+ cap = Capistrano::Configuration.new
98
+ cap.set(:hubcap_agnostic, false)
99
+ assert_raises(Hubcap::ApplicationModeError::DuplicateSets) {
100
+ hub.configure_capistrano(cap)
101
+ }
102
+ end
103
+
104
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class Hubcap::TestHubcap < Test::Unit::TestCase
4
+
5
+ def test_hub
6
+ hub = Hubcap.hub('group2') {
7
+ role(:baseline)
8
+ group('group1') { server('serverA') }
9
+ group('group2') { server('serverB') }
10
+ group('group3') { server('serverC') }
11
+ }
12
+ assert_equal(1, hub.servers.length)
13
+ assert_equal('serverB', hub.servers.last.name)
14
+ assert_equal([:baseline], hub.servers.first.cap_roles)
15
+ end
16
+
17
+
18
+ def test_load
19
+ # Fully specified path to a single file.
20
+ hub = Hubcap.load('', 'test/data/simple.rb')
21
+ assert_equal('simple', hub.groups.first.name)
22
+ assert_equal('localhost', hub.servers.last.name)
23
+
24
+ # You can omit the .rb
25
+ hub = Hubcap.load('', 'test/data/simple')
26
+ assert_equal(1, hub.groups.length)
27
+
28
+ # You can load multiple files.
29
+ hub = Hubcap.load('', 'test/data/simple', 'test/data/example')
30
+ assert_equal(6, hub.groups.length)
31
+
32
+ # You can load a directory (or directories).
33
+ hub = Hubcap.load('', 'test/data')
34
+ assert_equal(11, hub.groups.length)
35
+ # ..but note that Hubcap doesn't recurse into subdirectories:
36
+ assert_equal(nil, hub.params[:foo])
37
+ end
38
+
39
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class Hubcap::TestServer < Test::Unit::TestCase
4
+
5
+ def test_address
6
+ hub = Hubcap.hub { server('test') }
7
+ assert_equal('test', hub.servers.first.address)
8
+ hub = Hubcap.hub { server('test', :address => 'test.example.com') }
9
+ assert_equal('test.example.com', hub.servers.first.address)
10
+ end
11
+
12
+
13
+ def test_subgroups_disallowed
14
+ assert_raises(Hubcap::ServerSubgroupDisallowed) {
15
+ Hubcap.hub { server('test') { application('child') } }
16
+ }
17
+ assert_raises(Hubcap::ServerSubgroupDisallowed) {
18
+ Hubcap.hub { server('test') { server('child') } }
19
+ }
20
+ assert_raises(Hubcap::ServerSubgroupDisallowed) {
21
+ Hubcap.hub { server('test') { group('child') } }
22
+ }
23
+ end
24
+
25
+
26
+ def test_application_parent
27
+ # No application
28
+ hub = Hubcap.hub { server('test') }
29
+ assert_equal(nil, hub.servers.first.application_parent)
30
+
31
+ # Direct inheritance
32
+ hub = Hubcap.hub {
33
+ application('foo') { server('test') }
34
+ application('bar')
35
+ }
36
+ assert_equal('foo', hub.servers.first.application_parent.name)
37
+
38
+ # Grandparent in a complex structure
39
+ hub = Hubcap.hub {
40
+ group('everything') {
41
+ application('baz') {
42
+ group('g1') {
43
+ server('test')
44
+ }
45
+ }
46
+ }
47
+ }
48
+ assert_equal('baz', hub.servers.first.application_parent.name)
49
+ end
50
+
51
+
52
+ def test_yaml
53
+ hub = Hubcap.hub {
54
+ group('everything') {
55
+ role('baseline')
56
+ server('test') {
57
+ role('test::server')
58
+ param('foo' => 1, 'bar' => 2)
59
+ }
60
+ }
61
+ }
62
+ hash = YAML.load(hub.servers.first.yaml)
63
+ assert_equal(['baseline', 'test::server'], hash['classes'])
64
+ assert_equal(['classes', 'parameters'], hash.keys.sort)
65
+ assert_equal(['bar', 'foo'], hash['parameters'].keys.sort)
66
+ assert_equal([1, 2], hash['parameters'].values.sort)
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hubcap
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Joseph Pearson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-09-20 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Unite Capistrano and Puppet config in one Ruby file.
22
+ email:
23
+ - joseph@booki.sh
24
+ executables:
25
+ - hubcap
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Capfile.example
32
+ - README.md
33
+ - Rakefile
34
+ - bin/hubcap
35
+ - hubcap.gemspec
36
+ - lib/hubcap.rb
37
+ - lib/hubcap/application.rb
38
+ - lib/hubcap/group.rb
39
+ - lib/hubcap/hub.rb
40
+ - lib/hubcap/recipes/puppet.rb
41
+ - lib/hubcap/recipes/servers.rb
42
+ - lib/hubcap/server.rb
43
+ - lib/hubcap/version.rb
44
+ - test/data/example.rb
45
+ - test/data/parts/foo_param.rb
46
+ - test/data/readme.rb
47
+ - test/data/simple.rb
48
+ - test/test_helper.rb
49
+ - test/unit/test_application.rb
50
+ - test/unit/test_group.rb
51
+ - test/unit/test_hub.rb
52
+ - test/unit/test_hubcap.rb
53
+ - test/unit/test_server.rb
54
+ has_rdoc: true
55
+ homepage: ""
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Hubcap Capistrano/Puppet extension
84
+ test_files:
85
+ - test/data/example.rb
86
+ - test/data/parts/foo_param.rb
87
+ - test/data/readme.rb
88
+ - test/data/simple.rb
89
+ - test/test_helper.rb
90
+ - test/unit/test_application.rb
91
+ - test/unit/test_group.rb
92
+ - test/unit/test_hub.rb
93
+ - test/unit/test_hubcap.rb
94
+ - test/unit/test_server.rb