Skip to content

Commit fcbd3f5

Browse files
author
Eric Redmond
committed
kick off fsm testing
1 parent d37d8ad commit fcbd3f5

File tree

5 files changed

+990
-10
lines changed

5 files changed

+990
-10
lines changed

lib/flow.iced

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Flow
8484
null
8585

8686
variances: (req, res)->
87-
accept = if @resource.content_types_provided(req, res).length > 1 then ["Accept"] else []
87+
accept = if @resource.content_types_provided_sync(req, res).length > 1 then ["Accept"] else []
8888
accept_encoding = if @resource.encodings_provided_sync(req, res).length > 1 then ["Accept-Encoding"] else []
8989
accept_charset = if @resource.charsets_provided_sync(req, res).length > 1 then ["Accept-Charset"] else []
9090
_.union(accept, accept_encoding, accept_charset, @resource.variances_sync(req, res))
@@ -113,7 +113,7 @@ class Flow
113113
v3b12: (req, res) ->
114114
@decision_test(
115115
(req, res, next) =>
116-
next(_.contains(@resource.known_methods, req.method))
116+
next(_.contains(@resource.known_methods_sync(req, res), req.method))
117117
, req, res, true, 'v3b11', 501)
118118

119119
# "URI too long?"
@@ -195,8 +195,8 @@ class Flow
195195
@decision_test(
196196
(req, res, next)=>
197197
unless accept = @get_header_val(req, 'accept')
198-
# TODO: = MediaType.parse(@resource.content_types_provided()[0][0])
199-
@metadata['Content-Type'] = _.first(_.keys(@resource.content_types_provided()))
198+
# TODO: = MediaType.parse(@resource.content_types_provided_sync()[0][0])
199+
@metadata['Content-Type'] = _.first(_.keys(@resource.content_types_provided_sync()))
200200
next('v3d4')
201201
else
202202
next('v3c4')
@@ -206,7 +206,7 @@ class Flow
206206
v3c4: (req, res) ->
207207
@decision_test(
208208
(req, res, next)=>
209-
types = _.keys(@resource.content_types_provided())
209+
types = _.keys(@resource.content_types_provided_sync())
210210
chosen_type = @choose_media_type(types, @get_header_val(req, 'accept'))
211211
unless chosen_type
212212
next(406)
@@ -516,7 +516,7 @@ class Flow
516516
res.header["Expires"] = new Date(expires) if expires
517517
# httpd_util:rfc1123_date(calendar:universal_time_to_local_time(Exp))})
518518

519-
@resource.content_types_provided req, res, (content_types_provided) =>
519+
@resource.content_types_provided_sync req, res, (content_types_provided) =>
520520

521521
content_types = _.pairs(content_types_provided)
522522
content_type = @metadata['Content-Type']
@@ -566,7 +566,7 @@ class Flow
566566
# {MT, MParams} = webmachine_util:media_type_to_detail(CT),
567567
# wrcall({set_metadata, 'mediaparams', MParams}),
568568
# case [Fun || {Type,Fun} <-
569-
# resource_call(content_types_accepted), MT =:= Type] of
569+
# resource_call(content_types_accepted_sync), MT =:= Type] of
570570
# [] -> {respond,415};
571571
# AcceptedContentList ->
572572
# F = hd(AcceptedContentList),

lib/webmachine.iced

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class Webmachine
3333

3434
# TODO: wrap resource inside a Resource
3535
resource.authorization = {}
36-
resource.known_methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT', 'OPTIONS']
36+
resource.known_methods_sync ||= (req, res) -> ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'TRACE', 'CONNECT', 'OPTIONS']
3737
resource.allowed_methods_sync ||= (req, res) -> ['GET', 'HEAD']
3838
resource.charsets_provided_sync ||= (req, res) -> {"iso-8859-1" : (x) -> x}
3939
resource.encodings_provided_sync ||= (req, res) -> {"identity" : (x) -> x}
40+
resource.content_types_provided_sync ||= (req, res) -> {"text/html" : 'to_html'}
41+
resource.content_types_accepted_sync ||= (req, res) -> []
4042

4143
# TODO: change these to syncs?
42-
resource.content_types_provided ||= (req, res) -> {"text/html" : 'to_html'}
43-
resource.content_types_accepted ||= (req, res) -> []
4444
resource.options ||= (req, res) -> []
4545
resource.forbidden ||= (req, res, next) -> next(false)
4646

test/fsm-test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var vows = require('vows'),
2+
assert = require('assert'),
3+
net = require('net'),
4+
http = require('http'),
5+
url = require('url'),
6+
scenarios = require("./scenarios.js"),
7+
iced = require('iced-coffee-script'),
8+
ResData = require('../lib/response_data'),
9+
ReqData = require('../lib/request_data'),
10+
FSM = require('../lib/fsm'),
11+
wm = require('../lib/webmachine');
12+
13+
var port = 9000;
14+
var baseUrl = '127.0.0.1';
15+
16+
tests = {};
17+
18+
test = scenarios[0];
19+
20+
tests[test.name] = {
21+
topic: function () {
22+
var self = this;
23+
24+
mockNodeReq = {
25+
method: test.method
26+
};
27+
mockNodeRes = {
28+
end: function(){
29+
console.log('done');
30+
}
31+
};
32+
mockResource = {
33+
route: "/",
34+
service_available: function(req, res, next) {
35+
self.callback(undefined, req, res, next);
36+
}
37+
};
38+
39+
req = new ReqData(mockNodeReq, url.parse('/', true), {});
40+
res = new ResData(mockNodeRes);
41+
fsm = new FSM(mockResource, req, res);
42+
fsm.run();
43+
44+
// self.callback(undefined, req, res, function(reply){});
45+
},
46+
'and result is correct': function (err, req, res, next) {
47+
// assert.notEqual(err, 'timeout');
48+
assert.notEqual(next, undefined, 'next is required');
49+
assert.notEqual(res, undefined, 'res is required');
50+
assert.notEqual(req, undefined, 'req is required');
51+
next(false);
52+
assert.equal(res.statusCode(), test.checkStatus);
53+
}
54+
}
55+
56+
vows.describe('FSM').addBatch(tests).export(module);

0 commit comments

Comments
 (0)