dock_test 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +8 -0
- data/Guardfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/config.ru +16 -0
- data/dock_test.gemspec +24 -0
- data/lib/dock_test/assertions.rb +5 -0
- data/lib/dock_test/methods.rb +57 -0
- data/lib/dock_test/version.rb +3 -0
- data/lib/dock_test.rb +37 -0
- data/test/dock_test/test_localhost_methods.rb +77 -0
- data/test/test_helper.rb +5 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 91c8ee1954a3b1a2ee91aa2594ab86a7f8389bc5
|
4
|
+
data.tar.gz: 8ebb6e2c2c09d90ea333cfbfc82d1d3a99df425f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 025f3822488847eefbac951c4e169160a7d510cafa1f4b5e92fcdbbf1f175c75d28b646df55771d0ca4df1a3dd883ef5fc0f5cd195a42832ccdb5e66fd0e694e
|
7
|
+
data.tar.gz: e34bfbd614e855da9e6a75d5252abbed4844ca546a10b618310f89276a29543326721a56f343a0c6d564533cc5efbf1bb903e8b1ad6ec7ce638c54897988c164
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# This eliminates the stty warning.
|
5
|
+
interactor :simple
|
6
|
+
guard 'jruby-minitest', :spec_paths => ["test"] do
|
7
|
+
# with Minitest::Unit
|
8
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
9
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
10
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
11
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
12
|
+
end
|
13
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jack Xu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# DockTest
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dock_test'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dock_test
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/dock_test/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/config.ru
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'json'
|
3
|
+
app = Proc.new do |env|
|
4
|
+
|
5
|
+
request_json = {
|
6
|
+
verb: env["REQUEST_METHOD"],
|
7
|
+
uri: env["REQUEST_URI"],
|
8
|
+
body: env["rack.input"].read,
|
9
|
+
protcol: env["SERVER_PROTOCOL"],
|
10
|
+
headers: Hash[env.select {|k, v| k.start_with?("HTTP_") }.map {|k, v| [k[5..-1], v] }]
|
11
|
+
}.to_json
|
12
|
+
|
13
|
+
[200, {'Content-Type' => "application/json", 'Content-Length' => request_json.length.to_s}, [request_json]]
|
14
|
+
end
|
15
|
+
|
16
|
+
run app
|
data/dock_test.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dock_test/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dock_test"
|
8
|
+
spec.version = DockTest::VERSION
|
9
|
+
spec.authors = ["Jack Xu"]
|
10
|
+
spec.email = ["jackxxu@gmail.com"]
|
11
|
+
spec.summary = spec.description = %q{a outside-in service api test framework.}
|
12
|
+
spec.homepage = "https://github.com/jackxxu/dock_test"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'multi_json'
|
21
|
+
spec.add_dependency 'rack'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module DockTest
|
2
|
+
module Methods
|
3
|
+
|
4
|
+
%w(get post put patch delete options head).each do |meth_name|
|
5
|
+
define_method meth_name do |path, params = '', headers = {}, &block|
|
6
|
+
|
7
|
+
uri = URI.join(DockTest.url, path)
|
8
|
+
|
9
|
+
if DockTest.localhost?
|
10
|
+
uri.port = DockTest.port
|
11
|
+
end
|
12
|
+
|
13
|
+
# add the params to the GET requests
|
14
|
+
if meth_name == 'get' && !params.empty?
|
15
|
+
if(params.is_a?(Hash))
|
16
|
+
uri.query = URI.encode_www_form(URI.decode_www_form(uri.query || '') + params.to_a)
|
17
|
+
else
|
18
|
+
uri.query = uri.query.nil? ? params : "#{uri.query}&#{params}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
@last_request = Net::HTTP.const_get(meth_name.capitalize).new(uri.request_uri)
|
23
|
+
|
24
|
+
# add the params to the body of other requests
|
25
|
+
if meth_name != 'get'
|
26
|
+
@last_request.body = params
|
27
|
+
end
|
28
|
+
|
29
|
+
# sets the headers
|
30
|
+
headers.each do |key, value|
|
31
|
+
@last_request.add_field(key, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
# execute the request
|
35
|
+
@last_response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
36
|
+
http.request(@last_request)
|
37
|
+
end
|
38
|
+
|
39
|
+
yield @last_response if block_given?
|
40
|
+
|
41
|
+
@last_response
|
42
|
+
end
|
43
|
+
|
44
|
+
private meth_name
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def last_response
|
49
|
+
@last_response
|
50
|
+
end
|
51
|
+
|
52
|
+
def last_request
|
53
|
+
@last_request
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/dock_test.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require "dock_test/version"
|
2
|
+
require "dock_test/methods"
|
3
|
+
require "dock_test/assertions"
|
4
|
+
|
5
|
+
module DockTest
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_writer :port
|
10
|
+
def port
|
11
|
+
@port ||= 9999
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :url
|
15
|
+
# sets the test url
|
16
|
+
# also creates a new webrick server process
|
17
|
+
def url=(value)
|
18
|
+
@url = value
|
19
|
+
if localhost?
|
20
|
+
require "rack"
|
21
|
+
require 'webrick'
|
22
|
+
server = WEBrick::HTTPServer.new(:Port => port).tap do |server|
|
23
|
+
server.mount '/', Rack::Handler::WEBrick, Rack::Server.new.app
|
24
|
+
end
|
25
|
+
t = Thread.new { server.start }
|
26
|
+
trap('INT') do
|
27
|
+
server.shutdown
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def localhost?
|
34
|
+
@url && ['127.0.0.1', 'localhost'].include?(URI.parse(@url).host)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
class TestMethods < Minitest::Test
|
5
|
+
|
6
|
+
include DockTest::Methods
|
7
|
+
DockTest.url = 'http://localhost:3000'
|
8
|
+
|
9
|
+
def test_get_method_with_hash_body
|
10
|
+
get '/path?foo=bar', {a: :b}, {'CONTENT_TYPE' => 'application/json'}
|
11
|
+
|
12
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar&a=b'
|
13
|
+
assert_equal last_response_json['verb'], 'GET'
|
14
|
+
assert_equal last_response_json['body'], ''
|
15
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_method_with_string_body
|
19
|
+
get '/path?foo=bar', 'a=b', {'CONTENT_TYPE' => 'application/json'}
|
20
|
+
|
21
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar&a=b'
|
22
|
+
assert_equal last_response_json['verb'], 'GET'
|
23
|
+
assert_equal last_response_json['body'], ''
|
24
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_method_to_root
|
28
|
+
get '/', 'a=b', {'CONTENT_TYPE' => 'application/json'}
|
29
|
+
|
30
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/?a=b'
|
31
|
+
assert_equal last_response_json['verb'], 'GET'
|
32
|
+
assert_equal last_response_json['body'], ''
|
33
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_post_method
|
37
|
+
post '/path?foo=bar', MultiJson.dump({guid: '12345'}), {'CONTENT_TYPE' => 'application/json'}
|
38
|
+
|
39
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar'
|
40
|
+
assert_equal last_response_json['verb'], 'POST'
|
41
|
+
assert_equal last_response_json['body'], "{\"guid\":\"12345\"}"
|
42
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_put_method
|
46
|
+
put '/path?foo=bar', MultiJson.dump({guid: '12345'}), {'CONTENT_TYPE' => 'application/json'}
|
47
|
+
|
48
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar'
|
49
|
+
assert_equal last_response_json['verb'], 'PUT'
|
50
|
+
assert_equal last_response_json['body'], "{\"guid\":\"12345\"}"
|
51
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_patch_method
|
55
|
+
patch '/path?foo=bar', MultiJson.dump({guid: '12345'}), {'CONTENT_TYPE' => 'application/json'}
|
56
|
+
|
57
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar'
|
58
|
+
assert_equal last_response_json['verb'], 'PATCH'
|
59
|
+
assert_equal last_response_json['body'], "{\"guid\":\"12345\"}"
|
60
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_delete_method
|
64
|
+
delete '/path?foo=bar', '', {'CONTENT_TYPE' => 'application/json'}
|
65
|
+
|
66
|
+
assert_equal last_response_json['uri'], 'http://localhost:9999/path?foo=bar'
|
67
|
+
assert_equal last_response_json['verb'], 'DELETE'
|
68
|
+
assert_equal last_response_json['body'], ''
|
69
|
+
assert_equal last_response_json['headers']['CONTENT_TYPE'], 'application/json'
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def last_response_json
|
74
|
+
MultiJson.load(last_response.body)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dock_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Xu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.6'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
description: a outside-in service api test framework.
|
70
|
+
email:
|
71
|
+
- jackxxu@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- Guardfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- config.ru
|
83
|
+
- dock_test.gemspec
|
84
|
+
- lib/dock_test.rb
|
85
|
+
- lib/dock_test/assertions.rb
|
86
|
+
- lib/dock_test/methods.rb
|
87
|
+
- lib/dock_test/version.rb
|
88
|
+
- test/dock_test/test_localhost_methods.rb
|
89
|
+
- test/test_helper.rb
|
90
|
+
homepage: https://github.com/jackxxu/dock_test
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: a outside-in service api test framework.
|
114
|
+
test_files:
|
115
|
+
- test/dock_test/test_localhost_methods.rb
|
116
|
+
- test/test_helper.rb
|