isolated_database_service 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55f7e14d9296964518c990bcc9c4fa4b4fd49b76
4
+ data.tar.gz: 7d9f5cd338669f0029f1496fbb72aa04e3c32001
5
+ SHA512:
6
+ metadata.gz: 0ed111a96129df096d78c9a5531546a5310be7f6b4c23da962f8d62e0ad94a8e0dd0e9cc701e84ff52996ded308a8aa8790381b2513e5a1cfa0f04ae3606f79e
7
+ data.tar.gz: 1882cd6621a6374808d5aeee43b448b85ebe5b55211c5d94f6b7548e22c4e54b353d08c8c138949965b3eb2ff18a39f598048e5080513f3f6fa1357c4184a70f
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ cache: bundler
2
+ sudo: false
3
+ language: ruby
4
+ rvm:
5
+ - 2.1
6
+ - 2.2
7
+ script: bundle exec rspec
8
+
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bump'
4
+ gem 'sinatra'
5
+ gem 'sinatra-contrib'
6
+ gem 'rack-parser', :require => 'rack/parser'
7
+ gem 'isolated_server'
8
+ gem 'mysql2'
9
+
10
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ isolated_database_service (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ backports (3.6.7)
10
+ bump (0.5.3)
11
+ diff-lcs (1.2.5)
12
+ isolated_server (0.4.7)
13
+ multi_json (1.11.2)
14
+ mysql2 (0.4.2)
15
+ rack (1.6.4)
16
+ rack-parser (0.6.1)
17
+ rack
18
+ rack-protection (1.5.3)
19
+ rack
20
+ rack-test (0.6.3)
21
+ rack (>= 1.0)
22
+ rake (10.4.2)
23
+ rspec (3.4.0)
24
+ rspec-core (~> 3.4.0)
25
+ rspec-expectations (~> 3.4.0)
26
+ rspec-mocks (~> 3.4.0)
27
+ rspec-core (3.4.1)
28
+ rspec-support (~> 3.4.0)
29
+ rspec-expectations (3.4.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-mocks (3.4.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-support (3.4.1)
36
+ sinatra (1.4.6)
37
+ rack (~> 1.4)
38
+ rack-protection (~> 1.4)
39
+ tilt (>= 1.3, < 3)
40
+ sinatra-contrib (1.4.6)
41
+ backports (>= 2.0)
42
+ multi_json
43
+ rack-protection
44
+ rack-test
45
+ sinatra (~> 1.4.0)
46
+ tilt (>= 1.3, < 3)
47
+ tilt (2.0.1)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bump
54
+ bundler
55
+ isolated_database_service!
56
+ isolated_server
57
+ mysql2
58
+ rack-parser
59
+ rake
60
+ rspec
61
+ sinatra
62
+ sinatra-contrib
63
+
64
+ BUNDLED WITH
65
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # isolated_database_service
2
+
3
+ [![Build Status](https://travis-ci.org/ggrossman/isolated_database_service.png)](https://travis-ci.org/ggrossman/isolated_database_service)
4
+
5
+ Microservice wrapper for [isolated_server](https://github.com/gabetax/isolated_server)
6
+
7
+ [isolated_server](https://github.com/gabetax/isolated_server) lets you easily bring up and down clusters of
8
+ temporary MySQL and MongoDB servers on your local machine or CI environment for testing purposes.
9
+ However, it can only be used from Ruby.
10
+
11
+ This is a wrapper for [isolated_server](https://github.com/gabetax/isolated_server) which provides a
12
+ simple JSON REST API for it, making it language-agnostic and callable from Java, Scala, Python, etc.
13
+
14
+ ## Running
15
+
16
+ The script `boot_isolated_database_service` can be used to start the service:
17
+
18
+ ```bash
19
+ bin/boot_isolated_database_service
20
+ ```
21
+
22
+ Pass the `-p` argument to configure the listen port, or Sinatra's default is used.
23
+
24
+ ```bash
25
+ bin/boot_isolated_database_service -p 9000
26
+ ```
27
+
28
+ ## JSON API
29
+
30
+ ### Create a Server
31
+ `POST /servers`
32
+
33
+ Boots up a new MySQL or MongoDB server.
34
+
35
+ #### Request JSON
36
+
37
+ ```json
38
+ {
39
+ "server": {
40
+ "type": "mysql"
41
+ }
42
+ }
43
+ ```
44
+
45
+ `type` may be set to either `mysql` or `mongodb`. If not supplied, `mysql` is assumed.
46
+
47
+ #### Using curl
48
+
49
+ ```bash
50
+ curl -H "Content-Type: application/json" -X POST \
51
+ -d '{"server":{"type":"mysql"}}' http://localhost:9292/servers
52
+ ```
53
+
54
+ #### Example Response
55
+
56
+ ```http
57
+ 201 Created
58
+
59
+ {
60
+ "server": {
61
+ "id": 1,
62
+ "type": "mysql",
63
+ "port": 41536,
64
+ "up": true
65
+ }
66
+ }
67
+ ```
68
+
69
+ ### List Servers
70
+ `GET /servers`
71
+
72
+ Lists the servers currently available.
73
+
74
+ #### Using curl
75
+
76
+ ```bash
77
+ curl http://localhost:9292/servers
78
+ ```
79
+
80
+ #### Example Response
81
+
82
+ ```http
83
+ 200 OK
84
+
85
+ {
86
+ "servers": [
87
+ {
88
+ "id": 1,
89
+ "port": 30979,
90
+ "up": true,
91
+ "type":"mysql"
92
+ },
93
+ {
94
+ "id": 2,
95
+ "port": 33212,
96
+ "up": true,
97
+ "type": "mysql"
98
+ }
99
+ ]
100
+ }
101
+ ```
102
+
103
+ ### Update Server
104
+ `PUT /servers/{id}`
105
+
106
+ Updates a server, bringing it up or down, setting read-only/read-write, etc.
107
+
108
+ #### Request JSON
109
+
110
+ ```json
111
+ {
112
+ "server": {
113
+ "up": true,
114
+ "rw": true,
115
+ "master_id": 1
116
+ }
117
+ }
118
+ ```
119
+
120
+ All of the parameters `up`, `rw` and `master_id` are optional.
121
+
122
+ `up`: `true` will bring the server up, `false` will bring it down.
123
+
124
+ `rw`: `true` will set the server to read/write, `false` will set it to read-only.
125
+
126
+ `master_id`: The ID of another server can be given to make this server a slave of that master.
127
+
128
+ #### Using curl
129
+
130
+ ```bash
131
+ curl -H "Content-Type: application/json" -X PUT \
132
+ -d '{"server":{"up":false}}' http://localhost:9292/servers/2
133
+ ```
134
+
135
+ #### Example Response
136
+
137
+ ```http
138
+ 200 OK
139
+
140
+ {
141
+ "server": [
142
+ {
143
+ "id": 1,
144
+ "type": "mysql",
145
+ "up": true
146
+ }
147
+ ]
148
+ }
149
+ ```
150
+
151
+ ### Delete Server
152
+ `DELETE /servers/{id}`
153
+
154
+ Deletes a server, bringing it down and removing it from the server list.
155
+
156
+ #### Using curl
157
+
158
+ ```bash
159
+ curl -X DELETE http://localhost:9292/servers/2
160
+ ```
161
+
162
+ #### Example Response
163
+
164
+ ```http
165
+ 204 No Content
166
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require "bump/tasks"
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ cd `dirname "$0"`/..
3
+ bundle exec rackup config.ru "$@"
data/config.ru ADDED
@@ -0,0 +1,8 @@
1
+ # config.ru (run with rackup)
2
+ require 'rack/parser'
3
+ require 'isolated_database_service'
4
+ require 'json'
5
+
6
+ use Rack::Parser, :parsers => { 'application/json' => Proc.new { |data| JSON.parse data } }
7
+
8
+ run IsolatedDatabaseService::Application
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'isolated_database_service/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "isolated_database_service"
8
+ gem.version = IsolatedDatabaseService::VERSION
9
+ gem.authors = ["Gary Grossman"]
10
+ gem.email = ["gary.grossman@gmail.com"]
11
+ gem.summary = %q{Service wrapper for the isolated_server gem.}
12
+ gem.description = %q{A small service that allows you to easily spin up new local mysql/mongo servers for testing purposes.}
13
+ gem.homepage = "http://github.com/ggrossman/isolated_database_service"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "bundler"
22
+ gem.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,3 @@
1
+ module IsolatedDatabaseService
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,132 @@
1
+ require 'sinatra'
2
+ require 'sinatra/json'
3
+ require 'isolated_server'
4
+ require 'isolated_server/mysql'
5
+ require 'isolated_server/mongodb'
6
+
7
+ module IsolatedDatabaseService
8
+ class ServerList
9
+ attr_accessor :next_id, :servers
10
+
11
+ def initialize
12
+ @next_id = 1
13
+ @servers = {}
14
+ end
15
+
16
+ def add_server(server)
17
+ id = @next_id
18
+ @servers[id] = server
19
+ @next_id += 1
20
+ id
21
+ end
22
+
23
+ def delete_server(id)
24
+ @servers.delete(id)
25
+ end
26
+
27
+ def count
28
+ @servers.length
29
+ end
30
+
31
+ def clear
32
+ @servers = {}
33
+ @next_id = 1
34
+ end
35
+ end
36
+
37
+ class Application < Sinatra::Base
38
+ set :servers, ServerList.new
39
+
40
+ post '/servers' do
41
+ halt(400) unless params[:server]
42
+ server_type = params[:server][:type] || 'mysql'
43
+
44
+ new_server = case server_type
45
+ when 'mysql'
46
+ IsolatedServer::Mysql.new
47
+ when 'mongodb'
48
+ IsolatedServer::Mongodb.new
49
+ else
50
+ halt(40)
51
+ end
52
+
53
+ id = servers.add_server(new_server)
54
+ new_server.boot!
55
+ status 201
56
+ json :server => present_server(id, new_server)
57
+ end
58
+
59
+ get '/servers' do
60
+ json :servers => servers.servers.map { |id, server| present_server(id, server) }
61
+ end
62
+
63
+ put '/servers/:id' do
64
+ halt(400) unless params[:server]
65
+
66
+ up = parse_boolean(params[:server][:up])
67
+ unless up.nil?
68
+ if up
69
+ server.up!
70
+ else
71
+ server.down!
72
+ end
73
+ end
74
+
75
+ rw = parse_boolean(params[:server][:rw])
76
+ server.set_rw(rw) unless rw.nil?
77
+
78
+ master_id = params[:server][:master_id]
79
+ unless master_id.nil?
80
+ master_server = servers.servers[master_id.to_i] || halt(400)
81
+ server.make_slave_of(master_server)
82
+ end
83
+
84
+ json :server => present_server(params[:id].to_i, server)
85
+ end
86
+
87
+ delete '/servers/:id' do
88
+ server.down!
89
+ servers.delete_server(params[:id].to_i)
90
+ status 204
91
+ end
92
+
93
+ private
94
+
95
+ def servers
96
+ settings.servers
97
+ end
98
+
99
+ def server
100
+ @server ||= servers.servers[params[:id].to_i] || halt(404)
101
+ end
102
+
103
+ def parse_boolean(value)
104
+ if truthy?(value)
105
+ true
106
+ elsif falsy?(value)
107
+ false
108
+ else
109
+ nil
110
+ end
111
+ end
112
+
113
+ def truthy?(value)
114
+ ['true', 't', '1', 'yes', true].include?(value)
115
+ end
116
+
117
+ def falsy?(value)
118
+ ['false', 'f', '0', 'no', false].include?(value)
119
+ end
120
+
121
+ def present_server(id, server)
122
+ server_type = if server.is_a?(IsolatedServer::Mysql)
123
+ 'mysql'
124
+ elsif server.is_a?(IsolatedServer::Mongodb)
125
+ 'mongodb'
126
+ else
127
+ 'unknown'
128
+ end
129
+ {id: id, port: server.port, up: server.up?, type: server_type}
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,87 @@
1
+ require File.expand_path '../spec_helper.rb', __FILE__
2
+
3
+ describe IsolatedDatabaseService do
4
+ before do
5
+ allow_any_instance_of(IsolatedServer::Mysql).to receive(:boot!).and_return(true)
6
+ end
7
+
8
+ describe "GET /servers" do
9
+ before do
10
+ 3.times do
11
+ post "/servers", {server: {type: 'mysql'}}
12
+ end
13
+ end
14
+
15
+ it "should list out the servers" do
16
+ get "/servers"
17
+ expect(last_response).to be_ok
18
+ parsed_body = JSON.parse(last_response.body)
19
+ expect(parsed_body['servers'].length).to eq(3)
20
+ end
21
+ end
22
+
23
+ describe "POST /servers" do
24
+ it "should reject bad arguments" do
25
+ post "/servers"
26
+ expect(last_response).to be_bad_request
27
+ end
28
+
29
+ it "should create a server" do
30
+ post "/servers", {server: {type: 'mysql'}}
31
+ expect(last_response).to be_created
32
+ expect(app().servers.count).to eq(1)
33
+ end
34
+ end
35
+
36
+ describe "PUT /servers/:id" do
37
+ before do
38
+ @server = double()
39
+ allow(@server).to receive(:port).and_return(5000)
40
+ allow(@server).to receive(:up?).and_return(true)
41
+ @id = app().servers.add_server(@server)
42
+ end
43
+
44
+ it "should bring up a server" do
45
+ expect(@server).to receive(:up!).and_return(true)
46
+ put "/servers/#{@id}", {server: {up: true}}
47
+ end
48
+
49
+ it "should bring down a server" do
50
+ expect(@server).to receive(:down!).and_return(true)
51
+ put "/servers/#{@id}", {server: {up: false}}
52
+ end
53
+
54
+ it "should set a server to read/write" do
55
+ expect(@server).to receive(:set_rw).with(true).and_return(true)
56
+ put "/servers/#{@id}", {server: {rw: true}}
57
+ end
58
+
59
+ it "should set a server to read-only" do
60
+ expect(@server).to receive(:set_rw).with(false).and_return(true)
61
+ put "/servers/#{@id}", {server: {rw: false}}
62
+ end
63
+
64
+ it "should set a server's master" do
65
+ @master_server = double()
66
+ @master_id = app().servers.add_server(@master_server)
67
+ expect(@server).to receive(:make_slave_of).with(@master_server).and_return(true)
68
+ put "/servers/#{@id}", {server: {master_id: @master_id}}
69
+ end
70
+ end
71
+
72
+ describe "DELETE /servers/:id" do
73
+ before do
74
+ 3.times do
75
+ post "/servers", {server: {type: 'mysql'}}
76
+ end
77
+ end
78
+
79
+ it "should delete a server" do
80
+ expect(app().servers.count).to eq(3)
81
+ expect(app().servers.servers[1]).to receive(:down!)
82
+ delete "/servers/1"
83
+ expect(last_response.status).to eq(204)
84
+ expect(app().servers.count).to eq(2)
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,115 @@
1
+ require 'rack/test'
2
+ require 'isolated_database_service'
3
+
4
+ ENV['RACK_ENV'] = 'test'
5
+
6
+ module RSpecMixin
7
+ include Rack::Test::Methods
8
+
9
+ def app()
10
+ IsolatedDatabaseService::Application
11
+ end
12
+ end
13
+
14
+ # This file was generated by the `rspec --init` command. Conventionally, all
15
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
16
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
17
+ # this file to always be loaded, without a need to explicitly require it in any
18
+ # files.
19
+ #
20
+ # Given that it is always loaded, you are encouraged to keep this file as
21
+ # light-weight as possible. Requiring heavyweight dependencies from this file
22
+ # will add to the boot time of your test suite on EVERY test run, even for an
23
+ # individual file that may not need all of that loaded. Instead, consider making
24
+ # a separate helper file that requires the additional dependencies and performs
25
+ # the additional setup, and require it from the spec files that actually need
26
+ # it.
27
+ #
28
+ # The `.rspec` file also contains a few flags that are not defaults but that
29
+ # users commonly want.
30
+ #
31
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
32
+ RSpec.configure do |config|
33
+ config.include RSpecMixin
34
+
35
+ # rspec-expectations config goes here. You can use an alternate
36
+ # assertion/expectation library such as wrong or the stdlib/minitest
37
+ # assertions if you prefer.
38
+ config.expect_with :rspec do |expectations|
39
+ # This option will default to `true` in RSpec 4. It makes the `description`
40
+ # and `failure_message` of custom matchers include text for helper methods
41
+ # defined using `chain`, e.g.:
42
+ # be_bigger_than(2).and_smaller_than(4).description
43
+ # # => "be bigger than 2 and smaller than 4"
44
+ # ...rather than:
45
+ # # => "be bigger than 2"
46
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
47
+ end
48
+
49
+ # rspec-mocks config goes here. You can use an alternate test double
50
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
51
+ config.mock_with :rspec do |mocks|
52
+ # Prevents you from mocking or stubbing a method that does not exist on
53
+ # a real object. This is generally recommended, and will default to
54
+ # `true` in RSpec 4.
55
+ mocks.verify_partial_doubles = true
56
+ end
57
+
58
+ config.before(:each) do
59
+ app().servers.clear
60
+ end
61
+
62
+ # The settings below are suggested to provide a good initial experience
63
+ # with RSpec, but feel free to customize to your heart's content.
64
+ =begin
65
+ # These two settings work together to allow you to limit a spec run
66
+ # to individual examples or groups you care about by tagging them with
67
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
68
+ # get run.
69
+ config.filter_run :focus
70
+ config.run_all_when_everything_filtered = true
71
+
72
+ # Allows RSpec to persist some state between runs in order to support
73
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
74
+ # you configure your source control system to ignore this file.
75
+ config.example_status_persistence_file_path = "spec/examples.txt"
76
+
77
+ # Limits the available syntax to the non-monkey patched syntax that is
78
+ # recommended. For more details, see:
79
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
80
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
81
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
82
+ config.disable_monkey_patching!
83
+
84
+ # This setting enables warnings. It's recommended, but in some cases may
85
+ # be too noisy due to issues in dependencies.
86
+ config.warnings = true
87
+
88
+ # Many RSpec users commonly either run the entire suite or an individual
89
+ # file, and it's useful to allow more verbose output when running an
90
+ # individual spec file.
91
+ if config.files_to_run.one?
92
+ # Use the documentation formatter for detailed output,
93
+ # unless a formatter has already been configured
94
+ # (e.g. via a command-line flag).
95
+ config.default_formatter = 'doc'
96
+ end
97
+
98
+ # Print the 10 slowest examples and example groups at the
99
+ # end of the spec run, to help surface which specs are running
100
+ # particularly slow.
101
+ config.profile_examples = 10
102
+
103
+ # Run specs in random order to surface order dependencies. If you find an
104
+ # order dependency and want to debug it, you can fix the order by providing
105
+ # the seed, which is printed after each run.
106
+ # --seed 1234
107
+ config.order = :random
108
+
109
+ # Seed global randomization in this process using the `--seed` CLI option.
110
+ # Setting this allows you to use `--seed` to deterministically reproduce
111
+ # test failures related to randomization by passing the same `--seed` value
112
+ # as the one that triggered the failure.
113
+ Kernel.srand config.seed
114
+ =end
115
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: isolated_database_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary Grossman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A small service that allows you to easily spin up new local mysql/mongo
56
+ servers for testing purposes.
57
+ email:
58
+ - gary.grossman@gmail.com
59
+ executables:
60
+ - boot_isolated_service
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/boot_isolated_service
72
+ - config.ru
73
+ - isolated_database_service.gemspec
74
+ - lib/isolated_database_service.rb
75
+ - lib/isolated_database_service/version.rb
76
+ - spec/isolated_service_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: http://github.com/ggrossman/isolated_database_service
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Service wrapper for the isolated_server gem.
101
+ test_files:
102
+ - spec/isolated_service_spec.rb
103
+ - spec/spec_helper.rb