Weitere ähnliche Inhalte Ähnlich wie Mock Servers - Fake All the Things! (20) Kürzlich hochgeladen (20) Mock Servers - Fake All the Things!1. PEGGY • SENIOR DEVELOPER • ATLASSIAN • @PYKO
Mock servers
Fake all the things!
19. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Isolation
21. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Faster dev loop
23. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Better testing
34. // Assume all requests are successful
app.post('/rest/billing/1/product/*',
function(req, res) {
res.type('application/json');
res.status(202).send();
});
35. // Assume all requests are successful
app.post('/rest/billing/1/product/*',
function(req, res) {
res.type('application/json');
res.status(202).send();
});
36. // Assume all requests are successful
app.post('/rest/billing/1/product/*',
function(req, res) {
res.type('application/json');
res.status(202).send();
});
37. // Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
38. // Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
39. // Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
GET /rest/billing/1/instance/pricing
40. GET /rest/billing/1/instance/pricing
// Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
41. get /rest/billing/1/instance/pricing
// Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
42. path = 'instance/pricing-get.json'get instance/pricing
// Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
43. // Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
require('./instance/pricing-get.json');
55. // Mock out the APIs.
// Directory path reflects the REST path.
app.all('/rest/billing/1/*', function(req, res) {
var method = req.method.toLowerCase();
var path = req.path.replace('/rest/billing/1/', '') +
'-' + method + '.json';
res.send(require('./' + path));
});
56. app.post('/rest/billing/1/*', function (req, res) {
validatePostData(req);
res.send(getJsonFileForRequest(req, 'post'));
});
app.get('/rest/billing/1/*', function (req, res) {
res.send(getJsonFileForRequest(req, 'get'));
});
57. app.post('/rest/billing/1/*', function (req, res) {
validatePostData(req);
res.send(getJsonFileForRequest(req, 'post'));
});
app.get('/rest/billing/1/*', function (req, res) {
res.send(getJsonFileForRequest(req, 'get'));
});
58. app.post('/rest/billing/1/*', function (req, res) {
validatePostData(req);
res.send(getJsonFileForRequest(req, 'post'));
});
app.get('/rest/billing/1/*', function (req, res) {
res.send(getJsonFileForRequest(req, 'get'));
});
66. function getJsonFilePath(path, suffix, ignoreState) {
var basePath = '/' + path.replace('/rest/billing/1/', '');
var filePath;
if (app.state && !ignoreState) {
basePath = '/states/' + app.state + basePath;
}
filePath = __dirname + basePath + '-' + suffix + '.json';
return filePath;
}
app.state = 'all-the-products'
67. function getJsonFilePath(path, suffix, ignoreState) {
var basePath = '/' + path.replace('/rest/billing/1/', '');
var filePath;
if (app.state && !ignoreState) {
basePath = '/states/' + app.state + basePath;
}
filePath = __dirname + basePath + '-' + suffix + '.json';
return filePath;
}
app.state = 'all-the-products'
79. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys":
["jira-core.ondemand",
"jira-software.ondemand"
"jira-servicedesk.ondemand"]
}
}
},
80. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys":
["jira-core.ondemand",
"jira-software.ondemand"
"jira-servicedesk.ondemand"]
}
}
},
81. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys":
["jira-core.ondemand",
"jira-software.ondemand",
"jira-servicedesk.ondemand"]
}
}
},
83. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira-software.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys": ["jira-software.ondemand"]
}
}
}
84. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira-software.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys": ["jira-software.ondemand"]
}
}
}
85. {
"interactions": [
{
"request": {...},
"response": {...}
},
{
"request": {...},
"response": {...}
}
]
}
{
"request": {
"method": "POST",
"contentType": "application/json",
"body": {
"products": ["jira-software.ondemand"]
}
},
"response": {
"status": 200,
"body": {
"productKeys": ["jira-software.ondemand"]
}
}
}
86. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
88. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
89. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
109. "properties": {
"hostname": {
"type": "string"
},
"currentBillingPeriod": {
"$ref": "#/definitions/billingPeriod"
},
"nextBillingPeriod": {
"$ref": "#/definitions/billingPeriod"
},
"activeProducts": {
"type": "array",
110. "properties": {
"hostname": {
"type": "string"
},
"currentBillingPeriod": {
"$ref": "#/definitions/billingPeriod"
},
"nextBillingPeriod": {
"$ref": "#/definitions/billingPeriod"
},
"activeProducts": {
"type": "array",
126. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Isolation
127. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Faster dev loop
128. • Big cool statistic
• 2,56
9
• Add-Ons in Marketplace
Better testing