machines 0.5.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.
Files changed (180) hide show
  1. data/.gitignore +11 -0
  2. data/EXAMPLES.md +18 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +14 -0
  5. data/INSTALL.md +25 -0
  6. data/LICENSE +23 -0
  7. data/README.md +271 -0
  8. data/Rakefile +60 -0
  9. data/TODO.md +92 -0
  10. data/bin/machines +6 -0
  11. data/lib/machines/app_settings.rb +54 -0
  12. data/lib/machines/base.rb +13 -0
  13. data/lib/machines/checks.rb +63 -0
  14. data/lib/machines/cloud_machine.rb +33 -0
  15. data/lib/machines/command.rb +86 -0
  16. data/lib/machines/commandline.rb +148 -0
  17. data/lib/machines/configuration.rb +49 -0
  18. data/lib/machines/core.rb +117 -0
  19. data/lib/machines/database.rb +17 -0
  20. data/lib/machines/file_operations.rb +104 -0
  21. data/lib/machines/help.rb +30 -0
  22. data/lib/machines/installation.rb +151 -0
  23. data/lib/machines/log_command.rb +22 -0
  24. data/lib/machines/logger.rb +65 -0
  25. data/lib/machines/machinesfile.rb +25 -0
  26. data/lib/machines/named_buffer.rb +9 -0
  27. data/lib/machines/questions.rb +15 -0
  28. data/lib/machines/services.rb +24 -0
  29. data/lib/machines/upload.rb +29 -0
  30. data/lib/machines/version.rb +4 -0
  31. data/lib/machines.rb +19 -0
  32. data/lib/packages/abiword.rb +11 -0
  33. data/lib/packages/amazon_mp3.rb +4 -0
  34. data/lib/packages/awstats.rb +16 -0
  35. data/lib/packages/base.rb +14 -0
  36. data/lib/packages/chrome.rb +12 -0
  37. data/lib/packages/cruisecontrol.rb +22 -0
  38. data/lib/packages/dependencies.rb +10 -0
  39. data/lib/packages/docky.rb +36 -0
  40. data/lib/packages/dotfiles.rb +26 -0
  41. data/lib/packages/file_roller.rb +12 -0
  42. data/lib/packages/finalise.rb +4 -0
  43. data/lib/packages/firefox.rb +4 -0
  44. data/lib/packages/gedit.rb +11 -0
  45. data/lib/packages/git.rb +4 -0
  46. data/lib/packages/gmate.rb +33 -0
  47. data/lib/packages/gnome.rb +10 -0
  48. data/lib/packages/gnumeric.rb +11 -0
  49. data/lib/packages/hosts.rb +13 -0
  50. data/lib/packages/load_machines.rb +38 -0
  51. data/lib/packages/monit.rb +10 -0
  52. data/lib/packages/mysql.rb +46 -0
  53. data/lib/packages/nginx.rb +22 -0
  54. data/lib/packages/nginx_logrotate.rb +26 -0
  55. data/lib/packages/openbox.rb +35 -0
  56. data/lib/packages/passenger.rb +14 -0
  57. data/lib/packages/passenger_nginx.rb +8 -0
  58. data/lib/packages/postfix.rb +10 -0
  59. data/lib/packages/questions.rb +5 -0
  60. data/lib/packages/rbenv.rb +27 -0
  61. data/lib/packages/rvm.rb +20 -0
  62. data/lib/packages/save_machines.rb +4 -0
  63. data/lib/packages/slim.rb +6 -0
  64. data/lib/packages/sqlserver.rb +5 -0
  65. data/lib/packages/subtle.rb +29 -0
  66. data/lib/packages/sudo_mods.rb +6 -0
  67. data/lib/packages/time.rb +6 -0
  68. data/lib/packages/time_daily.rb +5 -0
  69. data/lib/packages/timezone.rb +10 -0
  70. data/lib/packages/unison.rb +5 -0
  71. data/lib/packages/virtualbox.rb +11 -0
  72. data/lib/packages/virtualbox_guest.rb +7 -0
  73. data/lib/packages/webapps.rb +36 -0
  74. data/lib/template/Machinesfile +48 -0
  75. data/lib/template/certificates/example.com.crt +0 -0
  76. data/lib/template/certificates/example.com.key +0 -0
  77. data/lib/template/certificates/selfsigned.crt +14 -0
  78. data/lib/template/certificates/selfsigned.key +16 -0
  79. data/lib/template/config.yml +98 -0
  80. data/lib/template/logrotate/app.erb +10 -0
  81. data/lib/template/logrotate/nginx.erb +12 -0
  82. data/lib/template/machines.yml +179 -0
  83. data/lib/template/misc/awstats.conf.erb +7 -0
  84. data/lib/template/misc/ntp.conf +7 -0
  85. data/lib/template/monit/conf.d/delayed_job.erb +11 -0
  86. data/lib/template/monit/conf.d/mysql.erb +7 -0
  87. data/lib/template/monit/conf.d/nginx +5 -0
  88. data/lib/template/monit/conf.d/postfix +7 -0
  89. data/lib/template/monit/conf.d/ssh +6 -0
  90. data/lib/template/monit/conf.d/system.erb +14 -0
  91. data/lib/template/monit/monitrc.erb +10 -0
  92. data/lib/template/monit/upstart.conf +16 -0
  93. data/lib/template/mysql/dbmaster.cnf +7 -0
  94. data/lib/template/mysql/dbslave.cnf +3 -0
  95. data/lib/template/nginx/app_server.conf.erb +87 -0
  96. data/lib/template/nginx/nginx.conf.erb +46 -0
  97. data/lib/template/nginx/upstart.conf.erb +21 -0
  98. data/lib/template/packages/custom.rb +17 -0
  99. data/lib/template/packages/productivity.rb +18 -0
  100. data/lib/template/slim/themes/dark/background.jpg +0 -0
  101. data/lib/template/slim/themes/dark/panel.png +0 -0
  102. data/lib/template/slim/themes/dark/slim.theme +39 -0
  103. data/lib/template/users/phil/dotfiles/bash_aliases +45 -0
  104. data/lib/template/users/phil/dotfiles/config/Trolltech.conf +4 -0
  105. data/lib/template/users/phil/dotfiles/config/gtk-3.0/settings.ini +9 -0
  106. data/lib/template/users/phil/dotfiles/config/openbox/autostart.sh +14 -0
  107. data/lib/template/users/phil/dotfiles/config/openbox/rc.xml +482 -0
  108. data/lib/template/users/phil/dotfiles/config/terminator/config +10 -0
  109. data/lib/template/users/phil/dotfiles/fonts.conf +15 -0
  110. data/lib/template/users/phil/dotfiles/gitconfig +27 -0
  111. data/lib/template/users/phil/dotfiles/gtkrc-2.0 +16 -0
  112. data/lib/template/users/phil/dotfiles/local/share/applications/mimeapps.list +4 -0
  113. data/lib/template/users/phil/dotfiles/unison/default.prf +33 -0
  114. data/lib/template/users/www/authorized_keys +0 -0
  115. data/lib/template/users/www/dotfiles/bash_aliases +40 -0
  116. data/lib/template/webapps.yml +75 -0
  117. data/machines.gemspec +44 -0
  118. data/spec/acceptance/dev_machine_spec.rb +22 -0
  119. data/spec/lib/machines/app_settings_spec.rb +106 -0
  120. data/spec/lib/machines/checks_spec.rb +105 -0
  121. data/spec/lib/machines/cloud_machine_spec.rb +36 -0
  122. data/spec/lib/machines/command_spec.rb +184 -0
  123. data/spec/lib/machines/commandline_spec.rb +299 -0
  124. data/spec/lib/machines/configuration_spec.rb +61 -0
  125. data/spec/lib/machines/core_spec.rb +299 -0
  126. data/spec/lib/machines/database_spec.rb +51 -0
  127. data/spec/lib/machines/file_operations_spec.rb +124 -0
  128. data/spec/lib/machines/help_spec.rb +22 -0
  129. data/spec/lib/machines/installation_spec.rb +176 -0
  130. data/spec/lib/machines/log_command_spec.rb +16 -0
  131. data/spec/lib/machines/logger_spec.rb +70 -0
  132. data/spec/lib/machines/machinesfile_spec.rb +34 -0
  133. data/spec/lib/machines/questions_spec.rb +73 -0
  134. data/spec/lib/machines/services_spec.rb +26 -0
  135. data/spec/lib/machines/upload_spec.rb +86 -0
  136. data/spec/lib/packages/abiword_spec.rb +20 -0
  137. data/spec/lib/packages/amazon_mp3_spec.rb +17 -0
  138. data/spec/lib/packages/awstats_spec.rb +26 -0
  139. data/spec/lib/packages/base_spec.rb +21 -0
  140. data/spec/lib/packages/chrome_spec.rb +30 -0
  141. data/spec/lib/packages/cruisecontrol_spec.rb +33 -0
  142. data/spec/lib/packages/dependencies_spec.rb +20 -0
  143. data/spec/lib/packages/docky_spec.rb +32 -0
  144. data/spec/lib/packages/dotfiles_spec.rb +44 -0
  145. data/spec/lib/packages/file_roller_spec.rb +69 -0
  146. data/spec/lib/packages/firefox_spec.rb +16 -0
  147. data/spec/lib/packages/gedit_spec.rb +20 -0
  148. data/spec/lib/packages/git_spec.rb +16 -0
  149. data/spec/lib/packages/gmate_spec.rb +39 -0
  150. data/spec/lib/packages/gnome_spec.rb +22 -0
  151. data/spec/lib/packages/gnumeric_spec.rb +21 -0
  152. data/spec/lib/packages/hosts_spec.rb +41 -0
  153. data/spec/lib/packages/load_machines_spec.rb +118 -0
  154. data/spec/lib/packages/monit_spec.rb +34 -0
  155. data/spec/lib/packages/mysql_spec.rb +69 -0
  156. data/spec/lib/packages/nginx_logrotate_spec.rb +80 -0
  157. data/spec/lib/packages/nginx_spec.rb +46 -0
  158. data/spec/lib/packages/openbox_spec.rb +41 -0
  159. data/spec/lib/packages/passenger_nginx_spec.rb +20 -0
  160. data/spec/lib/packages/passenger_spec.rb +26 -0
  161. data/spec/lib/packages/postfix_spec.rb +19 -0
  162. data/spec/lib/packages/questions_spec.rb +29 -0
  163. data/spec/lib/packages/rbenv_spec.rb +32 -0
  164. data/spec/lib/packages/rvm_spec.rb +31 -0
  165. data/spec/lib/packages/save_machines_spec.rb +51 -0
  166. data/spec/lib/packages/slim_spec.rb +22 -0
  167. data/spec/lib/packages/sqlserver_spec.rb +17 -0
  168. data/spec/lib/packages/timezone_spec.rb +27 -0
  169. data/spec/lib/packages/unison_spec.rb +17 -0
  170. data/spec/lib/packages/virtualbox_guest_spec.rb +25 -0
  171. data/spec/lib/packages/virtualbox_spec.rb +23 -0
  172. data/spec/lib/packages/webapps_spec.rb +70 -0
  173. data/spec/spec_helper.rb +103 -0
  174. data/spec/support/coverage.rb +8 -0
  175. data/spec/support/fake_out.rb +22 -0
  176. data/spec/support/fakefs_additions.rb +10 -0
  177. data/spec/support/minitest.rb +69 -0
  178. data/spec/support/vm_control.rb +54 -0
  179. data/tmp/.gitkeep +0 -0
  180. metadata +581 -0
@@ -0,0 +1,124 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'FileOperations' do
4
+ include Machines::FileOperations
5
+ include Machines::Core
6
+
7
+ describe 'append' do
8
+ it 'escapes backslashes (\\)' do
9
+ subject = append '\\', :to => 'file'
10
+ subject.command.must_match /"\\\\"/
11
+ end
12
+
13
+ it 'escapes dollar sign ($)' do
14
+ subject = append '$', :to => 'file'
15
+ subject.command.must_match /"\\\$\"/
16
+ end
17
+
18
+ it 'escapes double quotes (")' do
19
+ subject = append '"', :to => 'file'
20
+ subject.command.must_match /"\\""/
21
+ end
22
+
23
+ it 'escapes backticks (`)' do
24
+ subject = append '`', :to => 'file'
25
+ subject.command.must_match /"\\`"/
26
+ end
27
+
28
+ it 'appends to a file' do
29
+ subject = append 'string', :to => 'file'
30
+ subject.command.must_match /echo ".*" >> file/
31
+ end
32
+
33
+ it 'adds to a file with specified content including escaped characters' do
34
+ subject = append '\\$"`', :to => 'file'
35
+ subject.command.must_equal 'grep "\\\\\\$\\"\\`" file || echo "\\\\\\$\\"\\`" >> file'
36
+ end
37
+
38
+ it 'checks text was added' do
39
+ subject = append 'something', :to => 'file'
40
+ subject.check.must_equal "grep \"something\" file #{echo_result}"
41
+ end
42
+ end
43
+
44
+ describe 'chmod' do
45
+ subject { chmod(644, 'path') }
46
+ it { subject.command.must_equal 'chmod 644 path' }
47
+
48
+ describe 'when mode is a string' do
49
+ subject { chmod('644', 'path') }
50
+ it { subject.command.must_equal 'chmod 644 path' }
51
+ end
52
+ end
53
+
54
+ describe 'chown' do
55
+ it { chown('owner', 'path').command.must_equal 'chown owner:owner path' }
56
+ it { chown('user:group', 'path').command.must_equal 'chown user:group path' }
57
+ end
58
+
59
+ describe 'copy' do
60
+ subject { copy('from', 'to') }
61
+ it { subject.command.must_equal 'cp -rf from to' }
62
+ end
63
+
64
+ describe 'create_from' do
65
+ include Machines::AppSettings
66
+
67
+ it 'loads ERB template, applies settings and writes to remote machine' do
68
+ File.expects(:read).with('erb_path').returns('<%= method_on_binding %>')
69
+ app_builder = AppBuilder.new(:method_on_binding => 'result')
70
+ expects(:write).with('result', {:settings => app_builder, :to => 'file', :name => 'erb_path'})
71
+ create_from('erb_path', :settings => app_builder, :to => 'file')
72
+ end
73
+ end
74
+
75
+ describe 'link' do
76
+ subject { link 'target', 'link' }
77
+ it {subject.command.must_equal 'ln -sf target link'}
78
+ end
79
+
80
+ describe 'mkdir' do
81
+ it 'creates a mkdir command for a single path' do
82
+ mkdir('path').first.command.must_equal 'mkdir -p path'
83
+ end
84
+
85
+ it 'creates a mkdir command for a multiple paths' do
86
+ mkdir('path1', 'path2').map(&:command).must_equal ['mkdir -p path1', 'mkdir -p path2']
87
+ end
88
+
89
+ it 'creates a mkdir command for an array of paths' do
90
+ mkdir(['path1', 'path2']).map(&:command).must_equal ['mkdir -p path1', 'mkdir -p path2']
91
+ end
92
+ end
93
+
94
+ describe 'rename' do
95
+ subject { rename('oldname', 'newname') }
96
+ it { subject.command.must_equal 'mv -f oldname newname' }
97
+ end
98
+
99
+ describe 'remove' do
100
+ subject { remove 'file' }
101
+ it { subject.command.must_equal 'rm -rf file' }
102
+ end
103
+
104
+ describe 'remove_version_info' do
105
+ subject { remove_version_info 'name' }
106
+ it { subject.command.must_equal "find . -maxdepth 1 -name \"name*\" -a -type d | xargs -I xxx mv xxx name" }
107
+ end
108
+
109
+ describe 'replace' do
110
+ subject { replace('something', :with => 'some/path', :in => 'file') }
111
+ it { subject.command.must_equal "sed -i \"s/something/some\\/path/\" file" }
112
+ it { lambda{replace('something')}.must_raise ArgumentError }
113
+ end
114
+
115
+ describe 'write' do
116
+ it 'uploads from a buffer' do
117
+ mock_named_buffer = mock 'NamedBuffer'
118
+ NamedBuffer.expects(:new).with('name', 'something').returns mock_named_buffer
119
+ subject = write('something', :to => 'a_file', :name => 'name')
120
+ subject.local.must_equal mock_named_buffer
121
+ end
122
+ end
123
+ end
124
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Machines::Help do
4
+ subject { Machines::Help.new }
5
+
6
+ describe 'actions' do
7
+ it { subject.actions.must_equal ['htpasswd', 'new', 'dryrun', 'tasks', 'build', 'list', 'packages', 'override'] }
8
+ end
9
+
10
+ describe 'syntax' do
11
+ it 'includes version' do
12
+ subject.syntax.must_match /machines v0\.[0-9]+\.[0-9]+ - Ubuntu\/Ruby configuration tool\./
13
+ end
14
+
15
+ it 'includes syntax' do
16
+ subject.syntax.must_match /machines COMMAND/
17
+ subject.syntax.must_match /COMMAND can be:/
18
+ subject.syntax.must_match /build <machine> \[task\] Builds your chosen machine\. Optionally, build just one task/
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Installation' do
4
+ include Machines::Core
5
+ include Machines::Installation
6
+ include Machines::Configuration
7
+
8
+ describe 'add_ppa' do
9
+ it 'adds a ppa' do
10
+ subject = add_ppa 'user/name', 'key'
11
+ subject.map(&:command).must_equal ['add-apt-repository ppa:user/name', 'apt-get -q -y update > /tmp/apt-update.log']
12
+ end
13
+ end
14
+
15
+ describe 'deb' do
16
+ it 'adds to /etc/apt/sources and add a key' do
17
+ subject = deb 'source', :key => 'gpg', :name => 'name'
18
+ subject.map(&:command).must_equal [
19
+ "echo deb source >> /etc/apt/sources.list",
20
+ "wget -q gpg -O - | apt-key add -",
21
+ "apt-get -q -y update > /tmp/apt-update.log"
22
+ ]
23
+ subject.map(&:check).must_equal [
24
+ "grep \"source\" /etc/apt/sources.list #{echo_result}",
25
+ "apt-key list | grep -i name #{echo_result}",
26
+ "grep \"Reading package lists\" /tmp/apt-update.log #{echo_result}"
27
+ ]
28
+ end
29
+
30
+ it 'modifies echo command to grab the distribution name to be used in the source' do
31
+ subject = deb 'source YOUR_UBUNTU_VERSION_HERE', :key => 'gpg', :name => 'name'
32
+ subject.first.command.must_equal 'expr substr `cat /etc/lsb-release | grep DISTRIB_CODENAME` 18 20 | xargs -I YOUR_UBUNTU_VERSION_HERE echo deb source YOUR_UBUNTU_VERSION_HERE >> /etc/apt/sources.list'
33
+ end
34
+ end
35
+
36
+ describe 'debconf' do
37
+ it 'sends args to debconf-set-selections' do
38
+ subject = debconf 'app', 'setting', 'boolean', true
39
+ subject.command.must_equal 'echo app setting boolean true | debconf-set-selections'
40
+ end
41
+ end
42
+
43
+ describe 'extract' do
44
+ it 'instaniates commands to download, extract and remove a tar archive' do
45
+ subject = extract 'http://url/package.tar'
46
+ subject.command.must_equal 'cd /usr/local/src && wget http://url/package.tar && tar -zxf package.tar && rm package.tar && cd -'
47
+ subject.check.must_equal 'test -d /usr/local/src/package && echo CHECK PASSED || echo CHECK FAILED'
48
+ end
49
+
50
+ it 'instaniates commands to download, extract and remove a zip archive' do
51
+ subject = extract 'http://url/package.zip'
52
+ subject.command.must_equal 'cd /usr/local/src && wget http://url/package.zip && unzip -qq package.zip && rm package.zip && cd -'
53
+ subject.check.must_equal 'test -d /usr/local/src/package && echo CHECK PASSED || echo CHECK FAILED'
54
+ end
55
+
56
+ it 'moves extracted contents to specified folder' do
57
+ subject = extract 'http://url/package-1.0.tar.gz', :to => '/opt'
58
+ subject.command.must_equal 'cd /opt && wget http://url/package-1.0.tar.gz && tar -zxf package-1.0.tar.gz && rm package-1.0.tar.gz && cd -'
59
+ subject.check.must_equal 'test -d /opt/package-1.0 && echo CHECK PASSED || echo CHECK FAILED'
60
+ end
61
+ end
62
+
63
+ describe 'gem' do
64
+ it 'instaniates a command to install a gem' do
65
+ subject = gem 'package'
66
+ subject.command.must_equal 'gem install package'
67
+ end
68
+
69
+ it 'instaniates a command to install a gem with a specified version' do
70
+ subject = gem 'package', :version => '1'
71
+ subject.command.must_equal "gem install package -v \"1\""
72
+ end
73
+ end
74
+
75
+ describe 'gem_update' do
76
+ it 'instaniates a command to update gems' do
77
+ subject = gem_update 'gem'
78
+ subject.command.must_equal 'gem update gem'
79
+ end
80
+ end
81
+
82
+ describe 'git_clone' do
83
+ it 'instaniates a command to clone a git repository' do
84
+ subject = git_clone 'http://git_url.git'
85
+ subject.command.must_equal 'git clone --quiet http://git_url.git'
86
+ end
87
+
88
+ it 'instaniates a command to clone a git repository to a specified folder' do
89
+ subject = git_clone 'http://git_url.git', :to => 'dir'
90
+ subject.command.must_equal 'git clone --quiet http://git_url.git dir'
91
+ end
92
+
93
+ it 'raises when no url supplied' do
94
+ lambda { git_clone '' }.must_raise ArgumentError
95
+ lambda { git_clone nil }.must_raise ArgumentError
96
+ end
97
+
98
+ describe ':branch option' do
99
+ it 'clones to a specific branch' do
100
+ subject = git_clone 'http://git_url.git', :branch => 'other'
101
+ subject.command.must_equal 'git clone --quiet --branch other http://git_url.git'
102
+ end
103
+ end
104
+
105
+ describe ':tag option' do
106
+ it 'checks out a specific tag' do
107
+ subject = git_clone 'http://git_url.git', :to => 'dir', :tag => 'v1.0'
108
+ subject.map(&:command).must_equal [
109
+ 'git clone --quiet http://git_url.git dir',
110
+ 'cd dir && git checkout v1.0'
111
+ ]
112
+ end
113
+
114
+ it 'raises when no dir' do
115
+ lambda { git_clone 'http://git_url.git', :tag => 'v1.0' }.must_raise ArgumentError
116
+ end
117
+ end
118
+ end
119
+
120
+ describe 'install' do
121
+ it 'instaniates commands to download, install and remove a DEB package ' do
122
+ subject = install "http://some.url/package_name.deb"
123
+ subject.map(&:command).must_equal [
124
+ 'cd /tmp && wget http://some.url/package_name.deb && dpkg -i --force-architecture package_name.deb && rm package_name.deb && cd -'
125
+ ]
126
+ end
127
+
128
+ it 'instaniates commands to download, extract, install and remove a group of DEB packages ' do
129
+ subject = install "http://some.url/package_name.tar.gz"
130
+ subject.map(&:command).must_equal [
131
+ 'cd /tmp && wget http://some.url/package_name.tar.gz && tar -zxf package_name.tar.gz && rm package_name.tar.gz && cd -',
132
+ 'cd /tmp/package_name && dpkg -i --force-architecture *.deb && cd - && rm -rf /tmp/package_name'
133
+ ]
134
+ end
135
+
136
+ it 'instaniates a command to install a single apt package' do
137
+ subject = install 'package1'
138
+ subject.map(&:command).must_equal ['apt-get -q -y install package1']
139
+ end
140
+
141
+ it 'instaniates a command to install multiple apt packages' do
142
+ subject = install %w(package1 package2)
143
+ subject.map(&:command).must_equal [
144
+ 'apt-get -q -y install package1',
145
+ 'apt-get -q -y install package2'
146
+ ]
147
+ end
148
+ end
149
+
150
+ describe 'uninstall' do
151
+ it 'instaniates a command to uninstall a package' do
152
+ subject = uninstall %w(apackage)
153
+ subject.map(&:command).must_equal ['apt-get -q -y purge apackage']
154
+ end
155
+ end
156
+
157
+ describe 'update' do
158
+ it 'instaniates a command to update apt' do
159
+ subject = update
160
+ subject.command.must_equal 'apt-get -q -y update > /tmp/apt-update.log'
161
+ end
162
+ end
163
+
164
+ describe 'upgrade' do
165
+ it 'instaniates a command to upgrade apt' do
166
+ subject = upgrade
167
+ subject.map(&:command).must_equal [
168
+ 'apt-get -q -y update',
169
+ 'apt-get -q -y upgrade',
170
+ 'apt-get -q -y autoremove',
171
+ 'apt-get -q -y autoclean'
172
+ ]
173
+ end
174
+ end
175
+ end
176
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Machines::LogCommand do
4
+ subject {Machines::LogCommand.new :name, 'description'}
5
+
6
+ it 'logs the name and description' do
7
+ $conf.commands = [subject]
8
+ subject.run
9
+ $console.next.must_equal "\n"
10
+ $console.next.must_equal colored(" TASK name - description\n", :info)
11
+
12
+ $file.next.must_equal "\n"
13
+ $file.next.must_equal colored("TASK name - description\n", :info)
14
+ end
15
+ end
16
+
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Machines::Logger do
4
+ before(:each) do
5
+ $conf.machine = AppConf.new
6
+ $conf.machine.user = 'www'
7
+ $conf.commands = [1,2,3]
8
+ end
9
+
10
+ describe 'logging to screen' do
11
+ it 'logs first line only' do
12
+ Machines::Command.console.log %(something with "some text\nsome more\nand "lets quote" this one" > and some output)
13
+ $console.next.must_equal %(something with "some text..." > and some output\n)
14
+ end
15
+
16
+ it 'truncates lines longer than screen width' do
17
+ $terminal.stubs(:output_cols).returns 10
18
+ Machines::Command.console.log "A line that's longer than the screen width", :newline => false
19
+ $console.next.must_equal "A line...\r"
20
+ end
21
+ end
22
+
23
+ describe 'logging to file' do
24
+ it 'logs all lines' do
25
+ Machines::Command.file.log %(something with "some text\nsome more\nand "lets quote" this one" > and some output)
26
+ $file.next.must_equal %(something with "some text\nsome more\nand "lets quote" this one" > and some output\n)
27
+ end
28
+ end
29
+
30
+ describe 'log' do
31
+ it 'does not error when no message' do
32
+ Machines::Command.file.log nil
33
+ $file.next.must_equal "(no message)\n"
34
+ end
35
+
36
+ it 'returns to the beginning of the line when no newline' do
37
+ Machines::Command.console.log 'message', :newline => false
38
+ $console.next.must_equal "message\r"
39
+ end
40
+
41
+ it 'sends the command and line number' do
42
+ Machines::Command.file.log 'command'
43
+ $file.next.must_equal "command\n"
44
+ end
45
+
46
+ it 'displays message in specified color' do
47
+ Machines::Command.file.log 'command', :color => :yellow
48
+ $file.next.must_equal colored("command\n", :yellow)
49
+ end
50
+
51
+ it 'does not show passwords' do
52
+ $conf.passwords = ['a_password', 'another password']
53
+ Machines::Command.file.log 'something with a_password and another password in'
54
+ $file.next.must_equal "something with ***** and ***** in\n"
55
+ end
56
+
57
+ it 'displays newline when empty message' do
58
+ Machines::Command.file.log ''
59
+ $file.next.must_equal "\n"
60
+ end
61
+
62
+ it 'flushes the file' do
63
+ mock_file = mock 'File'
64
+ subject = Machines::Logger.new(mock_file)
65
+ mock_file.expects(:flush)
66
+ subject.flush
67
+ end
68
+ end
69
+ end
70
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Machinesfile' do
4
+ include Machines::Machinesfile
5
+
6
+ describe 'package' do
7
+ it 'raises specific error when failing to load Machinesfile' do
8
+ File.expects(:read).never
9
+ lambda{ package 'Machinesfile' }.must_raise LoadError, /Cannot find Machinesfile/
10
+ end
11
+
12
+ it 'loads custom package when it exists' do
13
+ custom_package = "packages/custom_package.rb"
14
+ FileUtils.mkdir_p File.dirname(custom_package)
15
+ FileUtils.touch custom_package
16
+ File.expects(:read).with(custom_package).returns ''
17
+ package :custom_package
18
+ end
19
+
20
+ it 'loads built-in package when no custom package' do
21
+ builtin_package = "#{$conf.application_dir}/packages/builtin_package.rb"
22
+ FileUtils.mkdir_p File.dirname(builtin_package)
23
+ FileUtils.touch builtin_package
24
+ File.expects(:read).with(builtin_package).returns ''
25
+ package :builtin_package
26
+ end
27
+
28
+ it 'raises when no custom and no built-in package' do
29
+ File.expects(:read).never
30
+ lambda { package :builtin_package}.must_raise LoadError, /Cannot find .* package builtin_package/
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Questions' do
4
+ include Machines::Questions
5
+
6
+ describe 'enter_password' do
7
+ before(:each) do
8
+ stubs(:ask).returns 'pa55word'
9
+ end
10
+
11
+ it 'does not echo output' do
12
+ mock_question = mock 'HighLine::Question'
13
+ mock_question.expects(:echo=).with(false).twice
14
+ stubs(:ask).yields(mock_question).returns 'pa55word'
15
+ enter_password 'type'
16
+ end
17
+
18
+ it 'prompts for a password' do
19
+ expects(:ask).with('Enter type password: ').once.returns 'pa55word'
20
+ enter_password('type')
21
+ end
22
+
23
+ it 'returns password' do
24
+ enter_password('type').must_equal 'pa55word'
25
+ end
26
+
27
+ it 'adds to password list' do
28
+ enter_password('type')
29
+ $conf.passwords.must_equal ['pa55word']
30
+ end
31
+
32
+ it 'does not add password less than 5 characters to password list' do
33
+ stubs(:ask).returns 'pass'
34
+ enter_password('type')
35
+ $conf.passwords.must_equal []
36
+ end
37
+
38
+ it 'does not add password if it is "password"' do
39
+ stubs(:ask).returns 'password'
40
+ enter_password('type')
41
+ $conf.passwords.must_equal []
42
+ end
43
+
44
+ it 'repeats until password and confirmation match' do
45
+ expects(:ask).with('Enter type password: ').twice.returns 'pa55word'
46
+ expects(:ask).with('Confirm the password: ').twice.returns 'pas', 'pa55word'
47
+ expects(:say).with('Passwords do not match, please re-enter')
48
+ enter_password('type').must_equal 'pa55word'
49
+ end
50
+
51
+ it 'only asks once when confirm set to false' do
52
+ expects(:ask).with('Enter type password: ').once.returns 'pa55word'
53
+ expects(:ask).with('Confirm the password: ').never
54
+ enter_password('type', false)
55
+ end
56
+
57
+ it 'password still added to list when not confirming' do
58
+ enter_password('type', false)
59
+ $conf.passwords.must_equal ['pa55word']
60
+ end
61
+
62
+ it 'password still returned when not confirming' do
63
+ enter_password('type', false).must_equal 'pa55word'
64
+ end
65
+
66
+ it 'do not add to passwords list if not available' do
67
+ $conf.passwords = nil
68
+ enter_password('type')
69
+ $conf.passwords.must_equal nil
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Services' do
4
+ include Machines::Core
5
+ include Machines::FileOperations
6
+ include Machines::Services
7
+
8
+ describe 'restart' do
9
+ subject { restart 'daemon' }
10
+ it { subject.command.must_equal 'service daemon restart' }
11
+ end
12
+
13
+ describe 'start' do
14
+ it 'start daemon and check it runs' do
15
+ subject = start 'daemon'
16
+ subject.command.must_equal 'service daemon start'
17
+ subject.check.must_equal 'ps aux | grep daemon | grep -v grep && echo CHECK PASSED || echo CHECK FAILED'
18
+ end
19
+
20
+ it 'start daemon with custom check' do
21
+ subject = start 'daemon', :check => 'check'
22
+ subject.check.must_equal 'check'
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe Machines::Upload do
4
+ subject { Machines::Upload.new('local', 'remote', 'check') }
5
+
6
+ describe 'initialize' do
7
+ it 'sets line, local, remote and check' do
8
+ subject.command.must_equal nil
9
+ subject.local.must_equal 'local'
10
+ subject.remote.must_equal 'remote'
11
+ subject.check.must_equal 'check'
12
+ end
13
+ end
14
+
15
+ describe 'run' do
16
+ before(:each) do
17
+ $conf.commands = [subject]
18
+ $conf.log_only = false
19
+ @mock_ssh = mock 'Net::SSH'
20
+ @mock_scp = stub 'Net::SCP'
21
+ Machines::Command.ssh = @mock_ssh
22
+ Machines::Command.scp = @mock_scp
23
+ @mock_ssh.stubs(:exec!).with('export TERM=linux && check').returns "CHECK PASSED"
24
+ end
25
+
26
+ it 'uploads local to remote with logging' do
27
+ @mock_scp.expects(:upload!).with('local', 'remote', {:recursive => false})
28
+ subject.run
29
+
30
+ $file.next.must_equal colored("UPLOAD local to remote\n", :highlight)
31
+ $file.next.must_equal colored("CHECK PASSED\n", :success)
32
+ $console.next.must_equal "100% UPLOAD local to remote\r"
33
+ $console.next.must_equal colored("100% UPLOAD local to remote\n", :success)
34
+ end
35
+
36
+ it 'logs with newline when logging only' do
37
+ @mock_scp.stubs(:upload!)
38
+ $conf.log_only = true
39
+ subject.run
40
+
41
+ $console.next.must_equal "100% UPLOAD local to remote\n"
42
+ end
43
+
44
+ it 'logs with return when log_only not specified' do
45
+ @mock_scp.stubs(:upload!)
46
+ $conf.log_only = nil
47
+ subject.run
48
+
49
+ $console.next.must_equal "100% UPLOAD local to remote\r"
50
+ end
51
+
52
+ it 'uploads a folder source' do
53
+ FileUtils.mkdir_p('local')
54
+ @mock_scp.expects(:upload!).with('local', 'remote', {:recursive => true})
55
+
56
+ subject.run
57
+ end
58
+
59
+ it 'uploads an in memory buffer' do
60
+ buffer = NamedBuffer.new('name', 'a buffer')
61
+ subject = Machines::Upload.new(buffer, 'remote', 'check')
62
+ $conf.commands = [subject]
63
+ @mock_scp.expects(:upload!).with(buffer, 'remote', {:recursive => false})
64
+ subject.run
65
+ end
66
+ end
67
+
68
+ describe 'info' do
69
+ it 'contains source and destination paths and UPLOAD' do
70
+ subject.info.must_equal 'UPLOAD local to remote'
71
+ end
72
+
73
+ describe 'when local is a buffer' do
74
+ subject { Machines::Upload.new(NamedBuffer.new('name', 'a buffer'), 'remote', 'check') }
75
+ it 'contains name of the buffer' do
76
+ subject.info.must_equal 'UPLOAD buffer from name to remote'
77
+ end
78
+
79
+ it 'handles nil names' do
80
+ subject = Machines::Upload.new(NamedBuffer.new(nil, 'a buffer'), 'remote', 'check')
81
+ subject.info.must_equal "UPLOAD unnamed buffer to remote"
82
+ end
83
+ end
84
+ end
85
+ end
86
+
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'packages/apps' do
4
+ before(:each) do
5
+ load_package('abiword')
6
+ end
7
+
8
+ it 'adds the following commands' do
9
+ eval_package
10
+ $conf.commands.map(&:info).must_equal [
11
+ "TASK abiword - Install a lightweight word processor",
12
+ "SUDO apt-get -q -y install abiword",
13
+ "TASK abiword_associations - Setup file associations for Abiword",
14
+ "RUN grep \"application/x-abiword=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/x-abiword=abiword.desktop\" >> .local/share/applications/mimeapps.list",
15
+ "RUN grep \"application/msword=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/msword=abiword.desktop\" >> .local/share/applications/mimeapps.list",
16
+ "RUN grep \"application/rtf=abiword.desktop\" .local/share/applications/mimeapps.list || echo \"application/rtf=abiword.desktop\" >> .local/share/applications/mimeapps.list"
17
+ ]
18
+ end
19
+ end
20
+
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'packages/amazon_mp3' do
4
+ before(:each) do
5
+ load_package('amazon_mp3')
6
+ end
7
+
8
+ it 'adds the following commands' do
9
+ eval_package
10
+ $conf.commands.map(&:info).must_equal [
11
+ "TASK amazon_mp3 - Download and install MP3 downloader from Amazon",
12
+ "SUDO cd /tmp && wget http://www.hilltopyodeler.com/packages/AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && tar -zxf AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && rm AmazonMP3-InstallerForUbuntuNewerThan-9.04.tar.gz && cd -",
13
+ "SUDO cd /tmp/AmazonMP3-InstallerForUbuntuNewerThan-9.04 && dpkg -i --force-architecture *.deb && cd - && rm -rf /tmp/AmazonMP3-InstallerForUbuntuNewerThan-9.04"
14
+ ]
15
+ end
16
+ end
17
+