hoverfly 0.0.3 → 0.0.4
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 +6 -3
- data/lib/client.rb +12 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c609fc3bdd9124c5b52e4388ba54b43c8f3abf1b
|
4
|
+
data.tar.gz: 9ced6d3f6317248a839969384859155c4b6eb090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e90f2e0151bd3df700b405a116ead38d4659115d22f9bfad328838dfa9574d895832ffaafb2d7a13169bfee7131d6b02ec3fbe1cc232a1f5479f444aa85a490f
|
7
|
+
data.tar.gz: 86a40c481cb302a76a4bab6e58767db0d83eadd6df5b8df4fda2859603e962392f21619bed86904f1462a27101a6487b50c2a8e5d5871d73e801bf76d1cea173
|
data/README.md
CHANGED
@@ -26,7 +26,8 @@ This gem gives you full access to the Hoverfly API as well as the ability to spi
|
|
26
26
|
```ruby
|
27
27
|
require 'hoverfly'
|
28
28
|
|
29
|
-
Hoverfly
|
29
|
+
# Start Hoverfly as a proxy
|
30
|
+
Hoverfly.start('test', 'proxy')
|
30
31
|
|
31
32
|
# Set Hoverfly to capture mode
|
32
33
|
Hoverfly.update_mode('capture')
|
@@ -45,6 +46,7 @@ Hoverfly.stop
|
|
45
46
|
```ruby
|
46
47
|
require 'hoverfly'
|
47
48
|
|
49
|
+
# Start Hoverfly as a webserver
|
48
50
|
Hoverfly.start('test')
|
49
51
|
|
50
52
|
# Set Hoverfly to simulate mode
|
@@ -54,7 +56,7 @@ Hoverfly.update_mode('simulate')
|
|
54
56
|
Hoverfly.import(['simulation.json'])
|
55
57
|
|
56
58
|
# Now when we make the API call, we will get the response that we imported into Hoverfly
|
57
|
-
`curl
|
59
|
+
`curl http://localhost:8500`
|
58
60
|
|
59
61
|
Hoverfly.stop
|
60
62
|
```
|
@@ -62,9 +64,10 @@ Hoverfly.stop
|
|
62
64
|
### Available Methods
|
63
65
|
| Method | Description | Example |
|
64
66
|
|--------|-------------|---------|
|
65
|
-
|start(tag, ports)|This method starts up a new instance of Hoverfly. It takes in a tag, which is required, as well as
|
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)|
|
66
68
|
|get_current_simulations|Returns the current simulation being used by Hoverfly|Hoverfly.get_current_simulations|
|
67
69
|
|get_current_simulation_schema|Returns the schema of the simulations currently being used by Hoverfly|Hoverfly.get_current_simulation_schema|
|
70
|
+
|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'])|
|
68
71
|
|get_config_info|Returns Hoverfly configuration info|Hoverfly.get_config_info|
|
69
72
|
|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|
|
70
73
|
|update_destinitation|Sets / updates the destination URL that Hoverfly looks at|Hoverfly.update_destination('http://time.jsontest.com')|
|
data/lib/client.rb
CHANGED
@@ -4,13 +4,18 @@ class Hoverfly
|
|
4
4
|
class << self
|
5
5
|
attr_reader :target
|
6
6
|
|
7
|
-
def start(target,
|
7
|
+
def start(target, mode = 'webserver', **ports)
|
8
8
|
@target = target
|
9
9
|
admin_port = ports.fetch(:admin, 8888)
|
10
10
|
proxy_port = ports.fetch(:proxy, 8500)
|
11
11
|
puts "Starting target #{target} with admin #{admin_port} and proxy #{proxy_port}"
|
12
12
|
system "hoverctl targets create #{@target}"
|
13
|
-
|
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
|
14
19
|
HoverflyAPI.default_options.update(verify: false)
|
15
20
|
HoverflyAPI.format :json
|
16
21
|
HoverflyAPI.base_uri "http://localhost:#{admin_port}"
|
@@ -23,22 +28,22 @@ class Hoverfly
|
|
23
28
|
end
|
24
29
|
|
25
30
|
def middleware(middleware_location)
|
26
|
-
update_middleware({binary: '', script: '', remote: ''}.merge(middleware_location))
|
31
|
+
update_middleware({ binary: '', script: '', remote: '' }.merge(middleware_location))
|
27
32
|
end
|
28
33
|
|
29
|
-
def import(file_list)
|
30
|
-
update_simulations(to_simulation(file_list))
|
34
|
+
def import(file_list, meta = {})
|
35
|
+
update_simulations(to_simulation(file_list, meta))
|
31
36
|
end
|
32
37
|
|
33
38
|
private
|
34
39
|
|
35
|
-
def to_simulation(file_list, meta
|
40
|
+
def to_simulation(file_list, meta)
|
36
41
|
header_path = meta[:header] || File.expand_path('schema_metadata/header.json', __dir__)
|
37
42
|
footer_path = meta[:footer] || File.expand_path('schema_metadata/footer.json', __dir__)
|
38
43
|
header = File.open(header_path)
|
39
44
|
footer = File.open(footer_path)
|
40
45
|
mock = header.read
|
41
|
-
all_simulations = file_list.map do |filename|
|
46
|
+
all_simulations = file_list.map do |filename|
|
42
47
|
file = File.open(filename)
|
43
48
|
simulation = file.read
|
44
49
|
file.close
|