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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +20 -1
- data/lib/infrataster/contexts.rb +10 -1
- data/lib/infrataster/contexts/base_context.rb +4 -0
- data/lib/infrataster/contexts/no_resource_context.rb +11 -0
- data/lib/infrataster/server.rb +8 -0
- data/lib/infrataster/version.rb +1 -1
- data/spec/integration/other_spec.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dc2f4bfbb95e831073eda6fed2e8e08032f351d
|
4
|
+
data.tar.gz: 47157b14bc98ee9311b1c96075e7ffc14eaccea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722dcfd3788573323d4e6d78cbc074ace5312ee24eb7738788482ce91d626089e1b352852ff75928a275bd19b74ca4544c50c7c89aa8c01da181c89da1f7f6b5
|
7
|
+
data.tar.gz: 37cf98854f85b6513a554f0494a98bb97a1cc4757e90ec7e2492368507faf5693f3b30501bd9f8566918a32b2bf2c2a3db81f3097dee25556796de5c057f8105
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,7 +28,7 @@ Create Vagrantfile:
|
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
# Vagrantfile
|
31
|
-
Vagrant.configure(
|
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.
|
data/lib/infrataster/contexts.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/infrataster/server.rb
CHANGED
@@ -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
|
data/lib/infrataster/version.rb
CHANGED
@@ -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.
|
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-
|
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
|