anywhere 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/anywhere.gemspec +27 -0
- data/bin/anywhere +41 -0
- data/lib/anywhere.rb +10 -0
- data/lib/anywhere/base.rb +124 -0
- data/lib/anywhere/execution_error.rb +9 -0
- data/lib/anywhere/local.rb +39 -0
- data/lib/anywhere/logger.rb +51 -0
- data/lib/anywhere/result.rb +60 -0
- data/lib/anywhere/ssh.rb +57 -0
- data/lib/anywhere/system_package.rb +21 -0
- data/lib/anywhere/version.rb +3 -0
- data/spec/fixtures/arch.tgz +0 -0
- data/spec/fixtures/packages.txt +387 -0
- data/spec/integration/local_integration_spec.rb +39 -0
- data/spec/integration/ssh_integration_spec.rb +126 -0
- data/spec/lib/anywhere/base_spec.rb +25 -0
- data/spec/lib/anywhere/local_spec.rb +43 -0
- data/spec/lib/anywhere/logger_spec.rb +16 -0
- data/spec/lib/anywhere/ssh_spec.rb +11 -0
- data/spec/lib/anywhere/system_package_spec.rb +29 -0
- data/spec/lib/anywhere_spec.rb +8 -0
- data/spec/spec_helper.rb +11 -0
- metadata +181 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/local"
|
3
|
+
|
4
|
+
describe "SSH integration spec" do
|
5
|
+
class NullLogger
|
6
|
+
[:info, :debug, :error].each do |name|
|
7
|
+
define_method(name) do |*args|
|
8
|
+
captured[name] ||= []
|
9
|
+
captured[name] << args
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def captured
|
14
|
+
@captured ||= {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before :all do
|
19
|
+
@runner = Anywhere::Local.new
|
20
|
+
@runner.logger = NullLogger.new
|
21
|
+
@path = "/tmp/test.txt"
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:runner) { @runner }
|
25
|
+
|
26
|
+
describe "#whoami" do
|
27
|
+
it { runner.whoami.should be_kind_of(String) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "porviding data through stdin" do
|
31
|
+
subject(:result) do
|
32
|
+
runner.execute("cat - > /tmp/test.txt", "hello world")
|
33
|
+
runner.execute("cat /tmp/test.txt").stdout
|
34
|
+
end
|
35
|
+
|
36
|
+
it { should be_kind_of(String) }
|
37
|
+
it { subject.should eq("hello world") }
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/ssh"
|
3
|
+
|
4
|
+
describe "SSH integration spec" do
|
5
|
+
class NullLogger
|
6
|
+
[:info, :debug, :error].each do |name|
|
7
|
+
define_method(name) do |*args|
|
8
|
+
captured[name] ||= []
|
9
|
+
captured[name] << args
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def captured
|
14
|
+
@captured ||= {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before :all do
|
19
|
+
@user = "vagrant"
|
20
|
+
host = "192.168.34.12"
|
21
|
+
port = 22
|
22
|
+
|
23
|
+
@runner = Anywhere::SSH.new(host, @user, port: port)
|
24
|
+
@runner.logger = NullLogger.new
|
25
|
+
@path = "/tmp/test.txt"
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:runner) { @runner }
|
29
|
+
|
30
|
+
describe "#whoami" do
|
31
|
+
it { runner.whoami.should eq(@user) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#home_dir" do
|
35
|
+
it { runner.home_dir.should eq("/home/vagrant") }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#extract_tar" do
|
39
|
+
let(:path) { FIXTURES_PATH.join("arch.tgz") }
|
40
|
+
|
41
|
+
it "extracts the provided path" do
|
42
|
+
runner.extract_tar(path, "/tmp/urknall/tar")
|
43
|
+
runner.execute("ls /tmp/urknall/tar").stdout.split("\n").should eq(["a.txt", "b.txt"])
|
44
|
+
runner.execute("cat /tmp/urknall/tar/a.txt").stdout.should eq("this is a\n")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#mkdir_p" do
|
49
|
+
before :each do
|
50
|
+
@runner.execute("rm -Rf /tmp/urknall")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create a new directory" do
|
54
|
+
@runner.mkdir_p("mkdir -p /tmp/urknall/test")
|
55
|
+
@runner.execute("file /tmp/urknall/test").stdout.should include("/tmp/urknall/test: directory")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#execute" do
|
60
|
+
subject { runner.execute("uptime") }
|
61
|
+
it { should be_kind_of(Anywhere::Result) }
|
62
|
+
it { subject.stdout.should be_kind_of(String) }
|
63
|
+
it { subject.stdout.should include("load average") }
|
64
|
+
it { subject.stderr.length.should eq(0) }
|
65
|
+
|
66
|
+
describe "with unknwon command" do
|
67
|
+
subject(:error) do
|
68
|
+
begin
|
69
|
+
runner.execute("rgne")
|
70
|
+
rescue => err
|
71
|
+
err
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it { should be_kind_of(Anywhere::ExecutionError) }
|
76
|
+
|
77
|
+
describe "#result" do
|
78
|
+
subject(:result) { error.result }
|
79
|
+
|
80
|
+
it { should_not be_success }
|
81
|
+
it { subject.stdout.should eq("") }
|
82
|
+
it { subject.stderr.should include("command not found") }
|
83
|
+
it { subject.exit_status.should eq(127) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "execute" do
|
89
|
+
subject { runner.execute("uptime") }
|
90
|
+
it { should be_kind_of(Anywhere::Result) }
|
91
|
+
it { subject.stdout.should be_kind_of(String) }
|
92
|
+
it { subject.stdout.should include("load average") }
|
93
|
+
it { subject.stderr.length.should eq(0) }
|
94
|
+
|
95
|
+
describe "with command not successful" do
|
96
|
+
it { expect { runner.execute("rgne") }.to raise_error(Anywhere::ExecutionError) }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "write_file" do
|
101
|
+
before :all do
|
102
|
+
@runner.execute("rm -f #{@path}")
|
103
|
+
end
|
104
|
+
|
105
|
+
subject { runner.write_file(@path, "hello world") }
|
106
|
+
it { should be_success }
|
107
|
+
it { runner.execute("cat #{@path}").stdout.should eq("hello world") }
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "write big files" do
|
111
|
+
before :all do
|
112
|
+
@runner.execute("rm -f #{@path}")
|
113
|
+
@content = "X" * 2 * 1024 ** 2
|
114
|
+
@response = @runner.write_file(@path, @content)
|
115
|
+
end
|
116
|
+
|
117
|
+
subject { @response }
|
118
|
+
|
119
|
+
it { @runner.md5sum(@path).should eq("97cdcd9fbaacc9ea373d676e6abce318") }
|
120
|
+
|
121
|
+
it { should be_success }
|
122
|
+
it { runner.execute("wc #{@path}").stdout.should be_kind_of(String) }
|
123
|
+
it { runner.execute("wc #{@path}").stdout.strip.split(/\s+/).at(2).to_i.should eq(2 * 1024 ** 2) }
|
124
|
+
it { runner.execute("cat #{@path}").stdout.should start_with("XXX") }
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Anywhere::Base" do
|
4
|
+
subject(:base) { Anywhere::Base.new }
|
5
|
+
it { should_not be_nil }
|
6
|
+
|
7
|
+
describe "root?" do
|
8
|
+
subject do
|
9
|
+
base.stub(:execute) { double("output", stdout: "root") }
|
10
|
+
base.root?
|
11
|
+
end
|
12
|
+
|
13
|
+
it { should be_true }
|
14
|
+
|
15
|
+
describe "not being root" do
|
16
|
+
subject do
|
17
|
+
base.stub(:execute) { double("output", stdout: "user") }
|
18
|
+
base.root?
|
19
|
+
end
|
20
|
+
|
21
|
+
it { should_not be_true }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/local"
|
3
|
+
|
4
|
+
describe "Anywhere::Local" do
|
5
|
+
before do
|
6
|
+
Anywhere.stub(:logger) { double("logger", error: true, info: true) }
|
7
|
+
end
|
8
|
+
|
9
|
+
subject(:local) { Anywhere::Local.new }
|
10
|
+
it { should_not be_nil }
|
11
|
+
|
12
|
+
describe "whoami" do
|
13
|
+
it { subject.whoami.should be_kind_of(String) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#execute" do
|
17
|
+
subject(:result) { local.execute("ls -la") }
|
18
|
+
|
19
|
+
it { should_not be_nil }
|
20
|
+
it { should be_kind_of(Anywhere::Result) }
|
21
|
+
it { subject.exit_status.should eq(0) }
|
22
|
+
it { subject.stdout.should be_kind_of(String) }
|
23
|
+
|
24
|
+
describe "with command raising an error" do
|
25
|
+
subject(:error) do
|
26
|
+
caught_err = nil
|
27
|
+
begin
|
28
|
+
local.execute("echo 1; echo 2 > /dev/stderr; exit 1")
|
29
|
+
rescue => err
|
30
|
+
caught_err = err
|
31
|
+
end
|
32
|
+
caught_err
|
33
|
+
end
|
34
|
+
|
35
|
+
it { should_not be_nil }
|
36
|
+
it { should be_kind_of(Anywhere::ExecutionError) }
|
37
|
+
it { subject.result.should be_kind_of(Anywhere::Result) }
|
38
|
+
|
39
|
+
it { subject.result.stdout.should eq("1") }
|
40
|
+
it { subject.result.stderr.should eq("2") }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/logger"
|
3
|
+
|
4
|
+
describe "Anywhere::Logger" do
|
5
|
+
subject(:logger) { Anywhere::Logger.new }
|
6
|
+
it { should_not be_nil }
|
7
|
+
it { subject.prefix.should be_nil }
|
8
|
+
|
9
|
+
describe "setting the prefix" do
|
10
|
+
it "changes the prefix" do
|
11
|
+
subject.prefix = "test"
|
12
|
+
subject.prefix.should eq("test")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/ssh"
|
3
|
+
|
4
|
+
describe "Anywhere::SSH" do
|
5
|
+
subject(:ssh) { Anywhere::SSH.new("test.host", "root") }
|
6
|
+
it { should_not be_nil }
|
7
|
+
|
8
|
+
it { subject.host.should eq("test.host") }
|
9
|
+
it { subject.user.should eq("root") }
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "anywhere/system_package"
|
3
|
+
|
4
|
+
describe "Anywhere::SystemPackage" do
|
5
|
+
subject(:package) do
|
6
|
+
Anywhere::SystemPackage.new("zlib1g-dev", "1:1.2.3.4.dfsg-3ubuntu4")
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should_not be_nil }
|
10
|
+
|
11
|
+
it { subject.name.should eq("zlib1g-dev") }
|
12
|
+
it { subject.version.should eq("1:1.2.3.4.dfsg-3ubuntu4") }
|
13
|
+
|
14
|
+
describe "#from_list" do
|
15
|
+
subject(:packages) do
|
16
|
+
Anywhere::SystemPackage.from_list(FIXTURES_PATH.join("packages.txt").read)
|
17
|
+
end
|
18
|
+
|
19
|
+
it { should be_kind_of(Array) }
|
20
|
+
it { subject.count.should eq(387) }
|
21
|
+
|
22
|
+
describe "#first" do
|
23
|
+
subject(:first) { packages.first }
|
24
|
+
it { subject.name.should eq("acpid") }
|
25
|
+
it { subject.version.should eq("1:2.0.10-1ubuntu3") }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# tags: rspec default settings wip config
|
3
|
+
|
4
|
+
RSpec.configure do |c|
|
5
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
c.filter_run :focus => true
|
7
|
+
c.run_all_when_everything_filtered = true
|
8
|
+
end
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
FIXTURES_PATH = Pathname.new(File.expand_path("../fixtures", __FILE__))
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anywhere
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tobias Schwab
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ssh
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: colorize
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.3'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Simple wrapper for Net/SSH
|
111
|
+
email:
|
112
|
+
- tobias.schwab@dynport.de
|
113
|
+
executables:
|
114
|
+
- anywhere
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- anywhere.gemspec
|
124
|
+
- bin/anywhere
|
125
|
+
- lib/anywhere.rb
|
126
|
+
- lib/anywhere/base.rb
|
127
|
+
- lib/anywhere/execution_error.rb
|
128
|
+
- lib/anywhere/local.rb
|
129
|
+
- lib/anywhere/logger.rb
|
130
|
+
- lib/anywhere/result.rb
|
131
|
+
- lib/anywhere/ssh.rb
|
132
|
+
- lib/anywhere/system_package.rb
|
133
|
+
- lib/anywhere/version.rb
|
134
|
+
- spec/fixtures/arch.tgz
|
135
|
+
- spec/fixtures/packages.txt
|
136
|
+
- spec/integration/local_integration_spec.rb
|
137
|
+
- spec/integration/ssh_integration_spec.rb
|
138
|
+
- spec/lib/anywhere/base_spec.rb
|
139
|
+
- spec/lib/anywhere/local_spec.rb
|
140
|
+
- spec/lib/anywhere/logger_spec.rb
|
141
|
+
- spec/lib/anywhere/ssh_spec.rb
|
142
|
+
- spec/lib/anywhere/system_package_spec.rb
|
143
|
+
- spec/lib/anywhere_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: ''
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ! '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.8.23
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Simple wrapper for Net/SSH
|
170
|
+
test_files:
|
171
|
+
- spec/fixtures/arch.tgz
|
172
|
+
- spec/fixtures/packages.txt
|
173
|
+
- spec/integration/local_integration_spec.rb
|
174
|
+
- spec/integration/ssh_integration_spec.rb
|
175
|
+
- spec/lib/anywhere/base_spec.rb
|
176
|
+
- spec/lib/anywhere/local_spec.rb
|
177
|
+
- spec/lib/anywhere/logger_spec.rb
|
178
|
+
- spec/lib/anywhere/ssh_spec.rb
|
179
|
+
- spec/lib/anywhere/system_package_spec.rb
|
180
|
+
- spec/lib/anywhere_spec.rb
|
181
|
+
- spec/spec_helper.rb
|