Mock HTTP responses with processed random data and a custom template
$ go get github.com/wolfmetr/mock-ass/cmd/mock-ass$ make run
or
$ ./mock-ass [-port=8000] to initialize session send POST request to http://localhost:8000/init
curl -X POST \
'http://localhost:8000/init/?content_type=application%2Fjson&session_ttl_min=13' \
-H 'content-type: text/plain' \
-d '{
"first_name": "{{ FirstName() }}",
"last_name": "{{ LastName() }}",
"full_name": "{{ FullName() }}",
"city": "{{ City() }}",
"country": "{{ FullCountry() }}",
"country2": "{{ TwoLetterCountry() }}",
"country3": "{{ ThreeLetterCountry() }}",
"isActive": {{ BooleanString() }},
"float": {{ Float(12) }},
"float2": {{ Float(10, 15) }},
"float3": {{ Float(10, 15, 2) }},
"float4": {{ Float(10, 15, 3) }},
"ip_v4": "{{ IPv4() }}",
"person": [
{% for x in Range(5) %}
{
"first_name": "{{ FirstNameChain(forloop.Counter0) }}",
"last_name": "{{ LastNameChain(forloop.Counter0) }}",
"full_name": "{{ FullNameChain(forloop.Counter0) }}",
"age": {{ Number(10, 100) }},
"email": "{{ Email() }}"
}{% if not forloop.Last %}, {% endif %}
{% endfor %}
]
}'
and get response like
{
"session": "ac8c81bf-75ae-42d4-90c1-de1523acddb7",
"url": "/session/?s=ac8c81bf-75ae-42d4-90c1-de1523acddb7"
}Then you can get your rendered template from GET http://localhost:8000/session/?s=ac8c81bf-75ae-42d4-90c1-de1523acddb7
Every request to http://localhost:8000/session/?s=... redirects request with 307 code to url like http://localhost:8000/session/?s=...&h=... where h is unique hash.
If you send GET request to http://localhost:8000/session/?s=...&h=... you'll get cached data, NOT random!
FirstName()— random male/female firstnameFirstNameChain(key int)FirstNameMale()— random male firstnameFirstNameMaleChain(key int)FirstNameFemale()— random female firstnameFirstNameFemaleChain(key int)LastName()— random lastnameLastNameChain(key int)FullName()— random male/female fullnameFullNameChain(key int)FullNameMale()— random male fullnameFullNameMaleChain(key int)FullNameFemale()— random female fullnameFullNameFemaleChain(key int)Email()— random emailEmailChain(key int)FullCountry()— random full country nameFullCountryChain(key int)TwoLetterCountry()— random two-letter country code (ISO 3166-1 alpha-2)TwoLetterCountryChain(key int)ThreeLetterCountry()— random three-letter country code (ISO 3166-1 alpha-3)ThreeLetterCountryChain(key int)City()— random city stringCityChain(key int)StateUsaCode()— random USA state code stringStateUsaCodeChain(key int)StateUsaName()— random USA state name stringStateUsaNameChain(key int)Number(max_num int)— random number from range 0 tomax_numNumber(min_num, max_num int)— random number from rangemin_numtomax_numNumberChain(key, [min_num,] max_num int)NumberString([min_num,] max_num int)— random number string (see Number)NumberStringChain(key, [min_num,] max_num int)Float([min_float,] max_float int)— random float from range 0(or min_float) tomax_floatFloatChain(key, [min_float,] max_float int)Decimal([min_float,] max_float int)— see FloatDecimalChain(key, [min_float,] max_float int)Boolean()— random booleanBooleanChain(key int)BooleanString()— random boolean stringBooleanStringChain(key int)Paragraph()— random 'lorem ipsum'-like textParagraphChain(key int)IPv4()— random IPv4 addressIPv4Chain(key int)Range(size int)— array from 1 tosize(including)
- hash — unique hash for request
- Tests
- Function
OneFromListfor return random item from args
- Vladimir Savvateev
- wolfmetrjob@gmail.com
- http://twitter.com/Wolfmetrs
The MIT License (MIT). Please see LICENSE for more information.