Skip to content

Commit

Permalink
feat(Enqueuer): Generic hooks and protocols documentation
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Tests are inside hooks;
Protocols demand deeper documentation;
  • Loading branch information
virgs committed Jun 24, 2019
1 parent 3d1b477 commit 6c895b1
Show file tree
Hide file tree
Showing 80 changed files with 15,945 additions and 6,117 deletions.
16 changes: 4 additions & 12 deletions README.md
Expand Up @@ -76,7 +76,7 @@ What if I want to mock a http server and hit it at the same time, you may ask. N
payload: mock response
onMessageReceived:
assertions:
- expect: message.body
- expect: body
toContain: `enqueuer`
- name: failing test
expectToBeTruthy: false
Expand Down Expand Up @@ -111,7 +111,7 @@ Once we get this [plugin installed](#plugin_installation) we are able to create
payload: polyglot message
onMessageReceived:
assertions:
- expect: message.body
- expect: body
toContain: 123456

Now go nuts!
Expand Down Expand Up @@ -376,21 +376,13 @@ You're free to explore them however you want, even doing things like this:
By default, there are three hook events available:

**onInit**
Available in requisitions, publishers and subscriptions. It gets executed as soon as the test is initialized.
Available in requisitions, publishers and subscriptions. It gets executed as soon as the component is initialized.
As available parameter, an `elapsedTime` variable is given, counting every milliseconds since the instantiation of this component.

**onFinish**
Available in requisitions, publishers and subscriptions. It gets executed when the test is about to finish.
Available in requisitions, publishers and subscriptions. It gets executed when the component is about to finish.
As available parameter, an `elapsedTime` variable is given, counting every milliseconds since the instantiation of this component.

**onMessageReceived**
Available in every subscription and in some publishers that provide synchronous properties. Depending on its author's will.
It gets executed when the component receives a message.
A `message` object is available having all of attributes returned from the received message.
Depending on the protocol implementation, there'll be additional objects to this hook.
For instance, in the built-in http publisher implementation, there's a `statusCode`, `headers`, a `body` and others, and the subscription implementation has `body`, `query`, `params` and `headers `, among other variables.
`elapsedTime` is also available here, counting every milliseconds since the instantiation of this component.

**custom**
Depending on the protocol implementation/library/author's mood, the publisher/subscription may have additional hooks.
Such as `onError`, `onResponseReceived`, `onFileNotFound` and `onRedirect`...
Expand Down
2 changes: 1 addition & 1 deletion conf/config-example.yml
Expand Up @@ -23,7 +23,7 @@ outputs:

store:
filePlaceholderInjection: I'm persisted in config file
tcpPayload: "enqueuer Rocks"
tcpPayload: enqueuer Rocks

skipped: 5

Expand Down
Binary file modified docs/images/nqrFlow.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 4 additions & 12 deletions docs/index.html
Expand Up @@ -317,7 +317,7 @@ <h4 id="install_it" style="padding-left: 8px">1.1 install it</h4>
payload: mock response
onMessageReceived:
assertions:
- expect: message.body
- expect: body
toContain: `enqueuer`
- name: failing test
expectToBeTruthy: false
Expand Down Expand Up @@ -354,7 +354,7 @@ <h4 id="install_it" style="padding-left: 8px">1.1 install it</h4>
payload: polyglot message
onMessageReceived:
assertions:
- expect: message.body
- expect: body
toContain: 123456
</code></pre>

Expand Down Expand Up @@ -652,21 +652,13 @@ <h4 id="hooks" style="padding-left: 8px">3.1 hooks</h4>
<p>By default, there are three hook events available:</p>

<p><strong>onInit</strong> <br>
Available in requisitions, publishers and subscriptions. It gets executed as soon as the test is initialized.
Available in requisitions, publishers and subscriptions. It gets executed as soon as the component is initialized.
As available parameter, an <code class="yaml">elapsedTime</code> variable is given, counting every milliseconds since the instantiation of this component.</p>

<p><strong>onFinish</strong> <br>
Available in requisitions, publishers and subscriptions. It gets executed when the test is about to finish.
Available in requisitions, publishers and subscriptions. It gets executed when the component is about to finish.
As available parameter, an <code class="yaml">elapsedTime</code> variable is given, counting every milliseconds since the instantiation of this component. </p>

<p><strong>onMessageReceived</strong> <br>
Available in every subscription and in some publishers that provide synchronous properties. Depending on its author's will.
It gets executed when the component receives a message.
A <code class="yaml">message</code> object is available having all of attributes returned from the received message.
Depending on the protocol implementation, there'll be additional objects to this hook.
For instance, in the built-in http publisher implementation, there's a <code class="yaml">statusCode</code>, <code class="yaml">headers</code>, a <code class="yaml">body</code> and others, and the subscription implementation has <code class="yaml">body</code>, <code class="yaml">query</code>, <code class="yaml">params</code> and <code class="yaml">headers</code>, among other variables.
<code class="yaml">elapsedTime</code> is also available here, counting every milliseconds since the instantiation of this component.</p>

<p><strong>custom</strong>
Depending on the protocol implementation/library/author's mood, the publisher/subscription may have additional hooks.
Such as <code class="yaml">onError</code>, <code class="yaml">onResponseReceived</code>, <code class="yaml">onFileNotFound</code> and <code class="yaml">onRedirect</code>...
Expand Down
2 changes: 1 addition & 1 deletion examples/custom.yml
Expand Up @@ -12,7 +12,7 @@ subscriptions:
module: misc/custom-protocol.js
timeout: 1000
onMessageReceived:
script: payload = Buffer.from(message.payload);
script: payload = Buffer.from(payload);
assertions:
- name: Payload
expect: payload
Expand Down
2 changes: 1 addition & 1 deletion examples/file.yml
Expand Up @@ -17,7 +17,7 @@ subscriptions:
assertions:
- name: Some time has passed
expect: now
toBeGreaterThanOrEqualTo: message.content
toBeGreaterThanOrEqualTo: content
- name: Filename
expect: name
toContain: `temp/`
Expand Down
2 changes: 1 addition & 1 deletion examples/http-auth-basic.yml
Expand Up @@ -30,5 +30,5 @@ subscriptions:
onMessageReceived:
assertions:
- name: Payload
expect: message.body
expect: body
toBeEqualTo: `basic auth`
2 changes: 1 addition & 1 deletion examples/http-auth-bearer.yml
Expand Up @@ -29,5 +29,5 @@ subscriptions:
onMessageReceived:
assertions:
- name: Payload
expect: message.body
expect: body
toBeEqualTo: `Rech`
2 changes: 1 addition & 1 deletion examples/http-auth-digest.yml
Expand Up @@ -47,6 +47,6 @@ subscriptions:
onMessageReceived:
assertions:
- name: Payload
expect: message.body
expect: body
toBeEqualTo: `Rech`

17 changes: 15 additions & 2 deletions examples/http-more-examples.yml
Expand Up @@ -44,7 +44,7 @@
subscription.response.payload = 'dynamically changed payload'
assertions:
- name: Payload
expect: JSON.parse(message.body).enqueuer
expect: JSON.parse(body).enqueuer
toBeEqualTo: `virgs`
- name: Params
expect: params.firstId
Expand Down Expand Up @@ -100,7 +100,7 @@
onMessageReceived:
assertions:
- name: Payload
expectToBeTruthy: JSON.parse(message.body).duplicated
expectToBeTruthy: JSON.parse(body).duplicated
- name: requisition 2 (port 23076)
timeout: 5000
subscriptions:
Expand All @@ -119,3 +119,16 @@
port: 23076
timeout: 1000
avoid: true
- publishers:
- type: http
url: http://localhost:23080/number-payload
method: POST
payload: virgs
subscriptions:
- type: http
endpoint: /number-payload
port: 23080
method: POST
response:
status: 444
payload: 4.45
5 changes: 2 additions & 3 deletions examples/https.yml
@@ -1,7 +1,6 @@
timeout: 3000
publishers:
- name: publisher description
type: HTTPS
- type: HTTPS
url: https://localhost:4430/enqueuer
method: POST
payload:
Expand Down Expand Up @@ -31,5 +30,5 @@ subscriptions:
onMessageReceived:
assertions:
- name: Https payload
expect: JSON.parse(message.body).https
expect: JSON.parse(body).https
toBeEqualTo: `works!`
2 changes: 1 addition & 1 deletion examples/readme-enqueuer-http-selftest.yml
Expand Up @@ -22,7 +22,7 @@ subscriptions:
payload: mock response
onMessageReceived:
assertions:
- expect: message.body
- expect: body
toContain: `enqueuer`
- name: failing test
ignore:
Expand Down
4 changes: 2 additions & 2 deletions examples/requisition-delay-iterations.yml
Expand Up @@ -14,6 +14,6 @@
toBeEqualTo: 10
- name: Elapsed time
expect: elapsedTime
toBeGreaterThanOrEqualTo: 3000
toBeGreaterThanOrEqualTo: 2950
- expect: new Date().getTime() - requisition.startTime.getTime()
toBeGreaterThanOrEqualTo: 3000
toBeGreaterThanOrEqualTo: 2950
2 changes: 1 addition & 1 deletion examples/udp.yml
Expand Up @@ -10,7 +10,7 @@
port: 23072
timeout: 1000
onMessageReceived:
script: payload = Buffer.from(message.payload);
script: payload = Buffer.from(payload);
assertions:
- name: Payload
expect: payload
Expand Down
10 changes: 7 additions & 3 deletions examples/uds.yml
@@ -1,5 +1,6 @@
- timeout: 3000
publishers:
timeout: 7000
requisitions:
- publishers:
- type: uds
path: /tmp/unix.sock
timeout: 2000
Expand All @@ -23,6 +24,8 @@
- name: Message received is enqueuer
expect: payload
toBeEqualTo: store.udsPayload
- expect: path
toBeEqualTo: `/tmp/unix.sock`
- publishers:
- type: uds
path: /tmp/unix2.sock
Expand All @@ -38,7 +41,8 @@
saveStream: udsSubStreamName
onMessageReceived:
assertions:
- expect: message.payload
- name: real error
expect: payload
toBeEqualTo: store.udsPayload
timeout: <<uds2Timeout>>
- publishers:
Expand Down
3 changes: 2 additions & 1 deletion misc/custom-protocol.js
Expand Up @@ -29,7 +29,8 @@ class Subscription {

this.server.on('message', (msg, remoteInfo) => {
this.server.close();
resolve({payload: msg, remoteInfo: remoteInfo});
this.subscription.executeHookEvent('onMessageReceived', {payload: msg, remoteInfo: remoteInfo});
resolve();
});
});
};
Expand Down

0 comments on commit 6c895b1

Please sign in to comment.