dkastner-hoverfly 0.0.6
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/LICENSE +21 -0
- data/README.md +97 -0
- data/lib/client.rb +35 -0
- data/lib/endpoints.rb +67 -0
- data/lib/hoverfly.rb +5 -0
- data/lib/schema_metadata/schema.json.erb +15 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d99f28981261879e31d4d8bd018ed498aa09695d
|
4
|
+
data.tar.gz: 858b991506be34b6c6d2af0750b78f6b7df05b85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b845c5ac96febadf8dc043f7e38b2bae1973cf139d8b7b0a356f06962cc06e09da6c745bb8d07537217655ece2a0a9f2763e01119a64604f2f174cf3a7c5eeee
|
7
|
+
data.tar.gz: 200301bef97894e9b7a81bea70326eaf6c1a7baf4ed8de2e8517111c88c219ef322d5756d68389757b52ce8b91a10b5f2da7948e2e880fda687c27fe3ac2cb6b
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT LICENSE
|
2
|
+
|
3
|
+
Copyright (c) Justin Commu <Justin.Commu@loblaw.ca>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Hoverfly Gem
|
2
|
+
[](https://travis-ci.org/azohra/hoverfly)
|
3
|
+
|
4
|
+
Welcome to the Hoverfly Gem, a ruby written wrapper for Hoverfly!
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'hoverfly'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install hoverfly
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
This gem gives you full access to the Hoverfly API as well as the ability to dynamically build simulations to import into Hoverfly. See below for examples, as well as a reference of the actions that can be done.
|
25
|
+
|
26
|
+
This gem assumes that you have already started a running instance of Hoverfly. This can be done in multiple ways. For example, you can install Hoverfly on your host system and start it by executing:
|
27
|
+
|
28
|
+
$ hoverctl start
|
29
|
+
|
30
|
+
Alternatively, you can start Hoverfly in a docker container and expose the Hoverfly admin and proxy ports to the host system as. If you have a docker image named `hoverfly` with Hoverfly already installed, then you can do this as follows:
|
31
|
+
|
32
|
+
$ docker run -d -p 8888:8888 -p 8500:8500 --name hoverfly hoverfly
|
33
|
+
|
34
|
+
The following examples assume that you have already started a Hoverfly instance (docker or otherwise) with the default admin and proxy ports (8888 and 8500 respectively)
|
35
|
+
|
36
|
+
### Recording an API response
|
37
|
+
```ruby
|
38
|
+
require 'hoverfly'
|
39
|
+
|
40
|
+
# Specify the ports to be used to communicate with Hoverfly
|
41
|
+
Hoverfly.set_ports(admin: 8888, proxy: 8500)
|
42
|
+
|
43
|
+
# Set Hoverfly to capture mode
|
44
|
+
Hoverfly.update_mode('capture')
|
45
|
+
|
46
|
+
# Send the API request to be recorded
|
47
|
+
`curl --proxy http://localhost:8500 http://time.jsontest.com `
|
48
|
+
|
49
|
+
# Export the simulation that Hoverfly has recorded
|
50
|
+
file = File.open( "simulation.json", "w" )
|
51
|
+
file << Hoverfly.get_current_simulations
|
52
|
+
file.close
|
53
|
+
```
|
54
|
+
### Replaying an existing API response
|
55
|
+
```ruby
|
56
|
+
require 'hoverfly'
|
57
|
+
|
58
|
+
# Specify the ports to be used to communicate with Hoverfly
|
59
|
+
Hoverfly.set_ports(admin: 8888, proxy: 8500)
|
60
|
+
|
61
|
+
# Set Hoverfly to simulate mode
|
62
|
+
Hoverfly.update_mode('simulate')
|
63
|
+
|
64
|
+
# Import an existing simulation into Hoverfly
|
65
|
+
Hoverfly.import(['simulation.json'])
|
66
|
+
|
67
|
+
# Now when we make the API call, we will get the response that we imported into Hoverfly
|
68
|
+
`curl --proxy http://localhost:8500 http://time.jsontest.com`
|
69
|
+
```
|
70
|
+
|
71
|
+
### Available Methods
|
72
|
+
| Method | Description | Example |
|
73
|
+
|--------|-------------|---------|
|
74
|
+
|get_current_simulations|Returns the current simulation being used by Hoverfly|Hoverfly.get_current_simulations|
|
75
|
+
|get_current_simulation_schema|Returns the schema of the simulations currently being used by Hoverfly|Hoverfly.get_current_simulation_schema|
|
76
|
+
|import(file_list)|Compiles the given files into a simulation JSON file, and then sets that file as the simulation to be used by Hoverfly|Hoverfly.import(['./login.json', './logout.json'])|
|
77
|
+
|get_config_info|Returns Hoverfly configuration info|Hoverfly.get_config_info|
|
78
|
+
|get_current_destination|Returns the current destination that has been set for Hoverfly. Once a destination has been set, Hoverfly only intercepts traffic for that URL|Hoverfly.get_current_destination|
|
79
|
+
|update_destinitation|Sets / updates the destination URL that Hoverfly looks at|Hoverfly.update_destination('http://time.jsontest.com')|
|
80
|
+
|get_current_middleware|Returns info about the middleware that Hoverfly is currently set to use|Hoverfly.get_current_middleware|
|
81
|
+
|middleware|This allows you to set the middleware to be used by Hoverfly. This method accepts a hash where the key specifies the type of middleware, and the value specifies the location. For example if wanted to use a remote server for your middleware, you would pass {remote: <server_url>} to this method|Hoverfly.middleware({remote: 'http://mymiddleware.com'})|
|
82
|
+
|get_current_mode|Returns the mode that Hoverfly is currently set to|Hoverfly.get_current_mode|
|
83
|
+
|update_mode|Changes the mode that Hoverfly in running in. By default, Hoverfly starts in simulate mdoe|Hoverfly.update_mode('capture')|
|
84
|
+
|get_usage|Returns usage info for Hoverfly|Hoverfly.get_usage|
|
85
|
+
|get_version|Returns the current Hoverfly version|Hoverfly.get_version|
|
86
|
+
|get_upstream_proxy|Returns the proxy port that Hoverfly is currently using|Hoverfly.get_upstream_proxy|
|
87
|
+
|get_cached_data|Returns data that Hoverfly has cached|Hoverfly.get_cached_data|
|
88
|
+
|clear_cached_data|Clears the Hoverfly cache|Hoverfly.clear_cached_data|
|
89
|
+
|get_logs|Returns the Hoverfly logs|Hoverfly.get_logs|
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
Bug reports and pull requests are welcome. Note that if you are reporting a bug then make sure to include a failing spec that highlights an example of the bug. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
94
|
+
|
95
|
+
## License
|
96
|
+
|
97
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/client.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Hoverfly
|
2
|
+
extend HoverflyAPI
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_reader :admin_port, :proxy_port
|
6
|
+
|
7
|
+
def set_ports(admin:, proxy:, ip: 'localhost')
|
8
|
+
@admin_port = admin
|
9
|
+
@proxy_port = proxy
|
10
|
+
HoverflyAPI.default_options.update(verify: false)
|
11
|
+
HoverflyAPI.format :json
|
12
|
+
HoverflyAPI.base_uri "http://#{ip}:#{@admin_port}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def middleware(middleware_location)
|
16
|
+
update_middleware({ binary: '', script: '', remote: '' }.merge(middleware_location))
|
17
|
+
end
|
18
|
+
|
19
|
+
def import(file_list, meta = {})
|
20
|
+
update_simulations(to_simulation(file_list, meta))
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def to_simulation(file_list, meta)
|
26
|
+
schema_path = meta[:schema] || File.expand_path('schema_metadata/schema.json.erb', __dir__)
|
27
|
+
all_simulations = file_list.map { |filename| File.read(filename) }
|
28
|
+
erb(File.read(schema_path)) { all_simulations.join(',') }
|
29
|
+
end
|
30
|
+
|
31
|
+
def erb(template)
|
32
|
+
ERB.new(template).result(binding)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/endpoints.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module HoverflyAPI
|
2
|
+
include HTTParty
|
3
|
+
|
4
|
+
def get_current_simulations
|
5
|
+
HoverflyAPI.get('/api/v2/simulation').response.body
|
6
|
+
end
|
7
|
+
|
8
|
+
def update_simulations(simulation)
|
9
|
+
HoverflyAPI.put('/api/v2/simulation', headers: { 'Content-Type' => 'application/json' }, body: simulation).response.body
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_current_simulation_schema
|
13
|
+
HoverflyAPI.get('/api/v2/simulation/schema').response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_config_info
|
17
|
+
HoverflyAPI.get('/api/v2/hoverfly').response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_current_destination
|
21
|
+
HoverflyAPI.get('/api/v2/hoverfly/destination').response.body
|
22
|
+
end
|
23
|
+
|
24
|
+
def update_destination(destination)
|
25
|
+
HoverflyAPI.put('/api/v2/hoverfly/destination', headers: { 'Content-Type' => 'application/json' }, body: { destination: destination }.to_json).response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_current_middleware
|
29
|
+
HoverflyAPI.get('/api/v2/hoverfly/middleware').response.body
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_middleware(middleware_request)
|
33
|
+
HoverflyAPI.put('/api/v2/hoverfly/middleware', headers: { 'Content-Type' => 'application/json' }, body: middleware_request.to_json).response.body
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_current_mode
|
37
|
+
HoverflyAPI.get('/api/v2/hoverfly/mode').response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_mode(mode)
|
41
|
+
HoverflyAPI.put('/api/v2/hoverfly/mode', headers: { 'Content-Type' => 'application/json' }, body: { mode: mode }.to_json).response.body
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_usage
|
45
|
+
HoverflyAPI.get('/api/v2/hoverfly/usage').response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_version
|
49
|
+
HoverflyAPI.get('/api/v2/hoverfly/version').response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_upstream_proxy
|
53
|
+
HoverflyAPI.get('/api/v2/hoverfly/upstream-proxy').response.body
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_cached_data
|
57
|
+
HoverflyAPI.get('/api/v2/cache').response.body
|
58
|
+
end
|
59
|
+
|
60
|
+
def clear_cached_data
|
61
|
+
HoverflyAPI.delete('/api/v2/cache').response.body
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_logs
|
65
|
+
HoverflyAPI.get('/api/v2/logs').response.body
|
66
|
+
end
|
67
|
+
end
|
data/lib/hoverfly.rb
ADDED
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dkastner-hoverfly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Automation Wizards
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.7
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.7
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.11.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.11.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.4.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.4
|
69
|
+
description: Use this library to interact with Hoverfly in ruby
|
70
|
+
email:
|
71
|
+
- bjorn.ramroop@loblaw.ca
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- lib/client.rb
|
79
|
+
- lib/endpoints.rb
|
80
|
+
- lib/hoverfly.rb
|
81
|
+
- lib/schema_metadata/schema.json.erb
|
82
|
+
homepage: https://github.com/automation-wizards/hoverfly
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.5.1
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Ruby wrapper for Hoverfly
|
106
|
+
test_files: []
|