navyrb 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,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Navy::Runner do
4
+ let(:cmd) { ['the', 'command'] }
5
+
6
+ describe ".launch" do
7
+ let(:success) { true }
8
+ let(:status) { double :success? => success }
9
+
10
+ before :each do
11
+ allow(Open3).to receive(:capture3) do |cmd|
12
+ @executed = cmd
13
+ ["stdout", "stderr", status]
14
+ end
15
+ end
16
+
17
+ it "executes the command" do
18
+ described_class.launch cmd
19
+ expect(@executed).to eq "the command"
20
+ end
21
+
22
+ context "when the execution succeeds" do
23
+ it "returns true" do
24
+ expect(described_class.launch(cmd)).to be true
25
+ end
26
+ end
27
+
28
+ context "when the execution fails" do
29
+ let(:success) { false }
30
+
31
+ it "returns false" do
32
+ expect(described_class.launch(cmd)).to be false
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,228 @@
1
+ require 'spec_helper'
2
+
3
+ describe Navy::TaskContainerBuilder do
4
+ let(:app) do
5
+ app = double(:name => 'the_app',
6
+ :image => 'the_image',
7
+ :linked_apps => [],
8
+ :dependencies => [],
9
+ :env_var? => false,
10
+ :proxy_to? => false,
11
+ :volumes_from => [],
12
+ :modes => nil)
13
+ app
14
+ end
15
+
16
+ let(:config) do
17
+ config = double :environment => "config_env",
18
+ :docker_args => nil,
19
+ :pre_tasks => [],
20
+ :post_tasks => []
21
+ allow(config).to receive(:container_name) do |name, options|
22
+ convoy = options[:convoy]
23
+ mode = options[:mode]
24
+ scale = options[:scale]
25
+ name = [convoy, name, mode, scale].compact.join '_'
26
+ "container_for_#{name}"
27
+ end
28
+ config
29
+ end
30
+
31
+ let(:options) { {:convoy => 'convoy_id', :cluster => 'the-cluster.com'} }
32
+
33
+ describe "#build_pre" do
34
+ subject { described_class.new(app, config, options).build_pre }
35
+
36
+ context "when there are no pretasks" do
37
+ it "returns nil" do
38
+ expect(subject).to be_nil
39
+ end
40
+ end
41
+
42
+ context "when there are pretasks" do
43
+ before :each do
44
+ allow(config).to receive(:pre_tasks) { |app| ["pre1_#{app}", "pre2_#{app}"] }
45
+ end
46
+
47
+ describe "#dependencies" do
48
+ context 'with dependencies' do
49
+ before :each do
50
+ allow(app).to receive(:dependencies).with(config).and_return(['dep1', 'dep2'])
51
+ end
52
+
53
+ it "returns array of container names depended on" do
54
+ expect(subject.dependencies).to eq ['container_for_convoy_id_dep1', 'container_for_convoy_id_dep2']
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ describe "#specification" do
61
+ let(:spec) { subject.specification }
62
+
63
+ it "gives needed details to bring up the container" do
64
+ expect(spec[:container_name]).to eq "container_for_convoy_id_the_app_pretasks"
65
+ expect(spec[:name]).to eq "the_app"
66
+ expect(spec[:image]).to eq "the_image"
67
+ expect(spec[:type]).to eq "task"
68
+ expect(spec[:cmds]).to eq ["pre1_the_app", "pre2_the_app"]
69
+ #expect(spec[:sha]).to eq "todo"
70
+ end
71
+
72
+
73
+ describe "Dependency Links" do
74
+ before :each do
75
+ allow(app).to receive(:dependencies).with(config).and_return(['dep1', 'dep2'])
76
+ end
77
+
78
+ it "links to the container" do
79
+ links = spec[:links]
80
+ expect(links).to include ['container_for_convoy_id_dep1', 'dep1']
81
+ expect(links).to include ['container_for_convoy_id_dep2', 'dep2']
82
+ end
83
+ end
84
+
85
+ describe "Environment" do
86
+ context "when there's an env_variable" do
87
+ before :each do
88
+ expect(app).to receive(:env_var?) { true }
89
+ expect(app).to receive(:env_var) { "THE_ENV_VAR" }
90
+ end
91
+
92
+ it "sets an environment variable with the config's environment" do
93
+ env = spec[:env]
94
+ expect(env['THE_ENV_VAR']).to eq 'config_env'
95
+ end
96
+ end
97
+
98
+ context "when there's no env variable" do
99
+ it "sets no environment variable" do
100
+ env = spec[:env]
101
+ expect(env['THE_ENV_VAR']).to be_nil
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "Volumes" do
107
+ before :each do
108
+ expect(app).to receive(:volumes_from).and_return(['fromvol1', 'fromvol2'])
109
+ end
110
+
111
+ it "adds any given volumes from" do
112
+ vols = spec[:volumes_from]
113
+ expect(vols).to eq ['fromvol1', 'fromvol2']
114
+ end
115
+ end
116
+
117
+ describe "Docker Flags" do
118
+ before :each do
119
+ expect(config).to receive(:docker_args).and_return('-some flags for docker')
120
+ end
121
+
122
+ it "adds them to the specification" do
123
+ expect(spec[:docker_args]).to eq "-some flags for docker"
124
+ end
125
+ end
126
+ end
127
+
128
+ end
129
+ end
130
+
131
+ describe "#build_post" do
132
+ subject { described_class.new(app, config, options).build_post }
133
+
134
+ context "when there are no post tasks" do
135
+ it "returns nil" do
136
+ expect(subject).to be_nil
137
+ end
138
+ end
139
+
140
+ context "when there are post tasks" do
141
+ before :each do
142
+ allow(config).to receive(:post_tasks) { |app| ["post1_#{app}", "post2_#{app}"] }
143
+ end
144
+
145
+ describe "#dependencies" do
146
+ it "includes the app container (at scale 1)" do
147
+ expect(subject.dependencies).to eq ['container_for_convoy_id_the_app_1']
148
+ end
149
+
150
+ context 'when there are modes' do
151
+ before :each do
152
+ allow(app).to receive(:modes) { {:modea => 'cmd1', :modeb => 'cmd2'} }
153
+ end
154
+
155
+ it "includes each mode task container" do
156
+ expect(subject.dependencies).to eq ['container_for_convoy_id_the_app_modea_1', 'container_for_convoy_id_the_app_modeb_1']
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "#specification" do
162
+ let(:spec) { subject.specification }
163
+
164
+ it "gives needed details to bring up the container" do
165
+ expect(spec[:container_name]).to eq "container_for_convoy_id_the_app_posttasks"
166
+ expect(spec[:name]).to eq "the_app"
167
+ expect(spec[:image]).to eq "the_image"
168
+ expect(spec[:type]).to eq "task"
169
+ expect(spec[:cmds]).to eq ["post1_the_app", "post2_the_app"]
170
+ #expect(spec[:sha]).to eq "todo"
171
+ end
172
+
173
+ describe "Application Links" do
174
+ before :each do
175
+ allow(app).to receive(:linked_apps).with(config).and_return(['app1', 'app2'])
176
+ end
177
+
178
+ it "sets an environment variable for the host" do
179
+ env = spec[:env]
180
+
181
+ expect(env['APP1_HOST_ADDR']).to eq "https://convoy_id-app1-the-cluster.com"
182
+ expect(env['APP2_HOST_ADDR']).to eq "https://convoy_id-app2-the-cluster.com"
183
+ end
184
+
185
+ it "links to the host proxy" do
186
+ links = spec[:links]
187
+ expect(links).to include ['host_proxy', 'convoy_id-app1-the-cluster.com']
188
+ expect(links).to include ['host_proxy', 'convoy_id-app2-the-cluster.com']
189
+ end
190
+ end
191
+
192
+ describe "Environment" do
193
+ context "when there's an env_variable" do
194
+ before :each do
195
+ expect(app).to receive(:env_var?) { true }
196
+ expect(app).to receive(:env_var) { "THE_ENV_VAR" }
197
+ end
198
+
199
+ it "sets an environment variable with the config's environment" do
200
+ env = spec[:env]
201
+ expect(env['THE_ENV_VAR']).to eq 'config_env'
202
+ end
203
+ end
204
+
205
+ context "when there's no env variable" do
206
+ it "sets no environment variable" do
207
+ env = spec[:env]
208
+ expect(env['THE_ENV_VAR']).to be_nil
209
+ end
210
+ end
211
+ end
212
+
213
+ describe "Dependency Links" do
214
+ before :each do
215
+ allow(app).to receive(:dependencies).with(config).and_return(['dep1', 'dep2'])
216
+ end
217
+
218
+ it "links to the container" do
219
+ links = spec[:links]
220
+ expect(links).to include ['container_for_convoy_id_dep1', 'dep1']
221
+ expect(links).to include ['container_for_convoy_id_dep2', 'dep2']
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
228
+
@@ -0,0 +1,93 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'cadre/rspec3'
18
+ require 'support/mock_etcd'
19
+ require 'simplecov'
20
+ SimpleCov.start
21
+
22
+ RSpec.configure do |config|
23
+ # The settings below are suggested to provide a good initial experience
24
+ # with RSpec, but feel free to customize to your heart's content.
25
+ =begin
26
+ # These two settings work together to allow you to limit a spec run
27
+ # to individual examples or groups you care about by tagging them with
28
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
29
+ # get run.
30
+ config.filter_run :focus
31
+ config.run_all_when_everything_filtered = true
32
+
33
+ # Many RSpec users commonly either run the entire suite or an individual
34
+ # file, and it's useful to allow more verbose output when running an
35
+ # individual spec file.
36
+ if config.files_to_run.one?
37
+ # Use the documentation formatter for detailed output,
38
+ # unless a formatter has already been configured
39
+ # (e.g. via a command-line flag).
40
+ config.default_formatter = 'doc'
41
+ end
42
+
43
+ # Print the 10 slowest examples and example groups at the
44
+ # end of the spec run, to help surface which specs are running
45
+ # particularly slow.
46
+ config.profile_examples = 10
47
+
48
+ # Run specs in random order to surface order dependencies. If you find an
49
+ # order dependency and want to debug it, you can fix the order by providing
50
+ # the seed, which is printed after each run.
51
+ # --seed 1234
52
+ config.order = :random
53
+
54
+ # Seed global randomization in this process using the `--seed` CLI option.
55
+ # Setting this allows you to use `--seed` to deterministically reproduce
56
+ # test failures related to randomization by passing the same `--seed` value
57
+ # as the one that triggered the failure.
58
+ Kernel.srand config.seed
59
+
60
+ # rspec-expectations config goes here. You can use an alternate
61
+ # assertion/expectation library such as wrong or the stdlib/minitest
62
+ # assertions if you prefer.
63
+ config.expect_with :rspec do |expectations|
64
+ # Enable only the newer, non-monkey-patching expect syntax.
65
+ # For more details, see:
66
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
67
+ expectations.syntax = :expect
68
+ end
69
+
70
+ # rspec-mocks config goes here. You can use an alternate test double
71
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
72
+ config.mock_with :rspec do |mocks|
73
+ # Enable only the newer, non-monkey-patching expect syntax.
74
+ # For more details, see:
75
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
76
+ mocks.syntax = :expect
77
+
78
+ # Prevents you from mocking or stubbing a method that does not exist on
79
+ # a real object. This is generally recommended.
80
+ mocks.verify_partial_doubles = true
81
+ end
82
+ =end
83
+
84
+ require 'navy'
85
+ config.run_all_when_everything_filtered = true
86
+ if config.formatters.empty?
87
+ config.add_formatter(:progress)
88
+ #but do consider:
89
+ #config.add_formatter(Cadre::RSpec3::TrueFeelingsFormatter)
90
+ end
91
+ config.add_formatter(Cadre::RSpec3::NotifyOnCompleteFormatter)
92
+ config.add_formatter(Cadre::RSpec3::QuickfixFormatter)
93
+ end
@@ -0,0 +1,24 @@
1
+ require 'json'
2
+
3
+ class MockEtcd
4
+ def keys
5
+ @keys ||= {}
6
+ end
7
+
8
+ def get(key)
9
+ keys[key]
10
+ end
11
+
12
+ def set(key, value)
13
+ keys[key] = value
14
+ end
15
+
16
+ def setJSON(key, value)
17
+ keys[key] = value.to_json
18
+ end
19
+
20
+ def getJSON(key)
21
+ value = keys[key]
22
+ JSON.parse(value) if value
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: navyrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Navy Project
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Provides utilities for navy project
63
+ email:
64
+ - mail@navyproject.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .simplecov
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - Guardfile
75
+ - LICENSE.txt
76
+ - README.md
77
+ - Rakefile
78
+ - lib/navy.rb
79
+ - lib/navy/app_container_builder.rb
80
+ - lib/navy/application.rb
81
+ - lib/navy/command_builder.rb
82
+ - lib/navy/configuration.rb
83
+ - lib/navy/container.rb
84
+ - lib/navy/container_building.rb
85
+ - lib/navy/etcd.rb
86
+ - lib/navy/logger.rb
87
+ - lib/navy/router.rb
88
+ - lib/navy/runner.rb
89
+ - lib/navy/task_container_builder.rb
90
+ - lib/navy/version.rb
91
+ - navyrb.gemspec
92
+ - spec/lib/navy/app_container_builder_spec.rb
93
+ - spec/lib/navy/application_spec.rb
94
+ - spec/lib/navy/command_builder_spec.rb
95
+ - spec/lib/navy/configuration_spec.rb
96
+ - spec/lib/navy/container_spec.rb
97
+ - spec/lib/navy/etcd_spec.rb
98
+ - spec/lib/navy/router_spec.rb
99
+ - spec/lib/navy/runner_spec.rb
100
+ - spec/lib/navy/task_container_builder_spec.rb
101
+ - spec/spec_helper.rb
102
+ - spec/support/mock_etcd.rb
103
+ homepage: ''
104
+ licenses: []
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ segments:
116
+ - 0
117
+ hash: 3072768792076419997
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 3072768792076419997
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 1.8.23
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Navy library for ruby
133
+ test_files:
134
+ - spec/lib/navy/app_container_builder_spec.rb
135
+ - spec/lib/navy/application_spec.rb
136
+ - spec/lib/navy/command_builder_spec.rb
137
+ - spec/lib/navy/configuration_spec.rb
138
+ - spec/lib/navy/container_spec.rb
139
+ - spec/lib/navy/etcd_spec.rb
140
+ - spec/lib/navy/router_spec.rb
141
+ - spec/lib/navy/runner_spec.rb
142
+ - spec/lib/navy/task_container_builder_spec.rb
143
+ - spec/spec_helper.rb
144
+ - spec/support/mock_etcd.rb