loadrunner 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f956c6c96502b4a447c61d0ba22965de6384a5388979160538eadf19554a60a1
4
- data.tar.gz: d34ffbdb98ecf2c288655456ac527ef56ebf87cbaa8d6c8849cfc3acca33e656
3
+ metadata.gz: ac288df3a479098d56c66cf0a2501fd5c8d59317d1243aba52290340c60892af
4
+ data.tar.gz: 74cdcf9ef45c4d7b913352b686160203aa03c6ef2722ea5fccc05020691bd3a8
5
5
  SHA512:
6
- metadata.gz: cfc5af284ca6ad9dd20a8c24debce0d774653a30dfbcdce33f8afbda5fb192a9afc8e2e22045dab4c12cb5f598f1f22bf32d2a58b509d00ffb5b73190d807f4d
7
- data.tar.gz: 5f62450212ac311be7baad8ee8c55729d6f026e351766e5e252977655453a6b8a034321991dd1e3bde1fddeb80801cd54e6551a4515e78441f1c74c44313fd30
6
+ metadata.gz: 4fc9eec533a6d826b86b1e9c227375230c114f9763463239cd8c886cdc5d0ec57a4d53ae5be11e0363512d6c172e01b764c129ef64e740fea89549b9bc88046e
7
+ data.tar.gz: 981e1c6df07e8799691b69ea81528bb83db9edc2ff0b3e9c17be04ac5453a384c423e15b199d8abb86493de660ba47cf63db8eefbdf74444d312f505fba9bbd9
data/README.md CHANGED
@@ -41,7 +41,7 @@ Getting Started
41
41
  $ loadrunner server
42
42
 
43
43
  # In another terminal, send a sample webhook event
44
- $ loadrunner send localhost:3000 myrepo push master
44
+ $ loadrunner event localhost:3000 myrepo push master
45
45
 
46
46
  # Verify the handler was executed
47
47
  $ cat output.txt
@@ -61,12 +61,13 @@ You can run both the server and the client using Docker.
61
61
  $ docker run -p3000:3000 dannyben/loadrunner server
62
62
 
63
63
  # Client
64
- $ docker run dannyben/loadrunner send http://webhook.server.com/payload repo push
64
+ $ docker run dannyben/loadrunner event http://webhook.server.com/payload repo push
65
65
 
66
66
  If you wish to connect the client to the server you are running through Docker,
67
67
  you can do something like this:
68
68
 
69
- $ docker run --network host dannyben/loadrunner send http://localhost:3000/payload repo push
69
+ $ docker run --network host dannyben/loadrunner event http://localhost:3000/payload repo push
70
70
 
71
+ See also: The [docker-compose file](docker-compose.yml).
71
72
 
72
73
  [1]: http://www.rubydoc.info/gems/loadrunner
@@ -6,13 +6,22 @@ module LoadRunner
6
6
  # Send simulated GitHub events to any webhook server
7
7
  class Client
8
8
  include HTTParty
9
- attr_accessor :secret_token, :base_url, :payload, :encoding
9
+ attr_accessor :secret_token, :host, :host_path, :payload, :encoding
10
10
 
11
11
  def initialize(opts={})
12
12
  @secret_token = opts[:secret_token]
13
- @base_url = opts[:base_url] || 'localhost:3000/payload'
14
13
  @encoding = opts[:encoding] || :json
15
- self.class.base_uri base_url
14
+
15
+ base_url = opts[:base_url] || 'http://localhost:3000/payload'
16
+ base_url = "http://#{base_url}" unless base_url =~ /^http/
17
+
18
+ url_parts = URI.parse base_url
19
+ @host_path = url_parts.path
20
+ url_parts.path = ''
21
+
22
+ @host = url_parts.to_s
23
+
24
+ self.class.base_uri host
16
25
  end
17
26
 
18
27
  # Send a simulated event using a shorthand syntax. opts can contain
@@ -30,15 +39,15 @@ module LoadRunner
30
39
  def send_payload(event, payload)
31
40
  @payload = payload.is_a?(String) ? payload : payload.to_json
32
41
  @payload = URI.encode_www_form(payload: @payload) if encoding == :form
33
- self.class.post "", body: @payload, headers: headers(event)
42
+ self.class.post host_path, body: @payload, headers: headers(event)
34
43
  end
35
44
 
36
45
  private
37
46
 
38
47
  def headers(event=:push)
39
48
  {}.tap do |header|
40
- header['X_GITHUB_EVENT'] = event.to_s if event
41
- header['X_HUB_SIGNATURE'] = signature if secret_token
49
+ header['X-GitHub-Event'] = event.to_s if event
50
+ header['X-Hub-Signature'] = signature if secret_token
42
51
  header['Content-Type'] = content_type[encoding]
43
52
  end
44
53
  end
@@ -9,14 +9,24 @@ module LoadRunner
9
9
 
10
10
  version VERSION
11
11
  docopt File.expand_path 'docopt.txt', __dir__
12
- subcommands [{'send' => 'send_event'}, 'status', 'server']
12
+ subcommands [:event, :payload, :status, :server]
13
13
 
14
- def send_event
14
+ def event
15
15
  client = Client.new client_opts
16
16
  response = client.send_event args['EVENT'], payload_opts
17
17
  show response
18
18
  end
19
19
 
20
+ def payload
21
+ client = Client.new client_opts
22
+ file = args['FILE']
23
+ raise ArgumentError, "File not found: #{file}" unless File.exist? file
24
+
25
+ json = File.read file
26
+ response = client.send_payload args['EVENT'], json
27
+ show response
28
+ end
29
+
20
30
  def server
21
31
  Server.prepare port: args['--port'], bind: args['--bind']
22
32
  Server.run!
@@ -2,7 +2,8 @@ LoadRunner
2
2
 
3
3
  Usage:
4
4
  loadrunner server [--port N --bind IP]
5
- loadrunner send URL REPO EVENT [REF --form]
5
+ loadrunner event URL REPO EVENT [REF --form]
6
+ loadrunner payload URL EVENT FILE [--form]
6
7
  loadrunner status REPO SHA STATE [--context TEXT --desc TEXT --url URL]
7
8
  loadrunner (-h|--help|--version)
8
9
 
@@ -10,8 +11,14 @@ Commands:
10
11
  server
11
12
  Start the webhook server.
12
13
 
13
- send
14
- Send a simulated GitHub event to a webhook server.
14
+ event
15
+ Send a simulated GitHub event to a webhook server. This will send a
16
+ simplified payload, with minimal properties and is intended for testing
17
+ of the loadrunner server.
18
+
19
+ payload
20
+ Send a JSON payload file to a webhook server. To obtain a proper
21
+ payload, you can copy one from your GitHub webhooks page.
15
22
 
16
23
  status
17
24
  Send status update to a github pull request.
@@ -29,6 +36,9 @@ Parameters:
29
36
  EVENT
30
37
  Any GitHub event, for example: push or ping.
31
38
 
39
+ FILE
40
+ A payload JSON file.
41
+
32
42
  REF
33
43
  A branch or tag specifier. This parameter supports four formats:
34
44
  * branch_name
@@ -70,10 +80,13 @@ Environment Variables:
70
80
 
71
81
  Examples:
72
82
  # Simulate push events
73
- loadrunner send localhost:3000/payload my_repo push master
74
- loadrunner send localhost:3000/payload my_repo push branch=master
75
- loadrunner send localhost:3000/payload my_repo push tag=staging --form
76
- loadrunner send localhost:3000/payload my_repo push refs/tags/staging
83
+ loadrunner event localhost:3000/payload my_repo push master
84
+ loadrunner event localhost:3000/payload my_repo push branch=master
85
+ loadrunner event localhost:3000/payload my_repo push tag=staging --form
86
+ loadrunner event localhost:3000/payload my_repo push refs/tags/staging
87
+
88
+ # Send a payload file
89
+ loadrunner payload localhost:3000/payload push payload.json
77
90
 
78
91
  # Start the server
79
92
  loadrunner server
@@ -1,3 +1,3 @@
1
1
  module LoadRunner
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt