vagrant-nitrousio 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.env-example +4 -0
  3. data/.gitignore +17 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +7 -0
  6. data/LICENSE +10 -0
  7. data/README.md +97 -0
  8. data/Rakefile +26 -0
  9. data/example_box/README.md +13 -0
  10. data/example_box/metadata.json +3 -0
  11. data/lib/vagrant-nitrousio/action/add_pub_key.rb +44 -0
  12. data/lib/vagrant-nitrousio/action/connect_nitrousio.rb +31 -0
  13. data/lib/vagrant-nitrousio/action/create.rb +79 -0
  14. data/lib/vagrant-nitrousio/action/is_created.rb +18 -0
  15. data/lib/vagrant-nitrousio/action/is_running.rb +18 -0
  16. data/lib/vagrant-nitrousio/action/is_stopped.rb +18 -0
  17. data/lib/vagrant-nitrousio/action/is_terminated.rb +18 -0
  18. data/lib/vagrant-nitrousio/action/message_already_created.rb +16 -0
  19. data/lib/vagrant-nitrousio/action/message_already_terminated.rb +16 -0
  20. data/lib/vagrant-nitrousio/action/message_cannot_halt.rb +16 -0
  21. data/lib/vagrant-nitrousio/action/message_cannot_terminate.rb +16 -0
  22. data/lib/vagrant-nitrousio/action/message_not_created.rb +16 -0
  23. data/lib/vagrant-nitrousio/action/message_not_running.rb +16 -0
  24. data/lib/vagrant-nitrousio/action/message_provisioning_not_yet_supported.rb +16 -0
  25. data/lib/vagrant-nitrousio/action/read_ssh_info.rb +60 -0
  26. data/lib/vagrant-nitrousio/action/read_state.rb +36 -0
  27. data/lib/vagrant-nitrousio/action/remove_machine_id.rb +19 -0
  28. data/lib/vagrant-nitrousio/action/start.rb +31 -0
  29. data/lib/vagrant-nitrousio/action/stop.rb +31 -0
  30. data/lib/vagrant-nitrousio/action/sync_folders.rb +57 -0
  31. data/lib/vagrant-nitrousio/action/terminate.rb +34 -0
  32. data/lib/vagrant-nitrousio/action/timed_provision.rb +21 -0
  33. data/lib/vagrant-nitrousio/action/warn_networks.rb +19 -0
  34. data/lib/vagrant-nitrousio/action.rb +166 -0
  35. data/lib/vagrant-nitrousio/client.rb +57 -0
  36. data/lib/vagrant-nitrousio/config.rb +94 -0
  37. data/lib/vagrant-nitrousio/errors.rb +55 -0
  38. data/lib/vagrant-nitrousio/plugin.rb +73 -0
  39. data/lib/vagrant-nitrousio/provider.rb +50 -0
  40. data/lib/vagrant-nitrousio/util/env.rb +12 -0
  41. data/lib/vagrant-nitrousio/util/timer.rb +17 -0
  42. data/lib/vagrant-nitrousio/version.rb +5 -0
  43. data/lib/vagrant-nitrousio.rb +18 -0
  44. data/locales/en.yml +139 -0
  45. data/nitrousio.box +0 -0
  46. data/sample/cookbooks/test/recipes/default.rb +1 -0
  47. data/sample/provision.sh +3 -0
  48. data/sample/puppet/manifests/site.pp +2 -0
  49. data/sample/puppet/modules/baseconfig/files/bashrc +107 -0
  50. data/sample/puppet/modules/baseconfig/manifests/init.pp +21 -0
  51. data/sample/test/hello.txt +1 -0
  52. data/spec/vagrant-nitrousio/action/create_spec.rb +36 -0
  53. data/spec/vagrant-nitrousio/action/read_ssh_info_spec.rb +59 -0
  54. data/spec/vagrant-nitrousio/action/read_state_spec.rb +46 -0
  55. data/spec/vagrant-nitrousio/action/start_spec.rb +32 -0
  56. data/spec/vagrant-nitrousio/action/stop_spec.rb +20 -0
  57. data/spec/vagrant-nitrousio/action/terminate_spec.rb +20 -0
  58. data/spec/vagrant-nitrousio/client_spec.rb +209 -0
  59. data/spec/vagrant-nitrousio/config_spec.rb +48 -0
  60. data/vagrant-nitrousio.gemspec +59 -0
  61. metadata +193 -0
@@ -0,0 +1,12 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Util
4
+ class Env
5
+ def self.read_with_default(env_var, default)
6
+ value = ENV[env_var]
7
+ value.nil? ? default : value
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ module Util
4
+ class Timer
5
+ # A basic utility method that times the execution of the given
6
+ # block and returns it.
7
+ def self.time
8
+ start_time = Time.now.to_f
9
+ yield
10
+ end_time = Time.now.to_f
11
+
12
+ end_time - start_time
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module NitrousIO
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'pathname'
2
+
3
+ require 'vagrant-nitrousio/plugin'
4
+
5
+ module VagrantPlugins
6
+ module NitrousIO
7
+ lib_path = Pathname.new(File.expand_path('../vagrant-nitrousio', __FILE__))
8
+ autoload :Action, lib_path.join('action')
9
+ autoload :Errors, lib_path.join('errors')
10
+
11
+ # This returns the path to the source of this plugin.
12
+ #
13
+ # @return [Pathname]
14
+ def self.source_root
15
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
16
+ end
17
+ end
18
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,139 @@
1
+ en:
2
+ vagrant_nitrousio:
3
+ already_created: |-
4
+ The box already exists on Nitrous.IO.
5
+ already_terminated: |-
6
+ The box is already terminated on Nitrous.IO.
7
+ cannot_terminate: |-
8
+ The box needs to be in either "running" or "stopped" state to be terminatable.
9
+ cannot_halt: |-
10
+ Failed to halt the box.
11
+ launching_box: |-
12
+ Launching a box on Nitrous.IO with the following settings...
13
+ not_created: |-
14
+ Your box on Nitrous.IO is not created. Please create your box by running `vagrant up` first.
15
+ not_running: |-
16
+ Your box on Nitrous.IO is not running. Please start your box by running `vagrant up` first.
17
+ box_ready: |-
18
+ Box is is ready for use
19
+ rsync_folder: |-
20
+ Rsyncing folder: %{hostpath} => %{guestpath}
21
+ pulling_image: |-
22
+ Pulling the base image to your Nitrous.IO host (this will take some time)...
23
+ creating_box: |-
24
+ Creating the box on Nitrous.IO...
25
+ starting_box: |-
26
+ Starting the box on Nitrous.IO...
27
+ stopped: |-
28
+ Your box on Nitrous.IO is stopped.
29
+ stopping_box: |-
30
+ Stopping the box on Nitrous.IO...
31
+ terminated: |-
32
+ Your box on Nitrous.IO is terminated.
33
+ terminating_box: |-
34
+ Terminating the box on Nitrous.IO...
35
+ warn_networks: |-
36
+ Warning! The Nitrous.IO provider doesn't support any of the Vagrant
37
+ high-level network configurations (`config.vm.network`). They
38
+ will be silently ignored.
39
+ adding_pub_key: |-
40
+ Adding public key to the box.
41
+
42
+ config:
43
+ username_required: |-
44
+ A username must be specified via "username"
45
+
46
+ password_required: |-
47
+ A password must be specified via "password"
48
+
49
+ host_required: |-
50
+ A host slug must be specified via "host"
51
+
52
+ private_key_missing: |-
53
+ The specified SSH private key could not be found
54
+
55
+ ssh_private_key_path_required: |-
56
+ A path to an ssh private key must be specified via "ssh_private_key_path"
57
+
58
+ errors:
59
+ api_error: |-
60
+ An unexpected error occurred:
61
+
62
+ %{message}
63
+
64
+ authentication_failed_error: |-
65
+ Failed to authenticate with Nitrous.IO. Check the reason shown below:
66
+
67
+ %{description}
68
+
69
+ host_not_found_error: |-
70
+ Host does not exist.
71
+
72
+ Make sure you use host's slug instead of the name.
73
+
74
+ image_not_found_error: |-
75
+ Image does not exist.
76
+
77
+ Specify a valid Docker repository.
78
+
79
+ box_not_yet_started_error: |-
80
+ Box is not yet started.
81
+
82
+ box_not_yet_stopped_error: |-
83
+ Box is not yet stopped.
84
+
85
+ box_not_yet_terminated_error: |-
86
+ Box is not yet terminated.
87
+
88
+ rsync_error: |-
89
+ There was an error when attemping to rsync a shared folder.
90
+ Please inspect the error message below for more info.
91
+
92
+ Host path: %{hostpath}
93
+ Guest path: %{guestpath}
94
+ Error: %{stderr}
95
+
96
+ timeout_error: |-
97
+ Box creation timed out.
98
+
99
+ states:
100
+ short_not_created: |-
101
+ not created
102
+ long_not_created: |-
103
+ The Nitrous.IO box is not created. Run `vagrant up` to create it.
104
+
105
+ short_provisioning: |-
106
+ provisioning
107
+ long_provisioning: |-
108
+ The Nitrous.IO box is being created.
109
+
110
+ short_running: |-
111
+ running
112
+ long_running: |-
113
+ The Nitrous.IO box is running. To stop this machine, you can run
114
+ `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
115
+
116
+ short_starting: |-
117
+ starting
118
+ long_starting: |-
119
+ The Nitrous.IO box is starting.
120
+
121
+ short_stopped: |-
122
+ stopped
123
+ long_stopped: |-
124
+ The Nitrous.IO box is stopped. Run `vagrant up` to start it.
125
+
126
+ short_stopping: |-
127
+ stopping
128
+ long_stopping: |-
129
+ The Nitrous.IO box is stopping.
130
+
131
+ short_terminated: |-
132
+ terminated
133
+ long_terminated: |-
134
+ The Nitrous.IO box is terminated.
135
+
136
+ short_terminating: |-
137
+ terminating
138
+ long_terminating: |-
139
+ The Nitrous.IO box is terminating.
data/nitrousio.box ADDED
Binary file
@@ -0,0 +1 @@
1
+ log 'Testing 1 2 3!'
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ touch hello.txt
@@ -0,0 +1,2 @@
1
+ include baseconfig
2
+
@@ -0,0 +1,107 @@
1
+ # ~/.bashrc: executed by bash(1) for non-login shells.
2
+ # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
3
+ # for examples
4
+
5
+ # If not running interactively, don't do anything
6
+ [ -z "$PS1" ] && return
7
+
8
+ # don't put duplicate lines or lines starting with space in the history.
9
+ # See bash(1) for more options
10
+ HISTCONTROL=ignoreboth
11
+
12
+ # append to the history file, don't overwrite it
13
+ shopt -s histappend
14
+
15
+ # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
16
+ HISTSIZE=50000
17
+ HISTFILESIZE=50000
18
+
19
+ # check the window size after each command and, if necessary,
20
+ # update the values of LINES and COLUMNS.
21
+ shopt -s checkwinsize
22
+
23
+ # If set, the pattern "**" used in a pathname expansion context will
24
+ # match all files and zero or more directories and subdirectories.
25
+ #shopt -s globstar
26
+
27
+ # make less more friendly for non-text input files, see lesspipe(1)
28
+ [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
29
+
30
+ # set variable identifying the chroot you work in (used in the prompt below)
31
+ if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
32
+ debian_chroot=$(cat /etc/debian_chroot)
33
+ fi
34
+
35
+ # set a fancy prompt (non-color, unless we know we "want" color)
36
+ case "$TERM" in
37
+ xterm-color) color_prompt=yes;;
38
+ esac
39
+
40
+ # uncomment for a colored prompt, if the terminal has the capability; turned
41
+ # off by default to not distract the user: the focus in a terminal window
42
+ # should be on the output of commands, not on the prompt
43
+ force_color_prompt=yes
44
+
45
+ if [ -n "$force_color_prompt" ]; then
46
+ if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
47
+ # We have color support; assume it's compliant with Ecma-48
48
+ # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
49
+ # a case would tend to support setf rather than setaf.)
50
+ color_prompt=yes
51
+ else
52
+ color_prompt=
53
+ fi
54
+ fi
55
+
56
+ if [ "$color_prompt" = yes ]; then
57
+ PS1='${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ '
58
+ else
59
+ PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
60
+ fi
61
+ unset color_prompt force_color_prompt
62
+
63
+ # If this is an xterm set the title to user@host:dir
64
+ case "$TERM" in
65
+ xterm*|rxvt*)
66
+ PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
67
+ ;;
68
+ *)
69
+ ;;
70
+ esac
71
+
72
+ # enable color support of ls and also add handy aliases
73
+ if [ -x /usr/bin/dircolors ]; then
74
+ test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
75
+ alias ls='ls --color=auto'
76
+ #alias dir='dir --color=auto'
77
+ #alias vdir='vdir --color=auto'
78
+
79
+ alias grep='grep --color=auto'
80
+ alias fgrep='fgrep --color=auto'
81
+ alias egrep='egrep --color=auto'
82
+ fi
83
+
84
+ # some more ls aliases
85
+ alias ll='ls -alF'
86
+ alias la='ls -A'
87
+ alias l='ls -CF'
88
+
89
+ # Add an "alert" alias for long running commands. Use like so:
90
+ # sleep 10; alert
91
+ alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
92
+
93
+ # Alias definitions.
94
+ # You may want to put all your additions into a separate file like
95
+ # ~/.bash_aliases, instead of adding them here directly.
96
+ # See /usr/share/doc/bash-doc/examples in the bash-doc package.
97
+
98
+ if [ -f ~/.bash_aliases ]; then
99
+ . ~/.bash_aliases
100
+ fi
101
+
102
+ # enable programmable completion features (you don't need to enable
103
+ # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
104
+ # sources /etc/bash.bashrc).
105
+ if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
106
+ . /etc/bash_completion
107
+ fi
@@ -0,0 +1,21 @@
1
+ # == Class: baseconfig
2
+ #
3
+ # Performs initial configuration tasks for all Vagrant boxes.
4
+ #
5
+ class baseconfig {
6
+ exec { 'apt-get update':
7
+ command => '/usr/bin/apt-get update';
8
+ }
9
+
10
+ host { 'hostmachine':
11
+ ip => '192.168.0.1';
12
+ }
13
+
14
+ file {
15
+ '/home/vagrant/.bashrc':
16
+ owner => 'vagrant',
17
+ group => 'vagrant',
18
+ mode => '0644',
19
+ source => 'puppet:///modules/baseconfig/bashrc';
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ Hello
@@ -0,0 +1,36 @@
1
+ require 'vagrant-nitrousio/action/create'
2
+
3
+ describe VagrantPlugins::NitrousIO::Action::Create do
4
+ let(:app) { double 'app', call: nil }
5
+ let(:machine) { OpenStruct.new id: nil }
6
+ let(:nitrousio) { double 'connection', request: nil }
7
+ let(:ui) { double 'ui', info: nil, warn: nil }
8
+ let(:env) { { nitrousio: nitrousio, machine: machine, ui: ui } }
9
+ let(:instance) { described_class.new(app, env) }
10
+
11
+ describe '#pull_image' do
12
+ let(:json) { '{"image":{"id":777}}' }
13
+ let(:response) { double 'response', status: 201, json: json, parsed: JSON.parse(json) }
14
+
15
+ it "sets container's id in the environment" do
16
+ nitrousio.should_receive(:request).with(:post, '/hosts/vagrant-host/images/pull', params: {
17
+ repository: "foo/bar-image:latest"
18
+ }).and_return response
19
+ instance.pull_image(nitrousio, machine, 'vagrant-host', 'foo/bar-image:latest')
20
+ end
21
+ end
22
+
23
+ describe '#create_container' do
24
+ let(:json) { '{"container":{"id":777,"state":"running"}}' }
25
+ let(:response) { double 'response', status: 201, json: json, parsed: JSON.parse(json) }
26
+
27
+ it "sets container's id in the environment" do
28
+ nitrousio.should_receive(:request).with(:post, '/containers', body: {
29
+ slug: 'sample-box', host: 'vagrant-host', image: 'foo/bar-image:latest',
30
+ privileged: true
31
+ }).and_return response
32
+ instance.create_container(nitrousio, machine, 'vagrant-host', 'foo/bar-image:latest', 'sample-box', true)
33
+ expect(machine.id).to eq 777
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,59 @@
1
+ require 'vagrant-nitrousio/action/read_ssh_info'
2
+ require 'ostruct'
3
+ require 'json'
4
+
5
+ describe VagrantPlugins::NitrousIO::Action::ReadSSHInfo do
6
+ let(:app) { double 'app', call: nil }
7
+ let(:instance) { VagrantPlugins::NitrousIO::Action::ReadSSHInfo.new(app, env) }
8
+
9
+ context 'when machine id is nil' do
10
+ let(:machine) { double 'machine', id: nil }
11
+ let(:env) { { nitrousio: nil, machine: machine } }
12
+
13
+ it 'returns nil' do
14
+ instance.call(env)
15
+ expect(env[:machine_ssh_info]).to be_nil
16
+ end
17
+ end
18
+
19
+ context 'when machine id is not nil' do
20
+ let(:config) { OpenStruct.new(host: 'vagrant-host', ssh_private_key_path: '/home/action/.ssh/id_rsa') }
21
+ let(:machine) { OpenStruct.new(id: 123, provider_config: config) }
22
+ let!(:nitrousio) { double 'connection', request: nil }
23
+ let(:env) { { nitrousio: nitrousio, machine: machine } }
24
+
25
+ context 'when request is successful' do
26
+ before do
27
+ json = '{"config":{"port":["public:4040:22/tcp","public:5000:5050","public:4040:22/udp"]}}'
28
+ response = double 'response', status: 200, body: json, parsed: JSON.parse(json)
29
+ nitrousio.should_receive(:request).with(:get, '/containers/123/config').and_return response
30
+ end
31
+
32
+ it 'makes a get request to /containers/:id/config and returns a hash containing the ssh info' do
33
+ instance.call(env)
34
+ expect(env[:machine_ssh_info]).to eq({
35
+ host: 'vagrant-host.nitrouspro.com',
36
+ port: '4040',
37
+ private_key_path: '/home/action/.ssh/id_rsa',
38
+ username: 'action'
39
+ })
40
+ end
41
+ end
42
+
43
+ context 'when request returns 404' do
44
+ before do
45
+ response = double 'response', status: 404
46
+ error = StandardError.new('request error')
47
+ error.stub(:response) { response }
48
+ nitrousio.should_receive(:request).with(:get, '/containers/123/config').and_raise error
49
+ end
50
+
51
+ it 'sets machine id to be nil and returns nil' do
52
+ instance.call(env)
53
+ expect(env[:machine].id).to be_nil
54
+ expect(env[:machine_ssh_info]).to be_nil
55
+ end
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,46 @@
1
+ require 'vagrant-nitrousio/action/read_state'
2
+ require 'ostruct'
3
+
4
+ describe VagrantPlugins::NitrousIO::Action::ReadState do
5
+ let(:app) { double 'app', call: nil }
6
+ let(:instance) { VagrantPlugins::NitrousIO::Action::ReadState.new(app, env) }
7
+
8
+ context 'when machine id is nil' do
9
+ let(:machine) { double 'machine', id: nil }
10
+ let(:env) { { nitrousio: nil, machine: machine } }
11
+
12
+ it 'sets the machine_state_id to be :not_created' do
13
+ instance.call(env)
14
+ expect(env[:machine_state_id]).to eq :not_created
15
+ end
16
+ end
17
+
18
+ context 'when machine id is not nil' do
19
+ let(:machine) { OpenStruct.new(id: 123) }
20
+ let!(:nitrousio) { double 'connection', request: nil, fetch_box_state: nil }
21
+ let(:env) { { nitrousio: nitrousio, machine: machine } }
22
+
23
+ context 'when request is successful' do
24
+ before do
25
+ nitrousio.should_receive(:fetch_box_state).with(123).and_return :running
26
+ end
27
+
28
+ it 'makes a get request to /containers/:id and returns the state' do
29
+ instance.call(env)
30
+ expect(env[:machine_state_id]).to eq :running
31
+ end
32
+ end
33
+
34
+ context 'when request returns 404' do
35
+ before do
36
+ nitrousio.should_receive(:fetch_box_state).with(123).and_return nil
37
+ end
38
+
39
+ it 'sets machine id to be nil and returns :not_created' do
40
+ instance.call(env)
41
+ expect(env[:machine].id).to be_nil
42
+ expect(env[:machine_state_id]).to eq :not_created
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ require 'vagrant-nitrousio/action/start'
2
+
3
+ describe VagrantPlugins::NitrousIO::Action::Start do
4
+ let(:app) { double 'app', call: nil }
5
+ let(:provider_config) { OpenStruct.new privileged: false }
6
+ let(:machine) { OpenStruct.new id: 777, provider_config: provider_config }
7
+ let(:nitrousio) { double 'connection', request: nil }
8
+ let(:ui) { double 'ui', info: nil, warn: nil }
9
+ let(:env) { { nitrousio: nitrousio, machine: machine, ui: ui } }
10
+ let(:instance) { described_class.new(app, env) }
11
+
12
+ describe '#start_container' do
13
+ let(:json) { '{"container":{"id":777,"state":"running"}}' }
14
+ let(:response) { double 'response', status: 200, json: json, parsed: JSON.parse(json) }
15
+
16
+ it 'runs the request' do
17
+ nitrousio.should_receive(:request).with(:post, '/containers/777/start', body: {privileged: false}).and_return response
18
+ instance.call(env)
19
+ end
20
+
21
+ context "with the provider config's privileged flag being set to true" do
22
+ before do
23
+ provider_config.privileged = true
24
+ end
25
+
26
+ it 'runs the request' do
27
+ nitrousio.should_receive(:request).with(:post, '/containers/777/start', body: {privileged: true}).and_return response
28
+ instance.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'vagrant-nitrousio/action/stop'
2
+
3
+ describe VagrantPlugins::NitrousIO::Action::Stop do
4
+ let(:app) { double 'app', call: nil }
5
+ let(:machine) { OpenStruct.new id: 777 }
6
+ let(:nitrousio) { double 'connection', request: nil }
7
+ let(:ui) { double 'ui', info: nil, warn: nil }
8
+ let(:env) { { nitrousio: nitrousio, machine: machine, ui: ui } }
9
+ let(:instance) { described_class.new(app, env) }
10
+
11
+ describe '#stop_container' do
12
+ let(:json) { '{"container":{"id":777,"state":"stopped"}}' }
13
+ let(:response) { double 'response', status: 200, json: json, parsed: JSON.parse(json) }
14
+
15
+ it 'runs the request' do
16
+ nitrousio.should_receive(:request).with(:post, '/containers/777/stop').and_return response
17
+ instance.call(env)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'vagrant-nitrousio/action/terminate'
2
+
3
+ describe VagrantPlugins::NitrousIO::Action::Terminate do
4
+ let(:app) { double 'app', call: nil }
5
+ let(:machine) { OpenStruct.new id: 777 }
6
+ let(:nitrousio) { double 'connection', request: nil }
7
+ let(:ui) { double 'ui', info: nil, warn: nil }
8
+ let(:env) { { nitrousio: nitrousio, machine: machine, ui: ui } }
9
+ let(:instance) { described_class.new(app, env) }
10
+
11
+ describe '#terminate_container' do
12
+ let(:json) { '{"box":{"id":777,"state":"terminated"}}' }
13
+ let(:response) { double 'response', status: 200, json: json, parsed: JSON.parse(json) }
14
+
15
+ it 'runs the request' do
16
+ nitrousio.should_receive(:request).with(:delete, '/containers/777').and_return response
17
+ instance.call(env)
18
+ end
19
+ end
20
+ end