ikran 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/bin/ikran +4 -0
- data/ikran.gemspec +65 -0
- data/lib/ikran.rb +4 -0
- data/lib/ikran/reader.rb +99 -0
- data/spec/ikran_spec.rb +93 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 darthdeus
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= ikran
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 darthdeus. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ikran"
|
8
|
+
gem.summary = %Q{Simple HTTP console testing framework}
|
9
|
+
gem.description = %Q{Simple console application for testing HTTP server}
|
10
|
+
gem.email = "darthdeus@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/darthdeus/ikran"
|
12
|
+
gem.authors = ["darthdeus"]
|
13
|
+
gem.add_dependency "addressable", ">= 2.1.1"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "cucumber", ">= 0.6.2"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
require 'rake/rdoctask'
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "ikran #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ikran
ADDED
data/ikran.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ikran}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["darthdeus"]
|
12
|
+
s.date = %q{2010-01-30}
|
13
|
+
s.default_executable = %q{ikran}
|
14
|
+
s.description = %q{Simple console application for testing HTTP server}
|
15
|
+
s.email = %q{darthdeus@gmail.com}
|
16
|
+
s.executables = ["ikran"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/ikran",
|
29
|
+
"ikran.gemspec",
|
30
|
+
"lib/ikran.rb",
|
31
|
+
"lib/ikran/reader.rb",
|
32
|
+
"spec/ikran_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/darthdeus/ikran}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Simple HTTP console testing framework}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/ikran_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<addressable>, [">= 2.1.1"])
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<addressable>, [">= 2.1.1"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
62
|
+
s.add_dependency(%q<cucumber>, [">= 0.6.2"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/ikran.rb
ADDED
data/lib/ikran/reader.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'addressable/uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Ikran
|
7
|
+
class Reader
|
8
|
+
attr_accessor :verbose
|
9
|
+
|
10
|
+
COMMANDS = ["exit", "server", "ping", "head", "verbose"]
|
11
|
+
STATUS_REGEXP = /#<Net::HTTP[a-zA-Z]+ (.+) readbody=(?:true|false)>/
|
12
|
+
|
13
|
+
def parse(command)
|
14
|
+
cmd = command.split(' ')
|
15
|
+
if COMMANDS.include? cmd.first
|
16
|
+
cmd.length > 1 ? ("#{cmd[0]} '#{cmd[1]}'") : cmd.first
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def exit
|
21
|
+
@running = false
|
22
|
+
"exiting ..."
|
23
|
+
end
|
24
|
+
|
25
|
+
def server(val = nil)
|
26
|
+
if val
|
27
|
+
begin
|
28
|
+
@server = Addressable::URI.heuristic_parse(val).to_s
|
29
|
+
"remote set to #{@server}"
|
30
|
+
rescue Addressable::URI::InvalidURIError => e
|
31
|
+
"invalid url"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@server ? "current remote is #{@server}" : "remote is not set"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def ping
|
39
|
+
if not @server
|
40
|
+
"remote must be set before executing ping without parameters"
|
41
|
+
elsif http_ping(@server)
|
42
|
+
"#{@server} is alive"
|
43
|
+
else
|
44
|
+
"#{@server} is unreachable"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def http_ping(url)
|
49
|
+
get_url(url).to_i < 400
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_url(url)
|
53
|
+
Net::HTTP.get_response(URI.parse(url)).inspect =~ STATUS_REGEXP
|
54
|
+
end
|
55
|
+
|
56
|
+
def head
|
57
|
+
return "remote must be set before executing head" unless @server
|
58
|
+
res = Net::HTTP.get_response(URI.parse(@server))
|
59
|
+
if res.inspect =~ STATUS_REGEXP
|
60
|
+
@verbose ? res.body : $1
|
61
|
+
else
|
62
|
+
"invalid response #{res.inspect}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def verbose
|
67
|
+
"verbose is now " + (@verbose = !@verbose ? "ON" : "OFF")
|
68
|
+
end
|
69
|
+
|
70
|
+
def exec(command)
|
71
|
+
cmd = parse(command)
|
72
|
+
if cmd
|
73
|
+
instance_eval(cmd)
|
74
|
+
else
|
75
|
+
"command #{command} doesn't exist"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
@running = true
|
81
|
+
while @running
|
82
|
+
print ">> "
|
83
|
+
line = gets.chomp!
|
84
|
+
puts exec(line)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.aliases(opts)
|
89
|
+
opts.each do |original, aliased|
|
90
|
+
[*aliased].each do |a|
|
91
|
+
alias_method a, original
|
92
|
+
COMMANDS << a.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
aliases :server => [:s, :r, :remote], :head => :h, :ping => :p, :verbose => :v, :exit => :e
|
98
|
+
end
|
99
|
+
end
|
data/spec/ikran_spec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ikran" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@reader = Ikran::Reader.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should stop expecting input after 'exit' command'" do
|
10
|
+
@reader.exec('exit').should == 'exiting ...'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow me to set remote server via 'server' command" do
|
14
|
+
server = 'example.com'
|
15
|
+
@reader.exec("server #{server}").should == "remote set to http://example.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return error if server is not set and 'server' command is invoked without any parameters" do
|
19
|
+
@reader.exec("server").should == "remote is not set"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return current remote server on 'server' command without any parameters" do
|
23
|
+
server = 'example.com'
|
24
|
+
@reader.exec("server #{server}")
|
25
|
+
@reader.exec("server").should == "current remote is http://example.com"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should accept only valid url for server command" do
|
29
|
+
# port can't be string
|
30
|
+
@reader.exec("server http://example.com:foo").should == "invalid url"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should show error on non-existing command" do
|
34
|
+
@reader.exec("foo").should == "command foo doesn't exist"
|
35
|
+
end
|
36
|
+
|
37
|
+
context "ping command" do
|
38
|
+
it "should require remote to be set if executing ping without parameters" do
|
39
|
+
@reader.exec("ping").should == "remote must be set before executing ping without parameters"
|
40
|
+
end
|
41
|
+
|
42
|
+
context "testing availability" do
|
43
|
+
it "should return 'server is alive' if server is available" do
|
44
|
+
@reader.stub!(:http_ping).and_return(true)
|
45
|
+
@reader.exec("server example.com")
|
46
|
+
@reader.exec("ping").should == "http://example.com is alive"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return 'server is unreachable' if server is unreachable" do
|
50
|
+
@reader.stub!(:http_ping).and_return(false)
|
51
|
+
@reader.exec("server example.com")
|
52
|
+
@reader.exec("ping").should == "http://example.com is unreachable"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should toggle verbose on 'verbose' command" do
|
58
|
+
@reader.exec("verbose").should == "verbose is now ON"
|
59
|
+
@reader.exec("verbose").should == "verbose is now OFF"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should require remote to be set before executing 'head' command" do
|
63
|
+
@reader.exec("head").should == "remote must be set before executing head"
|
64
|
+
end
|
65
|
+
|
66
|
+
context "non verbose mod" do
|
67
|
+
it "should send a request to given url on 'head' command" do
|
68
|
+
@reader = Ikran::Reader.new
|
69
|
+
@reader.exec("server example.com")
|
70
|
+
@reader.exec("head").should == "200 OK"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "parsing" do
|
75
|
+
it "should return entire command if no parameters are passed" do
|
76
|
+
@reader.parse("server").should == "server"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return entire command if only one parameter is passed with quoted parameter" do
|
80
|
+
@reader.parse("server first").should == "server 'first'"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should parse and return only first two words in command with quoted parameter" do
|
84
|
+
@reader.parse("server first second").should == "server 'first'"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return nil if command is invalid" do
|
88
|
+
@reader.parse("foo").should == nil
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ikran
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- darthdeus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-30 00:00:00 +01:00
|
13
|
+
default_executable: ikran
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: addressable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.9
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.6.2
|
44
|
+
version:
|
45
|
+
description: Simple console application for testing HTTP server
|
46
|
+
email: darthdeus@gmail.com
|
47
|
+
executables:
|
48
|
+
- ikran
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- bin/ikran
|
62
|
+
- ikran.gemspec
|
63
|
+
- lib/ikran.rb
|
64
|
+
- lib/ikran/reader.rb
|
65
|
+
- spec/ikran_spec.rb
|
66
|
+
- spec/spec.opts
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/darthdeus/ikran
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Simple HTTP console testing framework
|
96
|
+
test_files:
|
97
|
+
- spec/ikran_spec.rb
|
98
|
+
- spec/spec_helper.rb
|