hoverfly 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +16 -12
- data/lib/client.rb +12 -36
- data/lib/endpoints.rb +3 -3
- data/lib/schema_metadata/schema.json.erb +15 -0
- metadata +3 -4
- data/lib/schema_metadata/footer.json +0 -11
- data/lib/schema_metadata/header.json +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 195c03f65558691d1b564ef22563d42d2f69ced6
|
4
|
+
data.tar.gz: 90af28506d7c2870b438bfa7a755ea1dc9a994ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e1841e75801f9c3e10a67cdef3c1b1ef9103f3d15eb3224fafbc21168b50673639e1efa22981967b50a211beed8ebb76e907e86f792580e491f9735b5c073ab
|
7
|
+
data.tar.gz: 900cdb2b1ee91f43efb782b6d400ac22f0119971fd81b7555da5dad03685fb5ee2133cf1a0150f11823a4b0f5b3519e7d31aa58af8e517a2e93c81cfbb5d89cc
|
data/README.md
CHANGED
@@ -20,14 +20,24 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
This gem gives you full access to the Hoverfly API as well as the ability to
|
23
|
+
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.
|
24
|
+
|
25
|
+
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:
|
26
|
+
|
27
|
+
$ hoverctl start
|
28
|
+
|
29
|
+
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:
|
30
|
+
|
31
|
+
$ docker run -d -p 8888:8888 -p 8500:8500 --name hoverfly hoverfly
|
32
|
+
|
33
|
+
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)
|
24
34
|
|
25
35
|
### Recording an API response
|
26
36
|
```ruby
|
27
37
|
require 'hoverfly'
|
28
38
|
|
29
|
-
#
|
30
|
-
Hoverfly.
|
39
|
+
# Specify the ports to be used to communicate with Hoverfly
|
40
|
+
Hoverfly.set_ports(admin: 8888, proxy: 8500)
|
31
41
|
|
32
42
|
# Set Hoverfly to capture mode
|
33
43
|
Hoverfly.update_mode('capture')
|
@@ -39,15 +49,13 @@ Hoverfly.update_mode('capture')
|
|
39
49
|
file = File.open( "simulation.json", "w" )
|
40
50
|
file << Hoverfly.get_current_simulations
|
41
51
|
file.close
|
42
|
-
|
43
|
-
Hoverfly.stop
|
44
52
|
```
|
45
53
|
### Replaying an existing API response
|
46
54
|
```ruby
|
47
55
|
require 'hoverfly'
|
48
56
|
|
49
|
-
#
|
50
|
-
Hoverfly.
|
57
|
+
# Specify the ports to be used to communicate with Hoverfly
|
58
|
+
Hoverfly.set_ports(admin: 8888, proxy: 8500)
|
51
59
|
|
52
60
|
# Set Hoverfly to simulate mode
|
53
61
|
Hoverfly.update_mode('simulate')
|
@@ -56,15 +64,12 @@ Hoverfly.update_mode('simulate')
|
|
56
64
|
Hoverfly.import(['simulation.json'])
|
57
65
|
|
58
66
|
# Now when we make the API call, we will get the response that we imported into Hoverfly
|
59
|
-
`curl http://localhost:8500`
|
60
|
-
|
61
|
-
Hoverfly.stop
|
67
|
+
`curl --proxy http://localhost:8500 http://time.jsontest.com`
|
62
68
|
```
|
63
69
|
|
64
70
|
### Available Methods
|
65
71
|
| Method | Description | Example |
|
66
72
|
|--------|-------------|---------|
|
67
|
-
|start(tag, mode, ports)|This method starts up a new instance of Hoverfly. It takes in a tag, which is required, an optional mode, as well as keyword arguments that allow you to specify the admin and proxy ports. If no mode is specified, Hoverfly will start in webserver mode by default. If no hash is specified, then the default admin port (8888) and proxy port (8500) are used.| Hoverfly.start('test', 'proxy', admin: 9000, proxy: 9001)|
|
68
73
|
|get_current_simulations|Returns the current simulation being used by Hoverfly|Hoverfly.get_current_simulations|
|
69
74
|
|get_current_simulation_schema|Returns the schema of the simulations currently being used by Hoverfly|Hoverfly.get_current_simulation_schema|
|
70
75
|
|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'])|
|
@@ -81,7 +86,6 @@ Hoverfly.stop
|
|
81
86
|
|get_cached_data|Returns data that Hoverfly has cached|Hoverfly.get_cached_data|
|
82
87
|
|clear_cached_data|Clears the Hoverfly cache|Hoverfly.clear_cached_data|
|
83
88
|
|get_logs|Returns the Hoverfly logs|Hoverfly.get_logs|
|
84
|
-
|stop|Kills the current instance of Hoverfly. This shuts down Hoverfly and deletes the tag used to start that instance. Once Hoverfly is stopped, the tag can be reused|Hoverfly.stop|
|
85
89
|
|
86
90
|
## Contributing
|
87
91
|
|
data/lib/client.rb
CHANGED
@@ -2,29 +2,14 @@ class Hoverfly
|
|
2
2
|
extend HoverflyAPI
|
3
3
|
|
4
4
|
class << self
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :admin_port, :proxy_port
|
6
6
|
|
7
|
-
def
|
8
|
-
@
|
9
|
-
|
10
|
-
proxy_port = ports.fetch(:proxy, 8500)
|
11
|
-
puts "Starting target #{target} with admin #{admin_port} and proxy #{proxy_port}"
|
12
|
-
system "hoverctl targets create #{@target}"
|
13
|
-
if mode == 'proxy'
|
14
|
-
system "hoverctl start --admin-port #{admin_port} --proxy-port #{proxy_port} -t #{@target}"
|
15
|
-
else
|
16
|
-
system "hoverctl start webserver --admin-port #{admin_port} --proxy-port #{proxy_port} -t #{@target}"
|
17
|
-
puts "Unknown Hoverfly mode \"#{mode}\". Starting in webserver mode" if mode != 'webserver'
|
18
|
-
end
|
7
|
+
def set_ports(admin:, proxy:)
|
8
|
+
@admin_port = admin
|
9
|
+
@proxy_port = proxy
|
19
10
|
HoverflyAPI.default_options.update(verify: false)
|
20
11
|
HoverflyAPI.format :json
|
21
|
-
HoverflyAPI.base_uri "http://localhost:#{admin_port}"
|
22
|
-
end
|
23
|
-
|
24
|
-
def stop
|
25
|
-
puts "Stopping target #{Hoverfly.target} with base URL #{HoverflyAPI.base_uri}"
|
26
|
-
system "hoverctl stop -t #{@target}"
|
27
|
-
system "hoverctl targets delete #{@target} -f"
|
12
|
+
HoverflyAPI.base_uri "http://localhost:#{@admin_port}"
|
28
13
|
end
|
29
14
|
|
30
15
|
def middleware(middleware_location)
|
@@ -38,22 +23,13 @@ class Hoverfly
|
|
38
23
|
private
|
39
24
|
|
40
25
|
def to_simulation(file_list, meta)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
simulation = file.read
|
49
|
-
file.close
|
50
|
-
simulation
|
51
|
-
end
|
52
|
-
mock << all_simulations.join(',')
|
53
|
-
mock << footer.read
|
54
|
-
header.close
|
55
|
-
footer.close
|
56
|
-
mock
|
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)
|
57
33
|
end
|
58
34
|
end
|
59
35
|
end
|
data/lib/endpoints.rb
CHANGED
@@ -18,11 +18,11 @@ module HoverflyAPI
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_current_destination
|
21
|
-
HoverflyAPI.get('
|
21
|
+
HoverflyAPI.get('/api/v2/hoverfly/destination').response.body
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
HoverflyAPI.put('
|
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
26
|
end
|
27
27
|
|
28
28
|
def get_current_middleware
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoverfly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Automation Wizards
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -78,8 +78,7 @@ files:
|
|
78
78
|
- lib/client.rb
|
79
79
|
- lib/endpoints.rb
|
80
80
|
- lib/hoverfly.rb
|
81
|
-
- lib/schema_metadata/
|
82
|
-
- lib/schema_metadata/header.json
|
81
|
+
- lib/schema_metadata/schema.json.erb
|
83
82
|
homepage: https://github.com/automation-wizards/hoverfly
|
84
83
|
licenses:
|
85
84
|
- MIT
|