infrataster 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80561f12bb0ff0f01741cdb57baaea2d56513800
4
- data.tar.gz: aea47ce92d3d24b3f8ac017f2aad48a8e71213da
3
+ metadata.gz: f005787139f6d46caa2c8bbc1f1972d020521e88
4
+ data.tar.gz: 01d64f70e9addd588db3e28ea05b4ed89c5b1e93
5
5
  SHA512:
6
- metadata.gz: f5ca242ca143cb319d2bbc36f99d4261ecf3ea06092ef91006e89847bc6d618ff4f4ed736fe2915b23f87415f9458c75740edb3deb972da58a7395040a091fd7
7
- data.tar.gz: 9bdfabefd96a457c42b735b5510c77b3c87c9e8a53b4f1c8e86effb677f3f2e0cfb8355e77e8b67ef94dcf0a3ce3bf88e8065e46e70edf5c37abe016a11c0b0a
6
+ metadata.gz: ae1e92edb5053e0a85787d50d1d6c7839cc81026bc7f6d14392d9e91e1c80e9d2eda65526b9d3851bc2cbb18d7b81ed3e982864c294aa172b4974e757253e14c
7
+ data.tar.gz: 6857b48c2b0e3403b46eaea0631f8844fdb456567f550f057728291113b81bc0ffc5219a48680e64cff7ce81f4d278f6b1e8aaae39e7636b85b72d4e74e9d219
data/README.md CHANGED
@@ -90,7 +90,7 @@ describe server(:app) do
90
90
  expect(response.body).to include('Hello Sinatra')
91
91
  end
92
92
  it "responds as 'text/html'" do
93
- expect(response.headers['content-type']).to match(%r{^text/html})
93
+ expect(response.headers['content-type']).to eq("text/html")
94
94
  end
95
95
  end
96
96
  end
data/bin/infrataster ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'infrataster/cli'
4
+
5
+ Infrataster::CLI.start(ARGV)
6
+
data/infrataster.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "capybara"
27
27
  spec.add_runtime_dependency "poltergeist"
28
28
  spec.add_runtime_dependency "faraday"
29
+ spec.add_runtime_dependency "thor"
29
30
 
30
31
  spec.add_development_dependency "bundler", "~> 1.5"
31
32
  spec.add_development_dependency "rake"
@@ -0,0 +1,48 @@
1
+ require 'thor'
2
+ require 'fileutils'
3
+ require 'erb'
4
+
5
+ module Infrataster
6
+ class CLI < Thor
7
+ desc "init", "Initialize Infrataster specs."
8
+ option :path, type: :string, default: '.'
9
+ def init
10
+ path = File.expand_path(options[:path])
11
+ FileUtils.mkdir_p(path)
12
+ create_file_from_template(File.expand_path("Gemfile", path))
13
+ create_file_from_template(File.expand_path("Rakefile", path))
14
+ FileUtils.mkdir(File.expand_path("spec", path))
15
+ if ask_yes_or_no("Use Vagrant?")
16
+ create_file_from_template(File.expand_path("spec/Vagrantfile", path))
17
+ end
18
+ create_file_from_template(File.expand_path("spec/spec_helper.rb", path))
19
+ create_file_from_template(File.expand_path("spec/app_spec.rb", path))
20
+ end
21
+
22
+ private
23
+ def ask_yes_or_no(question)
24
+ print "#{question} (y/N): "
25
+ answer = $stdin.gets
26
+ if answer =~ /^y/i
27
+ true
28
+ else
29
+ false
30
+ end
31
+ end
32
+
33
+ def create_file_from_template(path)
34
+ basename = File.basename(path)
35
+
36
+ if File.exist?(path)
37
+ puts "#{basename} exists already. Skip."
38
+ return
39
+ end
40
+
41
+ open(path, 'w') do |f|
42
+ f.write(ERB.new(File.read(File.expand_path("../fixtures/#{basename}.erb", __FILE__))).result)
43
+ end
44
+
45
+ puts "Created: #{basename}"
46
+ end
47
+ end
48
+ end
@@ -17,7 +17,7 @@ module Infrataster
17
17
  resource.params.each_pair do |k, v|
18
18
  req.params[k] = v
19
19
  end
20
- req.headers['Host'] = resource.uri.host
20
+ req.headers['Host'] = determine_host(address)
21
21
  resource.headers.each_pair do |k, v|
22
22
  req.headers[k] = v
23
23
  end
@@ -25,6 +25,10 @@ module Infrataster
25
25
  end
26
26
  end
27
27
  end
28
+
29
+ def determine_host(default)
30
+ resource.uri.host || (server.options[:http] && server.options[:http][:host]) || default
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -0,0 +1,7 @@
1
+ # Generated by `infrataster init`
2
+ source "https://rubygems.org"
3
+
4
+ gem "infrataster"
5
+
6
+ # If you would like to test mysql, uncomment the next line.
7
+ # gem "infrataster-plugin-mysql"
@@ -0,0 +1,42 @@
1
+ # Generated by `infrataster init`
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ def exec_and_abort_if_fail(cmd)
6
+ system cmd
7
+ unless $?.exitstatus == 0
8
+ $stderr.puts "'#{cmd}' failed."
9
+ abort
10
+ end
11
+ end
12
+
13
+ desc 'Run tests'
14
+ task :spec => ['spec:integration']
15
+
16
+ namespace :spec do
17
+ RSpec::Core::RakeTask.new("infrataster") do |task|
18
+ task.pattern = "./spec/{,/*/**}/*_spec.rb"
19
+ end
20
+
21
+ desc 'Prepare'
22
+ task :prepare do
23
+ exec_and_abort_if_fail '/usr/bin/vagrant up'
24
+ exec_and_abort_if_fail '/usr/bin/vagrant provision'
25
+ end
26
+
27
+ desc 'Provision'
28
+ task :provision do
29
+ exec_and_abort_if_fail '/usr/bin/vagrant provision'
30
+ end
31
+
32
+ desc 'Restart VMs'
33
+ task :restart do
34
+ exec_and_abort_if_fail '/usr/bin/vagrant reload --provision'
35
+ end
36
+
37
+ desc 'Clean'
38
+ task :clean do
39
+ exec_and_abort_if_fail '/usr/bin/vagrant destroy -f'
40
+ end
41
+ end
42
+
@@ -0,0 +1,13 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ #
4
+ # Generated by `infrataster init`
5
+
6
+ VAGRANTFILE_API_VERSION = "2"
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ config.vm.box = "hashicorp/precise64"
9
+
10
+ config.vm.define :app do |c|
11
+ c.vm.network "private_network", ip: "192.168.44.10"
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # Generated by `infrataster init`
2
+ require 'spec_helper'
3
+
4
+ describe server(:app) do
5
+ describe http('http://app') do
6
+ it "responds OK 200" do
7
+ expect(response.status).to eq(200)
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,18 @@
1
+ # Generated by `infrataster init`
2
+ require 'infrataster/rspec'
3
+
4
+ ENV['VAGRANT_CWD'] = File.dirname(__FILE__)
5
+
6
+ Infrataster::Server.define(
7
+ :app,
8
+ '192.168.0.0/16',
9
+ vagrant: true,
10
+ )
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ config.order = 'random'
18
+ end
@@ -11,8 +11,12 @@ module Infrataster
11
11
  def initialize(url_str, options = {})
12
12
  @options = {params: {}, method: :get, headers: {}}.merge(options)
13
13
  @uri = URI.parse(url_str)
14
- unless %w!http https!.include?(@uri.scheme)
15
- raise Error, "The provided url, '#{@uri}', is not http or https."
14
+ if @uri.scheme
15
+ unless %w!http https!.include?(@uri.scheme)
16
+ raise Error, "The provided url, '#{@uri}', is not http or https."
17
+ end
18
+ else
19
+ @uri = URI::HTTP.build([@uri.userinfo, @uri.host, @uri.port, @uri.path, @uri.query, @uri.fragment])
16
20
  end
17
21
  end
18
22
 
@@ -77,9 +77,15 @@ module Infrataster
77
77
  end
78
78
  end
79
79
 
80
+ def ssh(&block)
81
+ Net::SSH.start(*ssh_start_args) do |ssh|
82
+ block.call(ssh)
83
+ end
84
+ end
85
+
80
86
  def ssh_exec(cmd, &block)
81
87
  result = nil
82
- Net::SSH.start(*ssh_start_args) do |ssh|
88
+ ssh do |ssh|
83
89
  result = ssh.exec!(cmd, &block)
84
90
  end
85
91
  result
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -51,6 +51,12 @@ describe server(:app) do
51
51
  expect(body_as_json['headers']['USER']).to eq('VALUE')
52
52
  end
53
53
  end
54
+
55
+ describe http('/path/to/resource') do
56
+ it "sends GET request with scheme and host" do
57
+ expect(body_as_json['headers']['HOST']).to eq('example.com')
58
+ end
59
+ end
54
60
  end
55
61
 
56
62
 
@@ -15,5 +15,11 @@ describe server(:proxy) do
15
15
  result = current_server.ssh_exec("cat /tmp/test-#{time.to_i}")
16
16
  expect(result.chomp).to eq('Hello')
17
17
  end
18
+ it "connects to the current server via SSH" do
19
+ current_server.ssh do |ssh|
20
+ expect(ssh.exec!('echo -n Hello')).to eq('Hello')
21
+ end
22
+ end
23
+
18
24
  end
19
25
 
@@ -10,6 +10,7 @@ Infrataster::Server.define(
10
10
  '172.16.0.0/16',
11
11
  vagrant: true,
12
12
  from: :proxy,
13
+ http: {host: 'example.com'},
13
14
  )
14
15
 
15
16
  RSpec.configure do |config|
@@ -0,0 +1,30 @@
1
+ require 'unit/spec_helper'
2
+
3
+ module Infrataster
4
+ module Contexts
5
+ describe HttpContext do
6
+ context "with relative URI resource" do
7
+ let(:address) { '127.0.0.1' }
8
+ let(:port) { 80 }
9
+ let(:resource) { Resources::HttpResource.new('/path/to/resource') }
10
+ subject { described_class.new(server, resource) }
11
+
12
+ context "with http host definition" do
13
+ let(:server) { Server.new('example.com', address, http: {:host => 'example.com'}) }
14
+
15
+ it "complements host with server definition" do
16
+ expect(subject.determine_host(address)).to eq('example.com')
17
+ end
18
+ end
19
+
20
+ context "with no http host definition" do
21
+ let(:server) { Server.new('example.com', address) }
22
+
23
+ it "complements host with ip address" do
24
+ expect(subject.determine_host(address)).to eq('127.0.0.1')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
1
+ require 'unit/spec_helper'
2
+
3
+ module Infrataster
4
+ module Resources
5
+ describe HttpResource do
6
+ context "with no scheme URI" do
7
+ it "complements scheme" do
8
+ resource = HttpResource.new('/path/to/resource')
9
+ expect(resource.uri.scheme).to eq('http')
10
+ end
11
+ end
12
+ end
13
+ end
14
+ 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.11
4
+ version: 0.1.12
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-29 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: thor
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +153,8 @@ dependencies:
139
153
  description:
140
154
  email:
141
155
  - ryota.arai@gmail.com
142
- executables: []
156
+ executables:
157
+ - infrataster
143
158
  extensions: []
144
159
  extra_rdoc_files: []
145
160
  files:
@@ -150,13 +165,20 @@ files:
150
165
  - LICENSE.txt
151
166
  - README.md
152
167
  - Rakefile
168
+ - bin/infrataster
153
169
  - infrataster.gemspec
154
170
  - lib/infrataster.rb
171
+ - lib/infrataster/cli.rb
155
172
  - lib/infrataster/contexts.rb
156
173
  - lib/infrataster/contexts/base_context.rb
157
174
  - lib/infrataster/contexts/capybara_context.rb
158
175
  - lib/infrataster/contexts/http_context.rb
159
176
  - lib/infrataster/contexts/no_resource_context.rb
177
+ - lib/infrataster/fixtures/Gemfile.erb
178
+ - lib/infrataster/fixtures/Rakefile.erb
179
+ - lib/infrataster/fixtures/Vagrantfile.erb
180
+ - lib/infrataster/fixtures/app_spec.rb.erb
181
+ - lib/infrataster/fixtures/spec_helper.rb.erb
160
182
  - lib/infrataster/helpers.rb
161
183
  - lib/infrataster/helpers/resource_helper.rb
162
184
  - lib/infrataster/helpers/rspec_helper.rb
@@ -185,6 +207,8 @@ files:
185
207
  - spec/integration/vm/cookbooks/proxy/recipes/default.rb
186
208
  - spec/integration/vm/cookbooks/proxy/templates/default/integration-test.erb
187
209
  - spec/integration/vm/vendor/.gitignore
210
+ - spec/unit/lib/infrataster/contexts/http_context_spec.rb
211
+ - spec/unit/lib/infrataster/resources/http_resource_spec.rb
188
212
  - spec/unit/lib/infrataster/server_spec.rb
189
213
  - spec/unit/spec_helper.rb
190
214
  homepage: https://github.com/ryotarai/infrataster
@@ -229,5 +253,7 @@ test_files:
229
253
  - spec/integration/vm/cookbooks/proxy/recipes/default.rb
230
254
  - spec/integration/vm/cookbooks/proxy/templates/default/integration-test.erb
231
255
  - spec/integration/vm/vendor/.gitignore
256
+ - spec/unit/lib/infrataster/contexts/http_context_spec.rb
257
+ - spec/unit/lib/infrataster/resources/http_resource_spec.rb
232
258
  - spec/unit/lib/infrataster/server_spec.rb
233
259
  - spec/unit/spec_helper.rb