Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
iss #13: sample config with parsers, stub server for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed May 16, 2016
1 parent 245e9dd commit e0d7776
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
73 changes: 72 additions & 1 deletion server/docs/sample-config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,78 @@ cheesecake.services: [
}
]
}

// body parser examples
{
name: body parser examples
endpoints: [

// available parser types:
// * text - all endpoint output
// * regexp - doing regexp on result (multiline mode), save first matching group
// * json - JSONPath (http://goessner.net/articles/JsonPath/)
// * xml - XPath

{
port: 52030
path: /text/simple
body_parsers: {
// parser key: { parser options }
simple_status: { type: text }
}
}

{
port: 52030
path: /text/formatted
body_parsers: {
version: {
type: regexp
regexp: "^version: ([\\d\\.]+) *$"
}
status: {
type: regexp
regexp: "^current status: (.*)$"
}
}
}

{
port: 52030
path: /json/simple
body_parsers: {
status: {
type: json
// JSONPath, some advanced syntax may not supported
// result should be JSON string or number
json_path: ".status"
}
major_version: {
type: json
regexp: ".version[0]"
}
}
}

{
port: 52030
path: /xml
body_parsers: {
mylib_type: {
type: xml
// XPath (relative to root node)
// result should be text node or attribute
xpath: "mylib/@type"
}
python_version: {
type: xml
// or absolute
xpath: "//versions/tornado"
}
}
}
]
}
// other services
{
name: myapp
Expand All @@ -66,7 +138,6 @@ cheesecake.services: [
path: /status
}
]

}
// ...
]
16 changes: 16 additions & 0 deletions server/etc/stub-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Stub server for testing

[Sample config](../../docs/sample-config.conf) used that stub.

### Requirements

* python 2.7
* [pip](http://pip.readthedocs.org/en/latest/installing.html) (python package tools)
* [zaglushka.py](https://github.com/maizy/zaglushka) (`pip install git+https://github.com/maizy/zaglushka.git`)

### Run

```
cd cheesecake/
zaglushka.py --ports=52030 --config=server/etc/stub-server/zaglushka.config
```
42 changes: 42 additions & 0 deletions server/etc/stub-server/zaglushka.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* see the config format description at:
* https://github.com/maizy/zaglushka/blob/master/examples/example.json
* */
{
"urls": [
{
"path": "/json/simple",
"response": {
"status": "ok",
"some_key": "..",
"version": [3, 2, 1]
},
"headers": {"Content-Type": "application/json"}
},

{
"path": "/json/wrong_format",
"response": "{\"status\" => \"oll wrang\"}",
"headers": {"Content-Type": "application/json"}
},

{
"path": "/text/simple",
"response": ":)",
"headers": {"Content-Type": "text/plain"}
},

{
"path": "/text/formatted",
"response": "\nversion: 7.7.7\ncurrent status: doing some work\nyear: 2016\n",
"headers": {"Content-Type": "text/plain"}
},

{
"path": "/xml",
"response": "<?xml version='1.0' encoding='utf-8'?>\n<versions><mylib type=\"production\">2.25.18</mylib><tornado>3.2.2</tornado><python>2.7.3</python></versions>",
"headers": {"Content-Type": "application/xml"}
}

]
}

0 comments on commit e0d7776

Please sign in to comment.