infrataster 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +0 -9
- data/Rakefile +1 -19
- data/infrataster.gemspec +0 -1
- data/lib/infrataster/contexts/capybara_context.rb +2 -10
- data/lib/infrataster/contexts/http_context.rb +1 -1
- data/lib/infrataster/rspec.rb +6 -0
- data/lib/infrataster/server.rb +28 -47
- data/lib/infrataster/version.rb +1 -1
- data/lib/infrataster.rb +0 -1
- data/spec/integration/spec_helper.rb +0 -2
- data/spec/unit/lib/infrataster/server_spec.rb +7 -20
- metadata +2 -17
- data/lib/infrataster/browsermob_proxy.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edd8224440be0202f0981f08c84d41d96452ced1
|
4
|
+
data.tar.gz: 22738c41f609c5a5975251c41aaf4405fb2a451b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0afc168b4efdf3c99d69f8780061c0d4276873c03801ef49394d56922a73e23a15da02a1376c6ff136c90cb5eca7b71e029d9351200b20713b3c4f4b08ebb11e
|
7
|
+
data.tar.gz: f737fd8a7ea09bdda40fffb1fc0e9165a3fe8369d7779a055b6c4b3b56be6ffd1568214e7996784cdbfd89db110138458bdb9e4e7e367492488bc0232eef52c5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -219,15 +219,6 @@ describe server(:app) do
|
|
219
219
|
end
|
220
220
|
```
|
221
221
|
|
222
|
-
If you use `capybara`, you should download and extract [BrowserMob Proxy](http://bmp.lightbody.net/) and set `Infrataster::BrowsermobProxy.bin_path` to binary path in `spec/spec_helper.rb`:
|
223
|
-
|
224
|
-
```ruby
|
225
|
-
# spec/spec_helper.rb
|
226
|
-
Infrataster::BrowsermobProxy.bin_path = '/path/to/browsermob/bin/browsermob'
|
227
|
-
```
|
228
|
-
|
229
|
-
(BrowserMob Proxy is needed to manipulate Host HTTP header.)
|
230
|
-
|
231
222
|
### `mysql_query` resource
|
232
223
|
|
233
224
|
`mysql_query` resource is now in [infrataster-plugin-mysql](https://github.com/ryotarai/infrataster-plugin-mysql).
|
data/Rakefile
CHANGED
@@ -29,25 +29,7 @@ namespace :spec do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
desc 'Prepare'
|
32
|
-
task :prepare => ['
|
33
|
-
end
|
34
|
-
|
35
|
-
task :download_browsermob do
|
36
|
-
dir = File.join(integration_dir, 'vm/vendor/browsermob')
|
37
|
-
unless Dir.exist?(dir)
|
38
|
-
puts yellow("Downloading browsermob...")
|
39
|
-
Dir.mktmpdir do |tmp|
|
40
|
-
open('https://s3-us-west-1.amazonaws.com/lightbody-bmp/browsermob-proxy-2.0-beta-9-bin.zip') do |remote|
|
41
|
-
open(File.join(tmp, 'browsermob-proxy.zip'), 'wb') do |f|
|
42
|
-
f.write(remote.read)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
Dir.chdir(tmp) do
|
46
|
-
system "unzip browsermob-proxy.zip"
|
47
|
-
end
|
48
|
-
FileUtils.mv(File.join(tmp, 'browsermob-proxy-2.0-beta-9'), dir)
|
49
|
-
end
|
50
|
-
end
|
32
|
+
task :prepare => ['start_vm'] do
|
51
33
|
end
|
52
34
|
|
53
35
|
task :berks_vendor do
|
data/infrataster.gemspec
CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "net-ssh-gateway"
|
25
25
|
spec.add_runtime_dependency "capybara"
|
26
26
|
spec.add_runtime_dependency "poltergeist"
|
27
|
-
spec.add_runtime_dependency "browsermob-proxy"
|
28
27
|
spec.add_runtime_dependency "faraday"
|
29
28
|
|
30
29
|
spec.add_development_dependency "bundler", "~> 1.5"
|
@@ -12,11 +12,9 @@ module Infrataster
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.prepare_session
|
15
|
-
proxy = BrowsermobProxy.proxy
|
16
15
|
Capybara.register_driver CAPYBARA_DRIVER_NAME do |app|
|
17
16
|
Capybara::Poltergeist::Driver.new(
|
18
17
|
app,
|
19
|
-
phantomjs_options: ["--proxy=http://#{proxy.host}:#{proxy.port}"],
|
20
18
|
)
|
21
19
|
end
|
22
20
|
Capybara::Session.new(CAPYBARA_DRIVER_NAME)
|
@@ -37,18 +35,12 @@ module Infrataster
|
|
37
35
|
def before_each(example)
|
38
36
|
example.example_group_instance.extend(Capybara::RSpecMatchers)
|
39
37
|
|
40
|
-
|
41
|
-
proxy.header({"Host" => resource.uri.host})
|
38
|
+
session.driver.headers = {"Host" => resource.uri.host}
|
42
39
|
|
43
|
-
address, port
|
44
|
-
server.open_gateway_on_from_server(resource.uri.port)
|
40
|
+
address, port = server.forward_port(resource.uri.port)
|
45
41
|
Capybara.app_host = "http://#{address}:#{port}"
|
46
42
|
end
|
47
43
|
|
48
|
-
def after_each(example)
|
49
|
-
@gateway_finalize_proc.call if @gateway_finalize_proc
|
50
|
-
end
|
51
|
-
|
52
44
|
Capybara::Session::DSL_METHODS.each do |method|
|
53
45
|
define_method method do |*args, &block|
|
54
46
|
page.send method, *args, &block
|
@@ -4,7 +4,7 @@ module Infrataster
|
|
4
4
|
module Contexts
|
5
5
|
class HttpContext < BaseContext
|
6
6
|
def response
|
7
|
-
server.
|
7
|
+
server.forward_port(resource.uri.port) do |address, port|
|
8
8
|
url = "#{resource.uri.scheme}://#{address}:#{port}"
|
9
9
|
|
10
10
|
conn = Faraday.new(:url => url) do |faraday|
|
data/lib/infrataster/rspec.rb
CHANGED
@@ -13,5 +13,11 @@ RSpec.configure do |config|
|
|
13
13
|
config.after(:each) do
|
14
14
|
@infrataster_context.after_each(example) if @infrataster_context.respond_to?(:after_each)
|
15
15
|
end
|
16
|
+
|
17
|
+
config.after(:all) do
|
18
|
+
Infrataster::Server.defined_servers.each do |server|
|
19
|
+
server.shutdown_gateway
|
20
|
+
end
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
data/lib/infrataster/server.rb
CHANGED
@@ -45,63 +45,34 @@ module Infrataster
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def find_available_port
|
49
|
+
# find available local port
|
50
|
+
server = TCPServer.new('127.0.0.1', 0)
|
51
|
+
available_port = server.addr[1]
|
52
|
+
server.close
|
53
53
|
|
54
|
-
|
54
|
+
available_port
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
58
|
-
gateway
|
59
|
-
yield gateway
|
60
|
-
ensure
|
61
|
-
finalize_proc.call
|
57
|
+
def gateway
|
58
|
+
@gateway ||= Net::SSH::Gateway.new(*ssh_start_args)
|
62
59
|
end
|
63
60
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
server.close
|
69
|
-
|
70
|
-
if block_given?
|
71
|
-
with_ssh_gateway do |gateway|
|
72
|
-
gateway.open(host, port, local_port) do |port|
|
73
|
-
yield port
|
74
|
-
end
|
75
|
-
end
|
76
|
-
else
|
77
|
-
gateway, gateway_finalize_proc = ssh_gateway
|
78
|
-
port = gateway.open(host, port, local_port)
|
79
|
-
finalize_proc = Proc.new do
|
80
|
-
gateway.close(port)
|
81
|
-
gateway_finalize_proc.call
|
82
|
-
end
|
83
|
-
[port, finalize_proc]
|
61
|
+
def shutdown_gateway
|
62
|
+
if @gateway
|
63
|
+
@gateway.shutdown!
|
64
|
+
@gateway = nil
|
84
65
|
end
|
85
66
|
end
|
86
67
|
|
87
|
-
def
|
68
|
+
def forward_port(port, &block)
|
69
|
+
host, forwarded_port = _forward_port(port)
|
88
70
|
if block_given?
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
yield '127.0.0.1', new_port
|
93
|
-
end
|
94
|
-
else
|
95
|
-
yield @address, port
|
96
|
-
end
|
71
|
+
return_value = block.call(host, forwarded_port)
|
72
|
+
from.gateway.close(forwarded_port) if from
|
73
|
+
return_value
|
97
74
|
else
|
98
|
-
|
99
|
-
new_port, finalize_proc = from.gateway_open(@address, port)
|
100
|
-
Logger.debug("tunnel: localhost:#{new_port} -> #{from.address} -> #{@address}:#{port}")
|
101
|
-
['127.0.0.1', new_port, finalize_proc]
|
102
|
-
else
|
103
|
-
[@address, port, nil]
|
104
|
-
end
|
75
|
+
[host, forwarded_port]
|
105
76
|
end
|
106
77
|
end
|
107
78
|
|
@@ -119,6 +90,16 @@ module Infrataster
|
|
119
90
|
|
120
91
|
private
|
121
92
|
|
93
|
+
def _forward_port(port)
|
94
|
+
if from
|
95
|
+
local_port = from.gateway.open(@address, port, find_available_port)
|
96
|
+
['127.0.0.1', local_port]
|
97
|
+
else
|
98
|
+
# no need to forward port
|
99
|
+
[@address, port]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
122
103
|
def _ssh_start_args
|
123
104
|
config = {}
|
124
105
|
|
data/lib/infrataster/version.rb
CHANGED
data/lib/infrataster.rb
CHANGED
@@ -12,8 +12,6 @@ Infrataster::Server.define(
|
|
12
12
|
from: :proxy,
|
13
13
|
)
|
14
14
|
|
15
|
-
Infrataster::BrowsermobProxy.bin_path = File.expand_path('../vm/vendor/browsermob/bin/browsermob-proxy', __FILE__)
|
16
|
-
|
17
15
|
RSpec.configure do |config|
|
18
16
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
17
|
config.run_all_when_everything_filtered = true
|
@@ -32,26 +32,13 @@ module Infrataster
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
describe "#ssh_gateway" do
|
36
|
-
it "returns gateway instance and proc for finalizing" do
|
37
|
-
server = Server.new('name', 'address', ssh: {host: 'host', user: 'user'})
|
38
|
-
|
39
|
-
gateway_mock = double
|
40
|
-
expect(gateway_mock).to receive(:shutdown!)
|
41
|
-
expect(Net::SSH::Gateway).to receive(:new).and_return(gateway_mock)
|
42
|
-
gateway, finalize_proc = server.ssh_gateway
|
43
|
-
finalize_proc.call
|
44
|
-
expect(gateway).to eq(gateway_mock)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
35
|
describe "#_ssh_start_args" do
|
49
36
|
context "with ssh option" do
|
50
37
|
context "when options[:ssh][:host] is set" do
|
51
38
|
it 'returns args for SSH.start' do
|
52
|
-
server = Server.new('name', 'address', ssh: {
|
39
|
+
server = Server.new('name', 'address', ssh: {host_name: 'host', user: 'user'})
|
53
40
|
expect(server.send(:_ssh_start_args)).
|
54
|
-
to eq(['host', 'user', {
|
41
|
+
to eq(['host', 'user', {host_name: 'host', user: 'user'}])
|
55
42
|
end
|
56
43
|
end
|
57
44
|
|
@@ -59,7 +46,7 @@ module Infrataster
|
|
59
46
|
it 'returns args for SSH.start' do
|
60
47
|
server = Server.new('name', 'address', ssh: {user: 'user'})
|
61
48
|
expect(server.send(:_ssh_start_args)).
|
62
|
-
to eq(['address', 'user', {
|
49
|
+
to eq(['address', 'user', {host_name: 'address', user: 'user'}])
|
63
50
|
end
|
64
51
|
end
|
65
52
|
end
|
@@ -69,9 +56,9 @@ module Infrataster
|
|
69
56
|
it 'returns args for SSH.start' do
|
70
57
|
server = Server.new('name', 'address', vagrant: true)
|
71
58
|
expect(server).to receive(:ssh_config_for_vagrant).with('name').
|
72
|
-
and_return({
|
59
|
+
and_return({host_name: 'host', user: 'user'})
|
73
60
|
expect(server.send(:_ssh_start_args)).
|
74
|
-
to eq(['host', 'user', {
|
61
|
+
to eq(['host', 'user', {host_name: 'host', user: 'user'}])
|
75
62
|
end
|
76
63
|
end
|
77
64
|
|
@@ -79,9 +66,9 @@ module Infrataster
|
|
79
66
|
it 'returns args for SSH.start' do
|
80
67
|
server = Server.new('name', 'address', vagrant: 'vagrant_vm_name')
|
81
68
|
expect(server).to receive(:ssh_config_for_vagrant).with('vagrant_vm_name').
|
82
|
-
and_return({
|
69
|
+
and_return({host_name: 'host', user: 'user'})
|
83
70
|
expect(server.send(:_ssh_start_args)).
|
84
|
-
to eq(['host', 'user', {
|
71
|
+
to eq(['host', 'user', {host_name: 'host', user: 'user'}])
|
85
72
|
end
|
86
73
|
end
|
87
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infrataster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: browsermob-proxy
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: faraday
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,7 +153,6 @@ files:
|
|
167
153
|
- ci/jenkins_build
|
168
154
|
- infrataster.gemspec
|
169
155
|
- lib/infrataster.rb
|
170
|
-
- lib/infrataster/browsermob_proxy.rb
|
171
156
|
- lib/infrataster/contexts.rb
|
172
157
|
- lib/infrataster/contexts/base_context.rb
|
173
158
|
- lib/infrataster/contexts/capybara_context.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'browsermob/proxy'
|
2
|
-
|
3
|
-
module Infrataster
|
4
|
-
module BrowsermobProxy
|
5
|
-
class << self
|
6
|
-
def server
|
7
|
-
@server ||= start_server
|
8
|
-
end
|
9
|
-
|
10
|
-
def proxy
|
11
|
-
@proxy ||= server.create_proxy
|
12
|
-
end
|
13
|
-
|
14
|
-
def bin_path
|
15
|
-
@bin_path
|
16
|
-
end
|
17
|
-
|
18
|
-
def bin_path=(path)
|
19
|
-
@bin_path = path
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def start_server
|
24
|
-
BrowserMob::Proxy::Server.new(find_bin, timeout: 60).tap do |server|
|
25
|
-
server.start
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def find_bin
|
30
|
-
return @bin_path if @bin_path
|
31
|
-
`which browsermob-proxy`
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|