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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c609fc3bdd9124c5b52e4388ba54b43c8f3abf1b
4
- data.tar.gz: 9ced6d3f6317248a839969384859155c4b6eb090
3
+ metadata.gz: 195c03f65558691d1b564ef22563d42d2f69ced6
4
+ data.tar.gz: 90af28506d7c2870b438bfa7a755ea1dc9a994ac
5
5
  SHA512:
6
- metadata.gz: e90f2e0151bd3df700b405a116ead38d4659115d22f9bfad328838dfa9574d895832ffaafb2d7a13169bfee7131d6b02ec3fbe1cc232a1f5479f444aa85a490f
7
- data.tar.gz: 86a40c481cb302a76a4bab6e58767db0d83eadd6df5b8df4fda2859603e962392f21619bed86904f1462a27101a6487b50c2a8e5d5871d73e801bf76d1cea173
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 spin up and tear down different Hoverfly instances. See below for examples, as well as a reference of the actions that can be done
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
- # Start Hoverfly as a proxy
30
- Hoverfly.start('test', 'proxy')
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
- # Start Hoverfly as a webserver
50
- Hoverfly.start('test')
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 :target
5
+ attr_reader :admin_port, :proxy_port
6
6
 
7
- def start(target, mode = 'webserver', **ports)
8
- @target = target
9
- admin_port = ports.fetch(:admin, 8888)
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
- header_path = meta[:header] || File.expand_path('schema_metadata/header.json', __dir__)
42
- footer_path = meta[:footer] || File.expand_path('schema_metadata/footer.json', __dir__)
43
- header = File.open(header_path)
44
- footer = File.open(footer_path)
45
- mock = header.read
46
- all_simulations = file_list.map do |filename|
47
- file = File.open(filename)
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(' /api/v2/hoverfly/destination').response.body
21
+ HoverflyAPI.get('/api/v2/hoverfly/destination').response.body
22
22
  end
23
23
 
24
- def update_destinitation(destination)
25
- HoverflyAPI.put(' /api/v2/hoverfly/destination', headers: { 'Content-Type' => 'application/json' }, body: { destination: destination }.to_json).response.body
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
@@ -0,0 +1,15 @@
1
+ {
2
+ "data": {
3
+ "pairs": [
4
+ <%= yield %>
5
+ ],
6
+ "globalActions": {
7
+ "delays": []
8
+ }
9
+ },
10
+ "meta": {
11
+ "schemaVersion": "v2",
12
+ "hoverflyVersion": "v0.10.2",
13
+ "timeExported": "2017-05-05T15:10:36-04:00"
14
+ }
15
+ }
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
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-06-20 00:00:00.000000000 Z
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/footer.json
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
@@ -1,11 +0,0 @@
1
- ],
2
- "globalActions": {
3
- "delays": []
4
- }
5
- },
6
- "meta": {
7
- "schemaVersion": "v2",
8
- "hoverflyVersion": "v0.10.2",
9
- "timeExported": "2017-05-05T15:10:36-04:00"
10
- }
11
- }
@@ -1,3 +0,0 @@
1
- {
2
- "data": {
3
- "pairs": [