vagrant-notify 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/Gemfile.lock +5 -2
- data/README.md +10 -19
- data/lib/vagrant-notify/middleware/install_command.rb +3 -1
- data/lib/vagrant-notify/middleware/start_server.rb +41 -11
- data/lib/vagrant-notify/middleware/stop_server.rb +7 -2
- data/lib/vagrant-notify/server.rb +49 -13
- data/lib/vagrant-notify/vagrant_ssh_ext.rb +22 -0
- data/lib/vagrant-notify/version.rb +1 -1
- data/lib/vagrant-notify.rb +13 -10
- data/spec/middleware/install_command_spec.rb +10 -1
- data/spec/middleware/start_server_spec.rb +26 -10
- data/spec/middleware/stop_server_spec.rb +10 -4
- data/spec/server_spec.rb +52 -3
- data/spec/spec_helper.rb +1 -0
- data/vagrant-notify.gemspec +2 -2
- metadata +33 -16
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vagrant-notify (0.0
|
5
|
-
vagrant
|
4
|
+
vagrant-notify (0.1.0)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
@@ -37,6 +36,8 @@ GEM
|
|
37
36
|
rspec-expectations (2.11.3)
|
38
37
|
diff-lcs (~> 1.1.3)
|
39
38
|
rspec-mocks (2.11.3)
|
39
|
+
rspec-spies (2.1.3)
|
40
|
+
rspec (~> 2.0)
|
40
41
|
thor (0.16.0)
|
41
42
|
vagrant (1.0.5)
|
42
43
|
archive-tar-minitar (= 0.5.2)
|
@@ -57,4 +58,6 @@ DEPENDENCIES
|
|
57
58
|
rake
|
58
59
|
rb-inotify
|
59
60
|
rspec
|
61
|
+
rspec-spies
|
62
|
+
vagrant
|
60
63
|
vagrant-notify!
|
data/README.md
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
# Vagrant::Notify
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/fgrehm/vagrant-notify.png)](https://travis-ci.org/fgrehm/vagrant-notify)
|
4
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/fgrehm/vagrant-notify)
|
4
5
|
|
5
6
|
A Vagrant plugin that forwards `notify-send` from guest to host machine, tested
|
6
7
|
using Ubuntu as guest and host machine.
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
10
|
-
|
11
|
+
If you use the gem version of Vagrant, use:
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
$ bundle
|
13
|
+
```terminal
|
14
|
+
$ gem install vagrant-notify
|
15
|
+
```
|
17
16
|
|
18
|
-
|
17
|
+
otherwise, use:
|
19
18
|
|
20
|
-
|
19
|
+
```terminal
|
20
|
+
$ vagrant gem install vagrant-notify
|
21
|
+
```
|
21
22
|
|
22
23
|
## Usage
|
23
24
|
|
@@ -27,22 +28,12 @@ will fire up on `8081` port and a [script](https://github.com/fgrehm/vagrant-not
|
|
27
28
|
will be installed on the guest machine to replace the original `notify-send`
|
28
29
|
command.
|
29
30
|
|
30
|
-
If by any
|
31
|
+
If by any chance your IP changes, you can run `vagrant provision` in order to
|
31
32
|
update the guest script with the new IP.
|
32
33
|
|
33
|
-
In case you need to run the notification server on a different port, you can set
|
34
|
-
it from your `Vagrantfile`:
|
35
34
|
|
36
|
-
```ruby
|
37
|
-
Vagrant::Notify::server_port = 8888
|
38
|
-
```
|
39
35
|
|
40
|
-
## TODO
|
41
36
|
|
42
|
-
* Display guest machine icons
|
43
|
-
* Support for Multi-VM environments
|
44
|
-
* Notify provisioning status
|
45
|
-
* Support for Mac OS
|
46
37
|
|
47
38
|
## Contributing
|
48
39
|
|
@@ -25,7 +25,9 @@ module Vagrant
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def compile_command(env)
|
28
|
-
|
28
|
+
uuid = env[:vm].uuid.to_s
|
29
|
+
local_data = env[:vm].env.local_data
|
30
|
+
host_port = local_data['vagrant-notify'][uuid]['port']
|
29
31
|
template_binding = OpenStruct.new(:host_ip => host_ip(env), :host_port => host_port)
|
30
32
|
command = ERB.new(File.read(@command_template_file)).result(template_binding.instance_eval { binding })
|
31
33
|
File.open(env[:vm].env.tmp_path + 'vagrant-notify-send', 'w') { |f| f.write(command) }
|
@@ -7,11 +7,12 @@ module Vagrant
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
10
|
-
|
10
|
+
@env = env
|
11
|
+
if pid = server_is_running?
|
11
12
|
env[:ui].info "Notification server is already running (#{pid})"
|
12
13
|
else
|
13
|
-
pid = run_server
|
14
|
-
env[:ui].info "Notification server
|
14
|
+
port, pid = run_server
|
15
|
+
env[:ui].info "Notification server is listening on #{port} (#{pid})"
|
15
16
|
end
|
16
17
|
|
17
18
|
@app.call(env)
|
@@ -19,21 +20,50 @@ module Vagrant
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
def run_server
|
23
|
-
|
23
|
+
def run_server
|
24
|
+
port = next_available_port
|
25
|
+
uuid = @env[:vm].uuid.to_s
|
26
|
+
pid = Server.run(@env, port)
|
24
27
|
|
25
|
-
local_data = env[:vm].env.local_data
|
26
|
-
local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
|
27
|
-
|
28
|
+
local_data = @env[:vm].env.local_data
|
29
|
+
config = local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
|
30
|
+
config.merge!(uuid => {'pid' => pid, 'port' => port })
|
28
31
|
local_data.commit
|
29
32
|
|
30
|
-
pid
|
33
|
+
[port, pid]
|
34
|
+
end
|
35
|
+
|
36
|
+
def next_available_port
|
37
|
+
range = @env[:vm].config.vm.auto_port_range.to_a
|
38
|
+
range -= @env[:vm].config.vm.forwarded_ports.collect { |opts| opts[:hostport].to_i }
|
39
|
+
range -= used_ports
|
40
|
+
|
41
|
+
if range.empty?
|
42
|
+
raise 'Unable to find a port to bind the notification server to'
|
43
|
+
end
|
44
|
+
|
45
|
+
# Set the port up to be the last one since vagrant's port collision handler
|
46
|
+
# will use the first as in:
|
47
|
+
# https://github.com/mitchellh/vagrant/blob/1-0-stable/lib/vagrant/action/vm/check_port_collisions.rb#L51
|
48
|
+
port = range.pop
|
49
|
+
end
|
50
|
+
|
51
|
+
def used_ports
|
52
|
+
local_data = @env[:vm].env.local_data
|
53
|
+
local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
|
54
|
+
local_data['vagrant-notify'].values.map do |settings|
|
55
|
+
settings['port'].to_i if settings['port']
|
56
|
+
end.compact
|
31
57
|
end
|
32
58
|
|
33
59
|
# REFACTOR: This is duplicated on Middleware::StopServer
|
34
|
-
def server_is_running?
|
60
|
+
def server_is_running?
|
61
|
+
uuid = @env[:vm].uuid.to_s
|
35
62
|
begin
|
36
|
-
pid = env[:vm].env.local_data.
|
63
|
+
pid = @env[:vm].env.local_data.
|
64
|
+
fetch('vagrant-notify', {}).
|
65
|
+
fetch(uuid, {}).
|
66
|
+
fetch('pid', nil)
|
37
67
|
return false unless pid
|
38
68
|
|
39
69
|
Process.getpgid(pid)
|
@@ -25,16 +25,21 @@ module Vagrant
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def cleanup_local_data(env)
|
28
|
+
uuid = env[:vm].uuid.to_s
|
28
29
|
local_data = env[:vm].env.local_data
|
29
30
|
local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
|
30
|
-
local_data['vagrant-notify'].delete(
|
31
|
+
local_data['vagrant-notify'].delete(uuid)
|
31
32
|
local_data.commit
|
32
33
|
end
|
33
34
|
|
34
35
|
# REFACTOR: This is duplicated on Middleware::StartServer
|
35
36
|
def server_is_running?(env)
|
37
|
+
uuid = env[:vm].uuid.to_s
|
36
38
|
begin
|
37
|
-
pid = env[:vm].env.local_data.
|
39
|
+
pid = env[:vm].env.local_data.
|
40
|
+
fetch('vagrant-notify', {}).
|
41
|
+
fetch(uuid, {}).
|
42
|
+
fetch('pid', nil)
|
38
43
|
return false unless pid
|
39
44
|
|
40
45
|
Process.getpgid(pid.to_i)
|
@@ -1,21 +1,14 @@
|
|
1
1
|
module Vagrant
|
2
2
|
module Notify
|
3
3
|
class Server
|
4
|
-
|
5
|
-
args = ''
|
6
|
-
while tmp = client.gets
|
7
|
-
args << tmp
|
8
|
-
end
|
9
|
-
client.close
|
4
|
+
HTTP_RESPONSE = "Hi! You just reached the vagrant notification server"
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def self.run
|
6
|
+
def self.run(env, port)
|
7
|
+
uuid = env[:vm].uuid
|
15
8
|
fork do
|
16
|
-
$0 =
|
17
|
-
tcp_server = TCPServer.open(
|
18
|
-
server = self.new
|
9
|
+
$0 = "vagrant-notify-server (#{port})"
|
10
|
+
tcp_server = TCPServer.open(port)
|
11
|
+
server = self.new(uuid)
|
19
12
|
loop {
|
20
13
|
Thread.start(tcp_server.accept) do |client|
|
21
14
|
server.receive_data(client)
|
@@ -23,6 +16,49 @@ module Vagrant
|
|
23
16
|
}
|
24
17
|
end
|
25
18
|
end
|
19
|
+
|
20
|
+
def initialize(uuid, env = Vagrant::Environment.new)
|
21
|
+
@uuid = uuid
|
22
|
+
@env = env
|
23
|
+
end
|
24
|
+
|
25
|
+
def receive_data(client)
|
26
|
+
args = read_args(client)
|
27
|
+
if http_request?(args)
|
28
|
+
client.puts HTTP_RESPONSE
|
29
|
+
else
|
30
|
+
download_icon!(args)
|
31
|
+
system("notify-send #{args}")
|
32
|
+
end
|
33
|
+
client.close
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def read_args(client)
|
39
|
+
''.tap do |args|
|
40
|
+
while tmp = client.gets and tmp !~ /^\s*$/
|
41
|
+
args << tmp
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def http_request?(args)
|
47
|
+
args =~ /^GET/
|
48
|
+
end
|
49
|
+
|
50
|
+
def download_icon!(args)
|
51
|
+
return unless args =~ /-i '([^']+)'/
|
52
|
+
icon = $1
|
53
|
+
# TODO: Handle system icons
|
54
|
+
host_file = "/tmp/vagrant-notify-#{@uuid}-#{icon.gsub('/', '-')}"
|
55
|
+
download(icon, host_file) unless File.exists?(host_file)
|
56
|
+
args.gsub!(icon, host_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def download(icon, host_file)
|
60
|
+
@env.vms[:default].channel.download(icon, host_file)
|
61
|
+
end
|
26
62
|
end
|
27
63
|
end
|
28
64
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'vagrant/communication/ssh'
|
2
|
+
|
3
|
+
module VagrantSshExt
|
4
|
+
# Based on https://github.com/mitchellh/vagrant/blob/1-0-stable/lib/vagrant/communication/ssh.rb#L75-L90
|
5
|
+
def download(from, to)
|
6
|
+
@logger.debug("Downloading: #{from} to #{to}")
|
7
|
+
|
8
|
+
connect do |connection|
|
9
|
+
scp = Net::SCP.new(connection)
|
10
|
+
scp.download!(from, to)
|
11
|
+
end
|
12
|
+
rescue Net::SCP::Error => e
|
13
|
+
# If we get the exit code of 127, then this means SCP is unavailable.
|
14
|
+
raise Errors::SCPUnavailable if e.message =~ /\(127\)/
|
15
|
+
# Otherwise, just raise the error up
|
16
|
+
raise
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
unless Vagrant::Communication::SSH.public_methods.include?('download')
|
21
|
+
Vagrant::Communication::SSH.send :include, VagrantSshExt
|
22
|
+
end
|
data/lib/vagrant-notify.rb
CHANGED
@@ -3,20 +3,18 @@ require 'socket'
|
|
3
3
|
require 'erb'
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
|
+
if File.exists?(File.join(File.expand_path('../../', __FILE__), '.git'))
|
7
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
8
|
+
end
|
9
|
+
|
6
10
|
require 'vagrant-notify/middleware'
|
7
11
|
require 'vagrant-notify/server'
|
12
|
+
require 'vagrant-notify/vagrant_ssh_ext'
|
8
13
|
require "vagrant-notify/version"
|
9
14
|
|
10
15
|
module Vagrant
|
11
16
|
module Notify
|
12
17
|
class << self
|
13
|
-
def server_port
|
14
|
-
@@server_port ||= 8081
|
15
|
-
end
|
16
|
-
def server_port=(server_port)
|
17
|
-
@@server_port = server_port
|
18
|
-
end
|
19
|
-
|
20
18
|
def files_path
|
21
19
|
@file_path ||= File.expand_path(File.dirname(__FILE__) + '/../files')
|
22
20
|
end
|
@@ -25,8 +23,13 @@ module Vagrant
|
|
25
23
|
end
|
26
24
|
|
27
25
|
Vagrant.actions[:start].tap do |start|
|
28
|
-
start.
|
29
|
-
start.insert_after Vagrant::
|
26
|
+
start.insert_after Vagrant::Action::VM::Boot, Vagrant::Notify::Middleware::StartServer
|
27
|
+
start.insert_after Vagrant::Notify::Middleware::StartServer, Vagrant::Notify::Middleware::InstallCommand
|
28
|
+
end
|
29
|
+
Vagrant.actions[:resume].tap do |start|
|
30
|
+
start.use Vagrant::Notify::Middleware::StartServer
|
31
|
+
start.use Vagrant::Notify::Middleware::InstallCommand
|
30
32
|
end
|
31
|
-
Vagrant.actions[:halt].use
|
33
|
+
Vagrant.actions[:halt].use Vagrant::Notify::Middleware::StopServer
|
34
|
+
Vagrant.actions[:suspend].use Vagrant::Notify::Middleware::StopServer
|
32
35
|
Vagrant.actions[:provision].use Vagrant::Notify::Middleware::InstallCommand
|
@@ -1,20 +1,25 @@
|
|
1
1
|
describe Vagrant::Notify::Middleware::InstallCommand do
|
2
2
|
let(:start_stack) { Vagrant.actions[:start].send(:stack) }
|
3
3
|
let(:provision_stack) { Vagrant.actions[:provision].send(:stack) }
|
4
|
+
let(:resume_stack) { Vagrant.actions[:resume].send(:stack) }
|
4
5
|
let(:host_ip) { 'host-ip' }
|
5
|
-
let(:host_port) {
|
6
|
+
let(:host_port) { 789 }
|
6
7
|
let(:template) { ERB.new('<%= host_ip %> <%= host_port %>') }
|
7
8
|
let(:compiled_command_path) { @env[:vm].env.tmp_path + 'vagrant-notify-send' }
|
8
9
|
let(:target_tmp_path) { '/tmp/notify-send' }
|
9
10
|
let(:target_path) { '/usr/bin/notify-send' }
|
10
11
|
let(:channel) { mock(:channel, :sudo => true, :upload => true, :execute => true) }
|
11
12
|
let(:get_ip_command) { 'echo -n $SSH_CLIENT | cut -d" " -f1' }
|
13
|
+
let(:uuid) { @env[:vm].uuid.to_s }
|
14
|
+
let(:local_data) { Hash.new }
|
12
15
|
|
13
16
|
subject { described_class.new(@app, @env) }
|
14
17
|
|
15
18
|
before do
|
16
19
|
@app, @env = action_env(vagrant_env.vms.values.first.env)
|
17
20
|
@env[:vm].stub(:channel => channel)
|
21
|
+
@env[:vm].env.stub(:local_data => local_data)
|
22
|
+
local_data['vagrant-notify'] = { uuid => {'port' => host_port } }
|
18
23
|
ERB.stub(:new => template)
|
19
24
|
end
|
20
25
|
|
@@ -25,6 +30,10 @@ describe Vagrant::Notify::Middleware::InstallCommand do
|
|
25
30
|
boot_index.should < middleware_index
|
26
31
|
end
|
27
32
|
|
33
|
+
it 'gets called when resuming machine' do
|
34
|
+
resume_stack.should include([described_class, [], nil])
|
35
|
+
end
|
36
|
+
|
28
37
|
it 'gets called when provisioning machine' do
|
29
38
|
provision_stack.should include([described_class, [], nil])
|
30
39
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
describe Vagrant::Notify::Middleware::StartServer do
|
2
|
-
let(:start_stack)
|
3
|
-
let(:
|
4
|
-
let(:
|
2
|
+
let(:start_stack) { Vagrant.actions[:start].send(:stack) }
|
3
|
+
let(:resume_stack) { Vagrant.actions[:resume].send(:stack) }
|
4
|
+
let(:server_pid) { 1234 }
|
5
|
+
let(:available_port) { 8080 }
|
6
|
+
let(:uuid) { @env[:vm].uuid.to_s }
|
7
|
+
let(:local_data) { Hash.new }
|
5
8
|
|
6
9
|
subject { described_class.new(@app, @env) }
|
7
10
|
|
@@ -16,23 +19,36 @@ describe Vagrant::Notify::Middleware::StartServer do
|
|
16
19
|
start_stack.should include([described_class, [], nil])
|
17
20
|
end
|
18
21
|
|
22
|
+
it 'gets called when resuming machine' do
|
23
|
+
resume_stack.should include([described_class, [], nil])
|
24
|
+
end
|
25
|
+
|
19
26
|
context 'server is down' do
|
20
|
-
before
|
27
|
+
before do
|
28
|
+
Process.stub(:getpgid).and_raise(Errno::ESRCH)
|
29
|
+
subject.stub(:next_available_port => available_port)
|
30
|
+
end
|
21
31
|
|
22
32
|
it 'fires up notification server when called' do
|
23
|
-
Vagrant::Notify::Server.should_receive(:run)
|
33
|
+
Vagrant::Notify::Server.should_receive(:run).with(@env, available_port)
|
24
34
|
subject.call(@env)
|
25
35
|
end
|
26
36
|
|
27
37
|
it 'notifies user about server start' do
|
28
|
-
@env[:ui].should_receive(:info).with("Notification server
|
38
|
+
@env[:ui].should_receive(:info).with("Notification server is listening on #{available_port} (#{server_pid})")
|
29
39
|
subject.call(@env)
|
30
40
|
end
|
31
41
|
|
32
42
|
it "persists server PID on local data" do
|
33
43
|
local_data.should_receive(:commit)
|
34
44
|
subject.call(@env)
|
35
|
-
local_data['vagrant-notify']['pid'].should == server_pid
|
45
|
+
local_data['vagrant-notify'][uuid]['pid'].should == server_pid
|
46
|
+
end
|
47
|
+
|
48
|
+
it "persists server port on local data" do
|
49
|
+
local_data.should_receive(:commit)
|
50
|
+
subject.call(@env)
|
51
|
+
local_data['vagrant-notify'][uuid]['port'].should == available_port
|
36
52
|
end
|
37
53
|
|
38
54
|
context "and a PID is present on Vagrant's local data" do
|
@@ -40,12 +56,12 @@ describe Vagrant::Notify::Middleware::StartServer do
|
|
40
56
|
|
41
57
|
before do
|
42
58
|
Vagrant::Notify::Server.stub(:run => new_pid)
|
43
|
-
local_data['vagrant-notify'] = { 'pid' => server_pid }
|
59
|
+
local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
|
44
60
|
end
|
45
61
|
|
46
62
|
it 'updates server PID' do
|
47
63
|
subject.call(@env)
|
48
|
-
local_data['vagrant-notify']['pid'].should == new_pid
|
64
|
+
local_data['vagrant-notify'][uuid]['pid'].should == new_pid
|
49
65
|
end
|
50
66
|
end
|
51
67
|
end
|
@@ -53,7 +69,7 @@ describe Vagrant::Notify::Middleware::StartServer do
|
|
53
69
|
context 'server is up' do
|
54
70
|
before do
|
55
71
|
Process.stub(:getpgid => true)
|
56
|
-
local_data['vagrant-notify'] = { 'pid' => server_pid }
|
72
|
+
local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
|
57
73
|
end
|
58
74
|
|
59
75
|
it 'does not start a new server instance' do
|
@@ -1,7 +1,9 @@
|
|
1
1
|
describe Vagrant::Notify::Middleware::StopServer do
|
2
|
-
let(:halt_stack)
|
3
|
-
let(:
|
4
|
-
let(:
|
2
|
+
let(:halt_stack) { Vagrant.actions[:halt].send(:stack) }
|
3
|
+
let(:suspend_stack) { Vagrant.actions[:halt].send(:stack) }
|
4
|
+
let(:server_pid) { '1234' }
|
5
|
+
let(:uuid) { @env[:vm].uuid.to_s }
|
6
|
+
let(:local_data) { { 'vagrant-notify' => { uuid => { 'pid' => server_pid } } } }
|
5
7
|
|
6
8
|
subject { described_class.new(@app, @env) }
|
7
9
|
|
@@ -15,6 +17,10 @@ describe Vagrant::Notify::Middleware::StopServer do
|
|
15
17
|
halt_stack.should include([described_class, [], nil])
|
16
18
|
end
|
17
19
|
|
20
|
+
it 'gets called when suspending machine' do
|
21
|
+
suspend_stack.should include([described_class, [], nil])
|
22
|
+
end
|
23
|
+
|
18
24
|
context 'server is down' do
|
19
25
|
before { Process.stub(:getpgid).and_raise(Errno::ESRCH) }
|
20
26
|
|
@@ -27,7 +33,7 @@ describe Vagrant::Notify::Middleware::StopServer do
|
|
27
33
|
context 'server is up' do
|
28
34
|
before do
|
29
35
|
Process.stub(:getpgid => true)
|
30
|
-
local_data['vagrant-notify'] = { 'pid' => server_pid }
|
36
|
+
local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
|
31
37
|
end
|
32
38
|
|
33
39
|
it 'notifies user that server is stopping' do
|
data/spec/server_spec.rb
CHANGED
@@ -2,9 +2,9 @@ describe Vagrant::Notify::Server do
|
|
2
2
|
let(:arguments) { "-- '20 examples, 1 failure\n10 seconds'" }
|
3
3
|
let(:client) { StringIO.new(arguments) }
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
subject { described_class.new('uuid') }
|
6
|
+
|
7
|
+
before { subject.stub(:system => true, :download => true) }
|
8
8
|
|
9
9
|
it 'runs notify-send with received data from client' do
|
10
10
|
subject.should_receive(:system).with("notify-send #{arguments}")
|
@@ -15,4 +15,53 @@ describe Vagrant::Notify::Server do
|
|
15
15
|
client.should_receive(:close)
|
16
16
|
subject.receive_data(client)
|
17
17
|
end
|
18
|
+
|
19
|
+
context 'notification with an icon' do
|
20
|
+
let(:arguments) { "-i 'foo/bar.jpg'" }
|
21
|
+
|
22
|
+
context 'icon hasnt been downloaded before' do
|
23
|
+
before { subject.receive_data(client) }
|
24
|
+
|
25
|
+
it 'downloads icon file to host machine' do
|
26
|
+
subject.should have_received(:download)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'rewrites icon path before sending the notification' do
|
30
|
+
subject.should have_received(:system).with("notify-send -i '/tmp/vagrant-notify-uuid-foo-bar.jpg'")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'icon file cache is present' do
|
35
|
+
before do
|
36
|
+
File.stub(:exists? => true)
|
37
|
+
subject.receive_data(client)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does not download icon if was already downloaded' do
|
41
|
+
subject.should_not have_received(:download)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'incoming HTTP connections' do
|
47
|
+
let(:client) do
|
48
|
+
StringIO.new("GET some/path\n\n").tap { |s|
|
49
|
+
s.stub(:close => true, :puts => true)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
before { subject.receive_data(client) }
|
54
|
+
|
55
|
+
it 'responds with a friendly message' do
|
56
|
+
client.should have_received(:puts).with(described_class::HTTP_RESPONSE)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'does not issue system commands' do
|
60
|
+
subject.should_not have_received(:system)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'closes connection' do
|
64
|
+
client.should have_received(:close)
|
65
|
+
end
|
66
|
+
end
|
18
67
|
end
|
data/spec/spec_helper.rb
CHANGED
data/vagrant-notify.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.
|
21
|
-
|
20
|
+
gem.add_development_dependency 'vagrant'
|
22
21
|
gem.add_development_dependency 'rake'
|
23
22
|
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'rspec-spies'
|
24
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-notify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,56 +9,72 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
15
16
|
name: vagrant
|
16
|
-
|
17
|
-
none: false
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
22
|
none: false
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
26
24
|
requirements:
|
27
25
|
- - ! '>='
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
version: '0'
|
28
|
+
none: false
|
29
|
+
type: :development
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
31
32
|
name: rake
|
32
|
-
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
33
38
|
none: false
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
34
40
|
requirements:
|
35
41
|
- - ! '>='
|
36
42
|
- !ruby/object:Gem::Version
|
37
43
|
version: '0'
|
44
|
+
none: false
|
38
45
|
type: :development
|
46
|
+
- !ruby/object:Gem::Dependency
|
39
47
|
prerelease: false
|
48
|
+
name: rspec
|
40
49
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
50
|
requirements:
|
43
51
|
- - ! '>='
|
44
52
|
- !ruby/object:Gem::Version
|
45
53
|
version: '0'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
54
|
none: false
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
50
56
|
requirements:
|
51
57
|
- - ! '>='
|
52
58
|
- !ruby/object:Gem::Version
|
53
59
|
version: '0'
|
60
|
+
none: false
|
54
61
|
type: :development
|
62
|
+
- !ruby/object:Gem::Dependency
|
55
63
|
prerelease: false
|
64
|
+
name: rspec-spies
|
56
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
57
70
|
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ! '>='
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
76
|
+
none: false
|
77
|
+
type: :development
|
62
78
|
description: A Vagrant plugin that redirects system notifications from guest to host
|
63
79
|
machine.
|
64
80
|
email:
|
@@ -83,6 +99,7 @@ files:
|
|
83
99
|
- lib/vagrant-notify/middleware/start_server.rb
|
84
100
|
- lib/vagrant-notify/middleware/stop_server.rb
|
85
101
|
- lib/vagrant-notify/server.rb
|
102
|
+
- lib/vagrant-notify/vagrant_ssh_ext.rb
|
86
103
|
- lib/vagrant-notify/version.rb
|
87
104
|
- lib/vagrant_init.rb
|
88
105
|
- spec/middleware/install_command_spec.rb
|
@@ -98,23 +115,23 @@ rdoc_options: []
|
|
98
115
|
require_paths:
|
99
116
|
- lib
|
100
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
118
|
requirements:
|
103
119
|
- - ! '>='
|
104
120
|
- !ruby/object:Gem::Version
|
105
121
|
version: '0'
|
106
122
|
segments:
|
107
123
|
- 0
|
108
|
-
hash: -
|
109
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
hash: -2874098481974869093
|
110
125
|
none: false
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
127
|
requirements:
|
112
128
|
- - ! '>='
|
113
129
|
- !ruby/object:Gem::Version
|
114
130
|
version: '0'
|
115
131
|
segments:
|
116
132
|
- 0
|
117
|
-
hash: -
|
133
|
+
hash: -2874098481974869093
|
134
|
+
none: false
|
118
135
|
requirements: []
|
119
136
|
rubyforge_project:
|
120
137
|
rubygems_version: 1.8.23
|