infrataster 0.1.5 → 0.1.6

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: b50f39082b28b0195fa82e039f6408776186cc96
4
- data.tar.gz: 6d8297343a434ce01ef1e3fe5551ede852584365
3
+ metadata.gz: 5dc2f4bfbb95e831073eda6fed2e8e08032f351d
4
+ data.tar.gz: 47157b14bc98ee9311b1c96075e7ffc14eaccea5
5
5
  SHA512:
6
- metadata.gz: f7a6962125a06db963a54f2057f94be3b2389a748e463e4a9be62c69e6cf0557b819d5161b8719cc48d7a46258de29794b854183dab17d010fd46a6cf03d6892
7
- data.tar.gz: 17b4b4cf5b7b858e7d548bcaa12a83a32ceb8826e26150651519f686348ba084a3ba2c24841edfee3cea6ebb178b0ad31b73270f26ee8bd81bd8074e8ec712bc
6
+ metadata.gz: 722dcfd3788573323d4e6d78cbc074ace5312ee24eb7738788482ce91d626089e1b352852ff75928a275bd19b74ca4544c50c7c89aa8c01da181c89da1f7f6b5
7
+ data.tar.gz: 37cf98854f85b6513a554f0494a98bb97a1cc4757e90ec7e2492368507faf5693f3b30501bd9f8566918a32b2bf2c2a3db81f3097dee25556796de5c057f8105
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.1.6
4
+
5
+ * Implement `Server#ssh\_exec` which executes a command on the server via SSH.
6
+
3
7
  ## v0.1.5
4
8
 
5
9
  * Extract mysql resource to [infrataster-plugin-mysql](https://github.com/ryotarai/infrataster-plugin-mysql).
data/README.md CHANGED
@@ -28,7 +28,7 @@ Create Vagrantfile:
28
28
 
29
29
  ```ruby
30
30
  # Vagrantfile
31
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
31
+ Vagrant.configure("2") do |config|
32
32
  config.vm.box = "hashicorp/precise64"
33
33
 
34
34
  config.vm.define :proxy do |c|
@@ -147,6 +147,25 @@ Infrataster::Server.define(
147
147
  )
148
148
  ```
149
149
 
150
+ ### #ssh_exec
151
+
152
+ You can execute a command on the server like the following:
153
+
154
+ ```ruby
155
+ describe server(:proxy) do
156
+ let(:time) { Time.now }
157
+ before do
158
+ current_server.ssh_exec "echo 'Hello' > /tmp/test-#{time.to_i}"
159
+ end
160
+ it "executes a command on the current server" do
161
+ result = current_server.ssh_exec("cat /tmp/test-#{time.to_i}")
162
+ expect(result.chomp).to eq('Hello')
163
+ end
164
+ end
165
+ ```
166
+
167
+ This is useful to test cases which depends on the status of the server.
168
+
150
169
  ## Resources
151
170
 
152
171
  "Resource" is what you test by Infrataster. For instance, the following code describes `http` resource.
@@ -1,5 +1,6 @@
1
1
  require 'infrataster/resources'
2
2
  require 'infrataster/contexts/base_context'
3
+ require 'infrataster/contexts/no_resource_context'
3
4
  require 'infrataster/contexts/http_context'
4
5
  require 'infrataster/contexts/capybara_context'
5
6
 
@@ -12,7 +13,15 @@ module Infrataster
12
13
  server_resource = find_described(Resources::ServerResource, example_group)
13
14
  resource = find_described(Resources::BaseResource, example_group)
14
15
 
15
- return if [server_resource, resource].any? &:nil?
16
+ unless server_resource || resource
17
+ # There is neither server_resource or resource
18
+ return nil
19
+ end
20
+
21
+ if server_resource && !resource
22
+ # Server is found but resource is not found
23
+ return Contexts::NoResourceContext.new(server_resource.server)
24
+ end
16
25
 
17
26
  resource.context_class.new(server_resource.server, resource)
18
27
  end
@@ -8,6 +8,10 @@ module Infrataster
8
8
  @server = server
9
9
  @resource = resource
10
10
  end
11
+
12
+ def current_server
13
+ @server
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,11 @@
1
+ module Infrataster
2
+ module Contexts
3
+ class NoResourceContext < BaseContext
4
+ def initialize(server)
5
+ super(server, nil)
6
+ end
7
+ end
8
+ end
9
+ end
10
+
11
+
@@ -105,6 +105,14 @@ module Infrataster
105
105
  end
106
106
  end
107
107
 
108
+ def ssh_exec(cmd, &block)
109
+ result = nil
110
+ Net::SSH.start(*ssh_start_args) do |ssh|
111
+ result = ssh.exec!(cmd, &block)
112
+ end
113
+ result
114
+ end
115
+
108
116
  def ssh_start_args
109
117
  @ssh_start_args ||= _ssh_start_args
110
118
  end
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -6,3 +6,14 @@ describe 'Normal subject not related to Infrataster' do
6
6
  end
7
7
  end
8
8
 
9
+ describe server(:proxy) do
10
+ let(:time) { Time.now }
11
+ before do
12
+ current_server.ssh_exec "echo 'Hello' > /tmp/test-#{time.to_i}"
13
+ end
14
+ it "executes a command on the current server" do
15
+ result = current_server.ssh_exec("cat /tmp/test-#{time.to_i}")
16
+ expect(result.chomp).to eq('Hello')
17
+ end
18
+ end
19
+
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.5
4
+ version: 0.1.6
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-06 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -172,6 +172,7 @@ files:
172
172
  - lib/infrataster/contexts/base_context.rb
173
173
  - lib/infrataster/contexts/capybara_context.rb
174
174
  - lib/infrataster/contexts/http_context.rb
175
+ - lib/infrataster/contexts/no_resource_context.rb
175
176
  - lib/infrataster/helpers.rb
176
177
  - lib/infrataster/helpers/resource_helper.rb
177
178
  - lib/infrataster/helpers/rspec_helper.rb