motherbrain 0.0.0.placeholder → 0.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +196 -0
- data/COMMANDS.md +9 -0
- data/CONTRIBUTING.md +24 -0
- data/Dockerfile +26 -0
- data/Gemfile +60 -2
- data/Guardfile +30 -0
- data/LICENSE +10 -0
- data/MANIFESTS.md +90 -0
- data/OPERATORS_GUIDE.md +195 -0
- data/PLUGINS.md +268 -0
- data/README.md +304 -16
- data/Thorfile +123 -0
- data/VAGRANT.md +116 -0
- data/bin/boot +9 -0
- data/bin/mb +5 -0
- data/bin/mbsrv +5 -0
- data/config.json +32 -0
- data/features/cli/bootstrap_command/configurable_scripts.feature +32 -0
- data/features/cli/configure_command.feature +57 -0
- data/features/cli/environment_command/create_command.feature +22 -0
- data/features/cli/environment_command/destroy_command.feature +33 -0
- data/features/cli/environment_command/from_command.feature +29 -0
- data/features/cli/environment_command/list_command.feature +0 -0
- data/features/cli/node_limiting.feature +47 -0
- data/features/cli/plugin_command/list_command.feature +46 -0
- data/features/cli/service_command/service_command.feature +21 -0
- data/features/cli/template_command.feature +10 -0
- data/features/cli/validate_config.feature +46 -0
- data/features/step_definitions/bootstrap_steps.rb +57 -0
- data/features/step_definitions/chef_server_steps.rb +3 -0
- data/features/step_definitions/configuration_steps.rb +18 -0
- data/features/step_definitions/core_cli_steps.rb +33 -0
- data/features/step_definitions/environment_steps.rb +43 -0
- data/features/step_definitions/node_steps.rb +3 -0
- data/features/step_definitions/plugin_steps.rb +15 -0
- data/features/step_definitions/template_steps.rb +7 -0
- data/features/support/env.rb +68 -0
- data/lib/mb/api.rb +8 -0
- data/lib/mb/api/application.rb +7 -0
- data/lib/mb/api/endpoint.rb +5 -0
- data/lib/mb/api/helpers.rb +38 -0
- data/lib/mb/api/v1.rb +56 -0
- data/lib/mb/api/v1/config_endpoint.rb +12 -0
- data/lib/mb/api/v1/environments_endpoint.rb +174 -0
- data/lib/mb/api/v1/jobs_endpoint.rb +31 -0
- data/lib/mb/api/v1/plugins_endpoint.rb +90 -0
- data/lib/mb/api/validators.rb +5 -0
- data/lib/mb/api/validators/sem_ver.rb +18 -0
- data/lib/mb/application.rb +148 -0
- data/lib/mb/berkshelf.rb +50 -0
- data/lib/mb/bootstrap.rb +9 -0
- data/lib/mb/bootstrap/manager.rb +250 -0
- data/lib/mb/bootstrap/manifest.rb +131 -0
- data/lib/mb/bootstrap/routine.rb +199 -0
- data/lib/mb/bootstrap/template.rb +73 -0
- data/lib/mb/bootstrap/worker.rb +227 -0
- data/lib/mb/chef.rb +6 -0
- data/lib/mb/chef/config.rb +69 -0
- data/lib/mb/chef/run_list_item.rb +115 -0
- data/lib/mb/chef_mutex.rb +304 -0
- data/lib/mb/clean_room_base.rb +39 -0
- data/lib/mb/cli.rb +50 -0
- data/lib/mb/cli/base.rb +51 -0
- data/lib/mb/cli/shell.rb +29 -0
- data/lib/mb/cli/shell/basic.rb +11 -0
- data/lib/mb/cli/shell/color.rb +11 -0
- data/lib/mb/cli/shell/ext.rb +41 -0
- data/lib/mb/cli/sub_command.rb +95 -0
- data/lib/mb/cli/sub_command/component.rb +56 -0
- data/lib/mb/cli/sub_command/plugin.rb +232 -0
- data/lib/mb/cli_client.rb +178 -0
- data/lib/mb/cli_gateway.rb +426 -0
- data/lib/mb/cli_gateway/sub_commands.rb +3 -0
- data/lib/mb/cli_gateway/sub_commands/environment.rb +124 -0
- data/lib/mb/cli_gateway/sub_commands/plugin.rb +148 -0
- data/lib/mb/command.rb +88 -0
- data/lib/mb/command_invoker.rb +235 -0
- data/lib/mb/command_invoker/worker.rb +40 -0
- data/lib/mb/command_runner.rb +233 -0
- data/lib/mb/component.rb +245 -0
- data/lib/mb/config.rb +275 -0
- data/lib/mb/config_manager.rb +75 -0
- data/lib/mb/console.rb +35 -0
- data/lib/mb/cookbook_metadata.rb +73 -0
- data/lib/mb/core_ext.rb +3 -0
- data/lib/mb/core_ext/dir.rb +37 -0
- data/lib/mb/core_ext/enumerable.rb +48 -0
- data/lib/mb/core_ext/file.rb +24 -0
- data/lib/mb/core_ext/signal.rb +11 -0
- data/lib/mb/environment_manager.rb +195 -0
- data/lib/mb/error_handler.rb +212 -0
- data/lib/mb/errors.rb +693 -0
- data/lib/mb/file_system.rb +60 -0
- data/lib/mb/file_system/tempfile.rb +25 -0
- data/lib/mb/gear.rb +154 -0
- data/lib/mb/gears.rb +8 -0
- data/lib/mb/gears/dynamic_service.rb +218 -0
- data/lib/mb/gears/jmx.rb +24 -0
- data/lib/mb/gears/jmx/action.rb +46 -0
- data/lib/mb/gears/mysql.rb +20 -0
- data/lib/mb/gears/mysql/action.rb +190 -0
- data/lib/mb/gears/service.rb +163 -0
- data/lib/mb/gears/service/action.rb +58 -0
- data/lib/mb/gears/service/action_runner.rb +161 -0
- data/lib/mb/grape_ext.rb +3 -0
- data/lib/mb/grape_ext/endpoint.rb +13 -0
- data/lib/mb/group.rb +143 -0
- data/lib/mb/job.rb +183 -0
- data/lib/mb/job/state_machine.rb +34 -0
- data/lib/mb/job/states.rb +46 -0
- data/lib/mb/job_manager.rb +96 -0
- data/lib/mb/job_record.rb +67 -0
- data/lib/mb/job_ticket.rb +25 -0
- data/lib/mb/lock_manager.rb +116 -0
- data/lib/mb/logging.rb +134 -0
- data/lib/mb/logging/basic_format.rb +31 -0
- data/lib/mb/manifest.rb +128 -0
- data/lib/mb/mixin.rb +3 -0
- data/lib/mb/mixin/attribute_setting.rb +265 -0
- data/lib/mb/mixin/coded_exit.rb +49 -0
- data/lib/mb/mixin/locks.rb +54 -0
- data/lib/mb/mixin/services.rb +100 -0
- data/lib/mb/node_filter.rb +97 -0
- data/lib/mb/node_querier.rb +527 -0
- data/lib/mb/plugin.rb +300 -0
- data/lib/mb/plugin_manager.rb +589 -0
- data/lib/mb/provisioner.rb +186 -0
- data/lib/mb/provisioner/manager.rb +213 -0
- data/lib/mb/provisioner/manifest.rb +125 -0
- data/lib/mb/provisioner/provision_data.rb +96 -0
- data/lib/mb/provisioners.rb +5 -0
- data/lib/mb/provisioners/aws.rb +395 -0
- data/lib/mb/rest_gateway.rb +72 -0
- data/lib/mb/ridley_ext.rb +5 -0
- data/lib/mb/ridley_ext/cookbook_object.rb +15 -0
- data/lib/mb/srv_ctl.rb +183 -0
- data/lib/mb/test.rb +104 -0
- data/lib/mb/thor_ext.rb +49 -0
- data/lib/mb/upgrade.rb +6 -0
- data/lib/mb/upgrade/manager.rb +85 -0
- data/lib/mb/upgrade/worker.rb +149 -0
- data/lib/mb/version.rb +1 -1
- data/lib/motherbrain.rb +166 -2
- data/man/man_helper.rb +81 -0
- data/man/mb.1 +494 -0
- data/man/mb.1.html +300 -0
- data/man/mb.1.ronn.erb +62 -0
- data/motherbrain.gemspec +56 -20
- data/scripts/node_name.rb +14 -0
- data/spec/fixtures/cb_metadata.json +7 -0
- data/spec/fixtures/cb_metadata.rb +14 -0
- data/spec/fixtures/fake_id_rsa +27 -0
- data/spec/fixtures/fake_key.pem +27 -0
- data/spec/fixtures/myface-0.1.0/metadata.rb +14 -0
- data/spec/fixtures/myface-0.1.0/motherbrain.rb +0 -0
- data/spec/fixtures/test_env.json +15 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/actor_mocking.rb +7 -0
- data/spec/support/berkshelf.rb +24 -0
- data/spec/support/chef_server.rb +102 -0
- data/spec/support/doubles.rb +11 -0
- data/spec/support/klass.rb +10 -0
- data/spec/support/matchers/each.rb +12 -0
- data/spec/support/matchers/error_codes.rb +5 -0
- data/spec/support/matchers/exit_codes.rb +57 -0
- data/spec/support/matchers/jobs.rb +11 -0
- data/spec/support/spec_helpers.rb +145 -0
- data/spec/unit/mb/api/application_spec.rb +11 -0
- data/spec/unit/mb/api/helpers_spec.rb +5 -0
- data/spec/unit/mb/api/v1/config_endpoint_spec.rb +19 -0
- data/spec/unit/mb/api/v1/environments_endpoint_spec.rb +71 -0
- data/spec/unit/mb/api/v1/jobs_endpoint_spec.rb +24 -0
- data/spec/unit/mb/api/v1/plugins_endpoint_spec.rb +298 -0
- data/spec/unit/mb/api/v1_spec.rb +37 -0
- data/spec/unit/mb/api/validators/sem_ver_spec.rb +5 -0
- data/spec/unit/mb/application_spec.rb +19 -0
- data/spec/unit/mb/berkshelf_spec.rb +38 -0
- data/spec/unit/mb/bootstrap/manager_spec.rb +347 -0
- data/spec/unit/mb/bootstrap/manifest_spec.rb +333 -0
- data/spec/unit/mb/bootstrap/routine_spec.rb +393 -0
- data/spec/unit/mb/bootstrap/template_spec.rb +100 -0
- data/spec/unit/mb/bootstrap/worker_spec.rb +194 -0
- data/spec/unit/mb/chef/config_spec.rb +33 -0
- data/spec/unit/mb/chef/run_list_item_spec.rb +34 -0
- data/spec/unit/mb/chef_mutex_spec.rb +314 -0
- data/spec/unit/mb/clean_room_base_spec.rb +31 -0
- data/spec/unit/mb/cli/base_spec.rb +43 -0
- data/spec/unit/mb/cli/shell/basic_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/color_spec.rb +5 -0
- data/spec/unit/mb/cli/shell/ext_spec.rb +11 -0
- data/spec/unit/mb/cli/shell_spec.rb +38 -0
- data/spec/unit/mb/cli/sub_command/base_spec.rb +102 -0
- data/spec/unit/mb/cli/sub_command/component_spec.rb +5 -0
- data/spec/unit/mb/cli/sub_command/plugin_spec.rb +91 -0
- data/spec/unit/mb/cli/sub_command_spec.rb +43 -0
- data/spec/unit/mb/cli/ui.rb +0 -0
- data/spec/unit/mb/cli_client_spec.rb +51 -0
- data/spec/unit/mb/cli_gateway_spec.rb +386 -0
- data/spec/unit/mb/command_invoker/worker_spec.rb +43 -0
- data/spec/unit/mb/command_invoker_spec.rb +230 -0
- data/spec/unit/mb/command_runner_spec.rb +299 -0
- data/spec/unit/mb/command_spec.rb +76 -0
- data/spec/unit/mb/component_spec.rb +185 -0
- data/spec/unit/mb/config_manager_spec.rb +31 -0
- data/spec/unit/mb/config_spec.rb +408 -0
- data/spec/unit/mb/cookbook_metadata_spec.rb +89 -0
- data/spec/unit/mb/core_ext/dir_spec.rb +92 -0
- data/spec/unit/mb/core_ext/enumerable_spec.rb +104 -0
- data/spec/unit/mb/core_ext/file_spec.rb +58 -0
- data/spec/unit/mb/core_ext/signal_spec.rb +24 -0
- data/spec/unit/mb/environment_manager_spec.rb +166 -0
- data/spec/unit/mb/error_handler_spec.rb +173 -0
- data/spec/unit/mb/errors_spec.rb +132 -0
- data/spec/unit/mb/file_system/tempfile_spec.rb +14 -0
- data/spec/unit/mb/file_system_spec.rb +69 -0
- data/spec/unit/mb/gear_spec.rb +125 -0
- data/spec/unit/mb/gears/dynamic_service_spec.rb +187 -0
- data/spec/unit/mb/gears/jmx/action_spec.rb +34 -0
- data/spec/unit/mb/gears/jmx_spec.rb +32 -0
- data/spec/unit/mb/gears/mysql/action_spec.rb +118 -0
- data/spec/unit/mb/gears/mysql_spec.rb +21 -0
- data/spec/unit/mb/gears/service/action_runner_spec.rb +182 -0
- data/spec/unit/mb/gears/service/action_spec.rb +44 -0
- data/spec/unit/mb/gears/service_spec.rb +124 -0
- data/spec/unit/mb/group_spec.rb +280 -0
- data/spec/unit/mb/job_manager_spec.rb +56 -0
- data/spec/unit/mb/job_record_spec.rb +60 -0
- data/spec/unit/mb/job_spec.rb +201 -0
- data/spec/unit/mb/locks_manager_spec.rb +88 -0
- data/spec/unit/mb/logging_spec.rb +133 -0
- data/spec/unit/mb/manifest_spec.rb +105 -0
- data/spec/unit/mb/mixin/attribute_setting_spec.rb +180 -0
- data/spec/unit/mb/mixin/coded_exit_spec.rb +25 -0
- data/spec/unit/mb/mixin/locks_spec.rb +32 -0
- data/spec/unit/mb/mixin/services_spec.rb +75 -0
- data/spec/unit/mb/node_filter_spec.rb +86 -0
- data/spec/unit/mb/node_querier_spec.rb +532 -0
- data/spec/unit/mb/plugin_manager_spec.rb +724 -0
- data/spec/unit/mb/plugin_spec.rb +247 -0
- data/spec/unit/mb/provisioner/manager_spec.rb +141 -0
- data/spec/unit/mb/provisioner/manifest_spec.rb +182 -0
- data/spec/unit/mb/provisioner/provision_data_spec.rb +113 -0
- data/spec/unit/mb/provisioner_spec.rb +251 -0
- data/spec/unit/mb/provisioners/aws_spec.rb +392 -0
- data/spec/unit/mb/provisioners/environment_factory_spec.rb +108 -0
- data/spec/unit/mb/rest_gateway_spec.rb +13 -0
- data/spec/unit/mb/ridley_ext/cookbook_object_spec.rb +105 -0
- data/spec/unit/mb/srv_ctl_spec.rb +142 -0
- data/spec/unit/mb/upgrade/manager_spec.rb +37 -0
- data/spec/unit/mb/upgrade/worker_spec.rb +219 -0
- data/spec/unit/motherbrain_spec.rb +58 -0
- data/templates/bootstrap.json +8 -0
- data/templates/motherbrain.rb +44 -0
- metadata +694 -15
- data/Rakefile +0 -1
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::Application do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it "has V1 mounted at '/'" do
|
7
|
+
endpoint = subject.endpoints.find { |endpoint| endpoint.options[:app] == MB::API::V1 }
|
8
|
+
expect(endpoint).to_not be_nil
|
9
|
+
expect(endpoint.options[:path]).to include('/')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::V1::ConfigEndpoint do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before(:all) { MB::RestGateway.start(port: 26101) }
|
7
|
+
after(:all) { MB::RestGateway.stop }
|
8
|
+
let(:app) { MB::RestGateway.instance.app }
|
9
|
+
|
10
|
+
describe "GET /config" do
|
11
|
+
let(:current_config) { MB::Application.config }
|
12
|
+
|
13
|
+
it "returns a MB::Config as JSON" do
|
14
|
+
get '/config'
|
15
|
+
last_response.status.should == 200
|
16
|
+
MB::Config.from_json(last_response.body).should be_a(MB::Config)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::V1::ConfigEndpoint do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before(:all) { MB::RestGateway.start(port: 26101) }
|
7
|
+
after(:all) { MB::RestGateway.stop }
|
8
|
+
let(:app) { MB::RestGateway.instance.app }
|
9
|
+
|
10
|
+
describe "GET /environments" do
|
11
|
+
let(:environments) { Array.new }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
environment_manager.should_receive(:list).and_return(environments)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a 200" do
|
18
|
+
get '/environments'
|
19
|
+
last_response.status.should == 200
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "POST /environments/:environment_id/upgrade" do
|
24
|
+
let(:environment_id) { "rpsec_test" }
|
25
|
+
let(:plugin_id) { "myface" }
|
26
|
+
let(:plugin_version) { "1.0.0" }
|
27
|
+
|
28
|
+
it "delegates to the upgrade manager returns 201" do
|
29
|
+
plugin = double('plugin')
|
30
|
+
job = MB::Job.new(:test).ticket
|
31
|
+
plugin_manager.should_receive(:find).with(plugin_id, plugin_version).and_return(plugin)
|
32
|
+
upgrade_manager.should_receive(:async_upgrade).with(environment_id, plugin, anything).and_return(job)
|
33
|
+
|
34
|
+
json_post "/environments/#{environment_id}/upgrade",
|
35
|
+
MultiJson.dump(plugin: { name: plugin_id, version: plugin_version })
|
36
|
+
|
37
|
+
last_response.status.should == 201
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "GET /environments/:environment_id/commands/:plugin_id" do
|
42
|
+
let(:environment_id) { "rspec_test" }
|
43
|
+
let(:plugin_id) { "myface" }
|
44
|
+
let(:plugin) { double('plugin', commands: []) }
|
45
|
+
|
46
|
+
it "returns the commands of the plugin for the environment" do
|
47
|
+
plugin_manager.should_receive(:for_environment).with(plugin_id, environment_id).and_return(plugin)
|
48
|
+
|
49
|
+
get "/environments/#{environment_id}/commands/#{plugin_id}"
|
50
|
+
last_response.status.should == 200
|
51
|
+
MultiJson.decode(last_response.body).should eql(plugin.commands)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "GET /environments/:environment_id/commands/:plugin_id/:component_id" do
|
56
|
+
let(:environment_id) { "rspec_test" }
|
57
|
+
let(:plugin_id) { "myface" }
|
58
|
+
let(:component_id) { "appsrv" }
|
59
|
+
let(:component) { double('component', commands: []) }
|
60
|
+
let(:plugin) { double('plugin') }
|
61
|
+
|
62
|
+
it "returns the commands of the plugin for the environment" do
|
63
|
+
plugin.should_receive(:component!).with(component_id).and_return(component)
|
64
|
+
plugin_manager.should_receive(:for_environment).with(plugin_id, environment_id).and_return(plugin)
|
65
|
+
|
66
|
+
get "/environments/#{environment_id}/commands/#{plugin_id}/#{component_id}"
|
67
|
+
last_response.status.should == 200
|
68
|
+
MultiJson.decode(last_response.body).should eql(component.commands)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::V1::JobsEndpoint do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before(:all) { MB::RestGateway.start(port: 26101) }
|
7
|
+
after(:all) { MB::RestGateway.stop }
|
8
|
+
let(:app) { MB::RestGateway.instance.app }
|
9
|
+
|
10
|
+
describe "GET /jobs" do
|
11
|
+
it "returns all jobs" do
|
12
|
+
get '/jobs'
|
13
|
+
last_response.status.should == 200
|
14
|
+
JSON.parse(last_response.body).should have(0).items
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "GET /jobs/:id" do
|
19
|
+
it "returns 404 if missing" do
|
20
|
+
get '/jobs/456'
|
21
|
+
last_response.status.should == 404
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::V1::PluginsEndpoint do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before(:all) { MB::RestGateway.start(port: 26101) }
|
7
|
+
after(:all) { MB::RestGateway.stop }
|
8
|
+
let(:app) { MB::RestGateway.instance.app }
|
9
|
+
|
10
|
+
describe "GET /plugins" do
|
11
|
+
it "returns all loaded plugins as JSON" do
|
12
|
+
get '/plugins'
|
13
|
+
last_response.status.should == 200
|
14
|
+
JSON.parse(last_response.body).should have(MB::Application.plugin_manager.list.length).items
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "GET /plugins/:name" do
|
19
|
+
context "when a matching plugin is found" do
|
20
|
+
let(:one) do
|
21
|
+
metadata = MB::CookbookMetadata.new do
|
22
|
+
name 'apple'
|
23
|
+
version '1.0.0'
|
24
|
+
end
|
25
|
+
MB::Plugin.new(metadata)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:two) do
|
29
|
+
metadata = MB::CookbookMetadata.new do
|
30
|
+
name 'apple'
|
31
|
+
version '2.0.0'
|
32
|
+
end
|
33
|
+
MB::Plugin.new(metadata)
|
34
|
+
end
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
MB::PluginManager.instance.clear_plugins
|
38
|
+
MB::PluginManager.instance.add(one)
|
39
|
+
MB::PluginManager.instance.add(two)
|
40
|
+
get '/plugins/apple'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns 200" do
|
44
|
+
last_response.status.should == 200
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has an item for each plugin version" do
|
48
|
+
JSON.parse(last_response.body).should have(2).items
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when no plugin versions are found for plugin" do
|
53
|
+
before(:each) { get '/plugins/test' }
|
54
|
+
|
55
|
+
it "returns 200" do
|
56
|
+
last_response.status.should == 200
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns an empty array" do
|
60
|
+
result = JSON.parse(last_response.body)
|
61
|
+
result.should be_empty
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "GET /plugins/:name/latest" do
|
67
|
+
let(:one) do
|
68
|
+
metadata = MB::CookbookMetadata.new do
|
69
|
+
name 'apple'
|
70
|
+
version '1.0.0'
|
71
|
+
end
|
72
|
+
MB::Plugin.new(metadata)
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:two) do
|
76
|
+
metadata = MB::CookbookMetadata.new do
|
77
|
+
name 'apple'
|
78
|
+
version '2.0.0'
|
79
|
+
end
|
80
|
+
MB::Plugin.new(metadata)
|
81
|
+
end
|
82
|
+
|
83
|
+
before(:each) do
|
84
|
+
MB::PluginManager.instance.add(one)
|
85
|
+
MB::PluginManager.instance.add(two)
|
86
|
+
get '/plugins/apple/latest'
|
87
|
+
end
|
88
|
+
|
89
|
+
after(:each) do
|
90
|
+
MB::PluginManager.instance.clear_plugins
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns 200" do
|
94
|
+
last_response.status.should == 200
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns the latest plugin version" do
|
98
|
+
response = JSON.parse(last_response.body)
|
99
|
+
response["name"].should eql("apple")
|
100
|
+
response["version"]["major"].should eql(2)
|
101
|
+
response["version"]["minor"].should eql(0)
|
102
|
+
response["version"]["patch"].should eql(0)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "GET /plugins/:name/:version" do
|
107
|
+
context "when the a matching plugin is found" do
|
108
|
+
let(:one) do
|
109
|
+
metadata = MB::CookbookMetadata.new do
|
110
|
+
name 'apple'
|
111
|
+
version '1.0.0'
|
112
|
+
end
|
113
|
+
MB::Plugin.new(metadata)
|
114
|
+
end
|
115
|
+
|
116
|
+
before(:each) do
|
117
|
+
MB::PluginManager.instance.add(one)
|
118
|
+
end
|
119
|
+
|
120
|
+
after(:each) do
|
121
|
+
MB::PluginManager.instance.clear_plugins
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns a 200 response" do
|
125
|
+
get '/plugins/apple/1_0_0'
|
126
|
+
last_response.status.should == 200
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns a plugin for the given name and version" do
|
130
|
+
get '/plugins/apple/1_0_0'
|
131
|
+
response = JSON.parse(last_response.body)
|
132
|
+
response["name"].should eql("apple")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when plugin not found" do
|
137
|
+
before(:each) { get '/plugins/test/1_0_0' }
|
138
|
+
|
139
|
+
it "returns a 404 response" do
|
140
|
+
last_response.status.should == 404
|
141
|
+
end
|
142
|
+
|
143
|
+
it "has the error code for PluginNotFound" do
|
144
|
+
result = JSON.parse(last_response.body)
|
145
|
+
result.should have_key("code")
|
146
|
+
result["code"].should be_error_code(MB::PluginNotFound)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "when an invalid version string is given" do
|
151
|
+
before(:each) { get '/plugins/test/fake_version' }
|
152
|
+
|
153
|
+
it "returns a 400 response" do
|
154
|
+
last_response.status.should == 400
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "GET /plugins/:name/latest/commands" do
|
160
|
+
let(:one) do
|
161
|
+
metadata = MB::CookbookMetadata.new do
|
162
|
+
name 'apple'
|
163
|
+
version '1.0.0'
|
164
|
+
end
|
165
|
+
MB::Plugin.new(metadata)
|
166
|
+
end
|
167
|
+
|
168
|
+
before(:each) do
|
169
|
+
MB::PluginManager.instance.add(one)
|
170
|
+
get '/plugins/apple/latest/commands'
|
171
|
+
end
|
172
|
+
|
173
|
+
after(:each) do
|
174
|
+
MB::PluginManager.instance.clear_plugins
|
175
|
+
end
|
176
|
+
|
177
|
+
it "returns a 200 response" do
|
178
|
+
last_response.status.should == 200
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "GET /plugins/:name/:version/commands" do
|
183
|
+
let(:one) do
|
184
|
+
metadata = MB::CookbookMetadata.new do
|
185
|
+
name 'apple'
|
186
|
+
version '1.0.0'
|
187
|
+
end
|
188
|
+
MB::Plugin.new(metadata)
|
189
|
+
end
|
190
|
+
|
191
|
+
before(:each) do
|
192
|
+
MB::PluginManager.instance.add(one)
|
193
|
+
get '/plugins/apple/1_0_0/commands'
|
194
|
+
end
|
195
|
+
|
196
|
+
after(:each) do
|
197
|
+
MB::PluginManager.instance.clear_plugins
|
198
|
+
end
|
199
|
+
|
200
|
+
it "returns a 200 response" do
|
201
|
+
last_response.status.should == 200
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
describe "GET /plugins/:name/latest/components" do
|
206
|
+
let(:one) do
|
207
|
+
metadata = MB::CookbookMetadata.new do
|
208
|
+
name 'apple'
|
209
|
+
version '1.0.0'
|
210
|
+
end
|
211
|
+
MB::Plugin.new(metadata)
|
212
|
+
end
|
213
|
+
|
214
|
+
before(:each) do
|
215
|
+
MB::PluginManager.instance.add(one)
|
216
|
+
get '/plugins/apple/latest/components'
|
217
|
+
end
|
218
|
+
|
219
|
+
after(:each) do
|
220
|
+
MB::PluginManager.instance.clear_plugins
|
221
|
+
end
|
222
|
+
|
223
|
+
it "returns a 200 response" do
|
224
|
+
last_response.status.should == 200
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe "GET /plugins/:name/:version/components" do
|
229
|
+
let(:one) do
|
230
|
+
metadata = MB::CookbookMetadata.new do
|
231
|
+
name 'apple'
|
232
|
+
version '1.0.0'
|
233
|
+
end
|
234
|
+
MB::Plugin.new(metadata)
|
235
|
+
end
|
236
|
+
|
237
|
+
before(:each) do
|
238
|
+
MB::PluginManager.instance.add(one)
|
239
|
+
get '/plugins/apple/1_0_0/components'
|
240
|
+
end
|
241
|
+
|
242
|
+
after(:each) do
|
243
|
+
MB::PluginManager.instance.clear_plugins
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns a 200 response" do
|
247
|
+
last_response.status.should == 200
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "GET /plugins/:name/latest/components/:component_id/commands" do
|
252
|
+
let(:one) do
|
253
|
+
metadata = MB::CookbookMetadata.new do
|
254
|
+
name 'apple'
|
255
|
+
version '1.0.0'
|
256
|
+
end
|
257
|
+
MB::Plugin.new(metadata)
|
258
|
+
end
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
MB::PluginManager.instance.add(one)
|
262
|
+
get '/plugins/apple/latest/components/myface/commands'
|
263
|
+
end
|
264
|
+
|
265
|
+
after(:each) do
|
266
|
+
MB::PluginManager.instance.clear_plugins
|
267
|
+
end
|
268
|
+
|
269
|
+
it "returns a 200 response" do
|
270
|
+
last_response.status.should == 200
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "GET /plugins/:name/:version/components/:component_id/commands" do
|
275
|
+
let(:one) do
|
276
|
+
metadata = MB::CookbookMetadata.new do
|
277
|
+
name 'apple'
|
278
|
+
version '1.0.0'
|
279
|
+
end
|
280
|
+
MB::Plugin.new(metadata) do
|
281
|
+
component "myface" do; end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
before(:each) do
|
286
|
+
MB::PluginManager.instance.add(one)
|
287
|
+
get '/plugins/apple/1_0_0/components/myface/commands'
|
288
|
+
end
|
289
|
+
|
290
|
+
after(:each) do
|
291
|
+
MB::PluginManager.instance.clear_plugins
|
292
|
+
end
|
293
|
+
|
294
|
+
it "returns a 200 response" do
|
295
|
+
last_response.status.should == 200
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MB::API::V1 do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before(:all) { MB::RestGateway.start(port: 26101) }
|
7
|
+
after(:all) { MB::RestGateway.stop }
|
8
|
+
let(:app) { MB::RestGateway.instance.app }
|
9
|
+
|
10
|
+
describe "API Error handling" do
|
11
|
+
describe "MB errors" do
|
12
|
+
it "returns a JSON response containing a code and message" do
|
13
|
+
get '/mb_error'
|
14
|
+
last_response.status.should == 500
|
15
|
+
json = JSON.parse(last_response.body)
|
16
|
+
|
17
|
+
json.should have_key("code")
|
18
|
+
json["code"].should eql(1000)
|
19
|
+
json.should have_key("message")
|
20
|
+
json["message"].should eql("a nice error message")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Unknown errors" do
|
25
|
+
it "returns a JSON response containing a -1 code and message" do
|
26
|
+
get '/unknown_error'
|
27
|
+
last_response.status.should == 500
|
28
|
+
json = JSON.parse(last_response.body)
|
29
|
+
|
30
|
+
json.should have_key("code")
|
31
|
+
json["code"].should eql(-1)
|
32
|
+
json.should have_key("message")
|
33
|
+
json["message"].should eql("hidden error message")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|