lbspec 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  require 'rake'
5
+ require 'highline/import'
5
6
 
6
7
  task :default => :travis
7
8
  task :travis => [:spec, :rubocop, 'coveralls:push']
@@ -19,3 +20,24 @@ end
19
20
  Rubocop::RakeTask.new(:rubocop) do |task|
20
21
  task.patterns = %w(lib/**/*.rb spec/**/*.rb)
21
22
  end
23
+
24
+ task :release do |t|
25
+ puts "Releaseing gem"
26
+ require_relative 'lib/lbspec'
27
+ version_current = Lbspec::VERSION
28
+ puts "now v#{version_current}"
29
+ version_new = ask("Input version")
30
+
31
+ file_path = 'lib/lbspec/version.rb'
32
+ text = File.read(file_path)
33
+ text = text.gsub(/#{version_current}/, version_new)
34
+ File.open(file_path, "w") {|file| file.puts text}
35
+
36
+ sh('gem build lbspec.gemspec')
37
+ if agree("Shall we continue? ( yes or no )")
38
+ puts "Pushing gem..."
39
+ sh("gem push lbspec-#{version_new}.gem")
40
+ else
41
+ puts "Exiting"
42
+ end
43
+ end
data/lbspec.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rubocop"
25
25
  spec.add_development_dependency "coveralls"
26
26
  spec.add_development_dependency "debugger"
27
+ spec.add_development_dependency "highline"
27
28
 
28
29
  spec.add_runtime_dependency "rspec"
29
30
  spec.add_runtime_dependency "net-ssh"
@@ -7,6 +7,9 @@ RSpec::Matchers.define :transfer do |nodes|
7
7
  @ssh = []
8
8
  @threads = []
9
9
  @nodes_connected = []
10
+ @protocol = nil
11
+ @application = nil
12
+ @http_path = '/'
10
13
  @vhost_port = 80
11
14
  @node_port = 0
12
15
  @result = false
@@ -25,6 +28,28 @@ RSpec::Matchers.define :transfer do |nodes|
25
28
  @node_port = port
26
29
  end
27
30
 
31
+ chain :tcp do
32
+ @protocol = :tcp
33
+ end
34
+
35
+ chain :udp do
36
+ @protocol = :udp
37
+ end
38
+
39
+ chain :http do
40
+ @protocol = :tcp
41
+ @application = :http
42
+ end
43
+
44
+ chain :https do
45
+ @protocol = :tcp
46
+ @application = :https
47
+ end
48
+
49
+ chain :path do |path|
50
+ @http_path = path
51
+ end
52
+
28
53
  def gen_keyword
29
54
  Lbspec::Util.gen_keyword
30
55
  end
@@ -63,17 +88,15 @@ RSpec::Matchers.define :transfer do |nodes|
63
88
  channel.exec capture_cmd do |ch, stream, data|
64
89
  num_match = 0
65
90
  ch.on_data do |c, d|
66
- # because of ngrep output condition first
67
- # to avoid incorrect match, count 2
68
91
  num_match += 1 if /#{@keyword}/ =~ d
69
- @result = true if num_match > 1
92
+ @result = true if num_match > 0
70
93
  end
71
94
  end
72
95
  end
73
96
 
74
97
  def capture_cmd
75
98
  port_str = @node_port > 0 ? "port #{@node_port}" : ''
76
- "sudo ngrep #{@keyword} #{port_str}"
99
+ "sudo ngrep #{@keyword} #{port_str} | grep -v \"match:\""
77
100
  end
78
101
 
79
102
  def disconnect_nodes
@@ -90,7 +113,31 @@ RSpec::Matchers.define :transfer do |nodes|
90
113
  addr_port = Lbspec::Util.split_addr_port(vhost.to_s)
91
114
  vhost_addr, vhost_port = addr_port[:addr], addr_port[:port]
92
115
  @vhost_port = vhost_port if vhost_port > 0
93
- system("echo #{@keyword} | nc #{vhost_addr} #{@vhost_port}")
116
+ if @application
117
+ send_request_application(vhost_addr, @vhost_port)
118
+ else
119
+ send_request_transport(vhost_addr, @vhost_port)
120
+ end
121
+ end
122
+
123
+ def send_request_application(addr, port)
124
+ case @application
125
+ when :http
126
+ query = "?#{@keyword}"
127
+ system("curl -sm 1 http://#{addr}:#{port}#{@http_path}#{query}")
128
+ when :https
129
+ query = "?#{@keyword}"
130
+ system("curl -sm 1 -k https://#{addr}:#{port}#{@http_path}#{query}")
131
+ end
132
+ end
133
+
134
+ def send_request_transport(addr, port)
135
+ case @protocol
136
+ when :udp
137
+ system("echo #{@keyword} | nc -u #{addr} #{port}")
138
+ else
139
+ system("echo #{@keyword} | nc #{addr} #{port}")
140
+ end
94
141
  end
95
142
 
96
143
  description do
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Lbspec is an RSpec plugin for easy Loadbalancer testing.
3
3
  module Lbspec
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -31,5 +31,23 @@ describe Lbspec do
31
31
  it 'should test transfer vhost:80 and a node on port 80' do
32
32
  'vhost_a:80'.should transfer('node_a').port(80)
33
33
  end
34
+ it 'should test transfer vhost:80 and a node on port 80/tcp' do
35
+ 'vhost_a:80'.should transfer('node_a').port(80).tcp
36
+ end
37
+ it 'should test transfer vhost:80 and a node on port 53/tcp' do
38
+ 'vhost_a:80'.should transfer('node_a').port(53).udp
39
+ end
40
+ it 'should test transfer vhost:80 and a node with http' do
41
+ 'vhost_a:80'.should transfer('node_a').http
42
+ end
43
+ it 'should test transfer vhost:443 and a node with https' do
44
+ 'vhost_a:443'.should transfer('node_a').port(80).https
45
+ end
46
+ it 'should test transfer vhost:443 and a node:80 with https' do
47
+ 'vhost_a:443'.should transfer('node_a').port(80).https
48
+ end
49
+ it 'should test transfer vhost:443 and a node with https /test' do
50
+ 'vhost_a:443'.should transfer('node_a').https.path('/test')
51
+ end
34
52
  end
35
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lbspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: highline
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: rspec
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -180,12 +196,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
196
  - - ! '>='
181
197
  - !ruby/object:Gem::Version
182
198
  version: '0'
199
+ segments:
200
+ - 0
201
+ hash: -4545456457714803124
183
202
  required_rubygems_version: !ruby/object:Gem::Requirement
184
203
  none: false
185
204
  requirements:
186
205
  - - ! '>='
187
206
  - !ruby/object:Gem::Version
188
207
  version: '0'
208
+ segments:
209
+ - 0
210
+ hash: -4545456457714803124
189
211
  requirements: []
190
212
  rubyforge_project:
191
213
  rubygems_version: 1.8.21