Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bd7af99
Prueba de metodo para obtener todos los objetos que se han dado de alta.
crodriguezVector Mar 3, 2016
404419d
Añadir la ruta para que la reconozca como reservada
crodriguezVector Mar 3, 2016
00a0cf0
Cambio a GET en getAll
crodriguezVector Mar 3, 2016
cce224b
Añadir el README para que se puede conocer como usar el servidor
crodriguezVector Mar 3, 2016
06c7d91
Añadir un HOWTO para que se pueda buscar la info
crodriguezVector Mar 3, 2016
5738971
Corrección de cómo se accede al json del HOWTO
crodriguezVector Mar 3, 2016
447fba3
no message
crodriguezVector Mar 3, 2016
a297eb4
Cambiar el README
crodriguezVector Mar 3, 2016
5ca7474
Modificaciones del README
crodriguezVector Mar 3, 2016
ef7ef82
Modificaciones README
crodriguezVector Mar 3, 2016
cef6ad6
Again README
crodriguezVector Mar 3, 2016
bbf4d05
Prueba de Borrado individual
crodriguezVector Mar 4, 2016
84ebe53
Corrección del borrado
crodriguezVector Mar 4, 2016
512e94f
More
crodriguezVector Mar 4, 2016
9389894
Commit
crodriguezVector Mar 4, 2016
ab2f456
Añadir el verbo al 'add' para que controle si esta recibiendo la peti…
crodriguezVector Mar 6, 2016
663e2df
logs
crodriguezVector Mar 6, 2016
fe45b28
cambiar igualdad de verbo
crodriguezVector Mar 6, 2016
6dacb59
came on
crodriguezVector Mar 6, 2016
92a371b
Go, go, go
crodriguezVector Mar 6, 2016
1a01e10
Terminar el borrar un elemento
crodriguezVector Mar 6, 2016
5c5a8ce
logs
crodriguezVector Mar 6, 2016
3abbd48
fix delOne
crodriguezVector Mar 6, 2016
349e0df
f
crodriguezVector Mar 6, 2016
9ac7920
probando borrado
crodriguezVector Mar 6, 2016
7b2bed6
borrar logs innecesarios y finalizar el fixing del metodo "delOne"
crodriguezVector Mar 6, 2016
61f29ea
Comentar las nuevas opciones.
crodriguezVector Mar 6, 2016
78ce456
Comentarios de HOWTO
crodriguezVector Mar 6, 2016
8243c06
Probando el cambio del Howto a ruta fija
crodriguezVector Mar 10, 2016
6902e37
Quitar el 200 OK
crodriguezVector Mar 10, 2016
697d846
Meter los headers correctos.
crodriguezVector Mar 10, 2016
9774481
Meter un README2.html para que se muestre como tal.
crodriguezVector Mar 10, 2016
7d7c678
Eliminar la ruta al HowTo como un sample json
crodriguezVector Mar 10, 2016
f14b326
Delete personal data.
crodriguezVector Apr 6, 2016
0680960
Delete autorized for Flush
crodriguezVector Apr 6, 2016
76456cc
Delete some comments.
crodriguezVector Apr 6, 2016
f112d89
Delete unnecessary dependency
crodriguezVector Apr 6, 2016
d979048
Added tests for delOne and method matching
crodriguezVector Apr 7, 2016
9feccd6
Fix README.
crodriguezVector Apr 8, 2016
df12160
Update fakeresponse.js
cesinrm Apr 9, 2016
f29ebdc
Modifications:
crodriguezVector Apr 12, 2016
2e54d83
Update README.md
cesinrm May 16, 2016
95d021a
Update README.md
cesinrm May 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ note that I will be adding an 'at' parameter to configure the special behavior t
> responseBody: 'Thou shall not pass!',
> at: 3 }

##### Same endpoint with different verbs/method

Now, you can do a GET and POST at the same endpoint

> { route: 'login',
> responseCode: 200,
> responseBody: 'ok',
> verb: 'GET' }

> { route: 'login',
> responseCode: 200,
> responseBody: 'You are doing a POST',
> verb: 'POST' }


##### Delay response

Expand All @@ -138,10 +152,23 @@ The following will delay server response in one second:
> responseBody: 'OK',
> delay: 1000 }

##### Resetting server configuration

### Delete one petition

Sometimes, you want to remove an entry. So, now you can.

All you have to do is 'DELETE' to http://localhost:3012/delOne the following data:

Delete /test by deleting:
> { route: 'test',
> responseCode: 200,
> verb: "GET" }


#### Resetting server configuration

To avoid the need to restart fake-server in order to clear the configuration, we've implemented a special endpoint called `/flush`. By sending a `DELETE` request to http://localhost:3012/flush, you will erase all previously configured responses.


### Limitations
- There are two reserved endpoints: POST '/add' and `DELETE` '/flush'. These cannot be used by your application.
- There are reserved endpoints: POST '/add', GET '/getAll', DELETE '/delOne' and DELETE, '/flush'. These cannot be used by your application.
305 changes: 305 additions & 0 deletions README2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
#fake-server
<br />
<br />
[![Build
Status](https://travis-ci.org/yahoo/fake-server.svg)](https://travis-ci.org/yahoo/fake-server)
<br />
<br />
Fake-server is a generic and non-intrusive tool used to mock any server
response. It has been designed to address issues when running tests
against unstable or slow external servers.
<br />
<br />
===========
<br />
<br />
## How it works
<br />
<br />
The idea is to create a webserver listening in a different port and make
your tests bring it up and configure how it should behave against each
different request. "Configuration" can be done by posting the parameters
and desired response to the server, or through configuration files
inside ./default_routes/.
<br />
<br />
For every request, fake-server will try to match against the configured
URIs and return the expected response.
<br />
<br />
### Advantages
<br />
- No need to instrument your code (as long as the external server endpoint is configurable :P)<br />
- Generic enough to work with blackbox or whitebox tests.<br />
- No database required<br />
<br />
<br />
### Quickstart (two really basic scenarios)<br />
<br />
Clone this repository (npm package coming soon)<br />
> git clone git@github.com:yahoo/fake-server.git<br />
<br />
Start (it will start a server on port 3012)<br />
> node server.js<br />
<br />
<br />
Let's say you want "/test" to always return "hello" and
"/foo" to return a 404.
<br />
<br />
All you have to do is `POST` to http://localhost:3012/add/ the
following data:
<br />
<br />
Configure /test by posting:
<br />
> { route: '/test',
<br />
> responseCode: 200,
<br />
> responseBody: "hello" }
<br />
<br />
one of the many ways to do this is using cURL:
<br />
```
<br />
curl http://localhost:3012/add -X POST -H
"Content-Type:application/json" -H "Accept:application/json" \
<br />
-d
'{"route":"/test","responseCode":200,"responseBody":"hello"}'
<br />
```
<br />
<br />
now let's configure our 404 example by sending this to the server:
<br />
> { route: '/foo',
<br />
> responseCode: 404,
<br />
> responseBody: "Not found" }
<br />
<br />
using cURL:
<br />
```
<br />
curl http://localhost:3012/add -X POST -H
"Content-Type:application/json" -H "Accept:application/json" \
<br />
-d '{"route":"/foo","responseCode":404,"responseBody":"Not
found"}'
<br />
```
<br />
<br />
now, in your browser you can see the results:
<br />
http://localhost:3012/foo
<br />
http://localhost:3012/test
<br />
<br />
<br />
### What else can fake-server do?
<br />
<br />
Configuration is done by sending a POST request to /add or by placing a
json file containing configurations inside a "routes" object (see
default_routes/sample.json for reference). Here are the supported
features for this version:
<br />
<br />
##### Routes can be RegEx
<br />
<br />
This will match http://localhost:3012/news/007 as well
as http://localhost:3012/news/1231293871293827:
<br />
<br />
> { route: '/news/[0-9]'
<br />
> responseCode: 200,
<br />
> responseBody: 'whatever you want' }
<br />
<br />
##### Fake-server supports "POST" calls and uses payload for matching.
Regexs are supported for payload matching, and paths can be used to
specify inner properties of JSON payloads:
<br />
<br />
> { route: '/news'
<br />
> payload: {
<br />
> id: [\\d+],
<br />
> requests[1].user.login: 'jdoe',
<br />
> month: "february"
<br />
> },
<br />
> responseCode: 200,
<br />
> responseBody: 'yay! it matches'
<br />
> }
<br />
<br />
##### Support for query string matching. All query params are evaluated
as a RegEx.
<br />
<br />
> { route: '/news',
<br />
> queryParams: {
<br />
> id: "[\\d+]",
<br />
> location: "Hawaii"
<br />
> }
<br />
> responseCode: 200,
<br />
> responseBody: 'Regex matching rocks'
<br />
> }
<br />
<br />
##### ... can also use the request Headers. So you can check if specific
cookies are present, for instance
<br />
<br />
> { route: '/secure',
<br />
> requiredHeaders: {
<br />
> X-Auth: "secret",
<br />
> },
<br />
> responseCode: 200,
<br />
> responseBody: 'header is there'
<br />
> }
<br />
<br />
<br />
##### Response can be a file. In this case, fake-server will respond
with the output of that file.
<br />
<br />
The following configuration example will return the output of
./mock_data/sample.json *(notice the parameter is called responseData
instead of responseBody)*
<br />
<br />
Para esto, teneis que poneros en contacto conmigo --> crodriguez
<br />
<br />
> { route: '/',
<br />
> responseCode: 200,
<br />
> responseData: './mock_data/sample.json' }
<br />
<br />
##### Same endpoint with different verbs/method
<br />
<br />
Now, you can do a GET and POST at the same endpoint
<br />
<br />
> { route: '/login',
<br />
> responseCode: 200,
<br />
> responseBody: 'ok',
<br />
> verb: 'GET' }
<br />
<br />
> { route: '/login',
<br />
> responseCode: 200,
<br />
> responseBody: 'You are doing a POST',
<br />
> verb: 'POST' }
<br />
<br />
##### Same endpoint can have different responses
<br />
<br />
This will return '200' in the first two requests to '/' and
403 on the third request
<br />
<br />
> { route: '/',
<br />
> responseCode: 200,
<br />
> responseBody: 'ok' }
<br />
<br />
note that I will be adding an 'at' parameter to configure the special
behavior to the third request:
<br />
<br />
> { route: '/',
<br />
> responseCode: 403,
<br />
> responseBody: 'Thou shall not pass!',
<br />
> at: 3 }
<br />
<br />
<br />
##### Delay response
<br />
<br />
The following will delay server response in one second:
<br />
<br />
> { route: '/slow/.*',
<br />
> responseCode: 200,
<br />
> responseBody: 'OK',
<br />
> delay: 1000 }
<br />
<br />
## Delete one petition
<br />
<br />
Sometimes, you want to remove an entry. So, now you can.
<br />
<br />
All you have to do is 'DELETE' to http://localhost:3012/delOne the
following data:
<br />
<br />
Delete /test by deleting:
<br />
> { route: '/test',
<br />
> responseCode: 200,
<br />
> verb: "GET" }
<br />
<br />
<br />
<br />
### Limitations
<br />
- There are reserved endpoints: POST '/add', GET '/getAll', DELETE
'/delOne' and DELETE, '/flush'. These cannot be used by your application.
<br />
Loading