@@ -5,7 +5,7 @@ var webdav = require('../../lib/index.js'),
5
5
6
6
module . exports = ( test , options , index ) => test ( 'source' , ( isValid , server ) =>
7
7
{
8
- isValid = isValid . multiple ( 1 , server ) ;
8
+ isValid = isValid . multiple ( 2 , server ) ;
9
9
const _ = ( e , cb ) => {
10
10
if ( e )
11
11
isValid ( false , e ) ;
@@ -25,105 +25,111 @@ module.exports = (test, options, index) => test('source', (isValid, server) =>
25
25
26
26
const url = 'http://localhost:' + ( options . port + index )
27
27
28
- let processed = '<html><body>processed content</body></html>' ;
29
- let unprocessed = 'unprocessed content' ;
30
-
31
- server . rootResource . addChild ( {
32
- write ( targetSource , callback )
33
- {
34
- callback ( null , new stream . Writable ( {
35
- write : ( chunk , encoding , callback ) => {
36
- if ( targetSource )
37
- unprocessed = chunk ;
38
- else
39
- processed = chunk ;
40
-
41
- callback ( null ) ;
42
- }
43
- } ) ) ;
44
- } ,
45
- read ( targetSource , callback )
46
- {
47
- callback ( null , new stream . Readable ( {
48
- read : function ( size )
49
- {
50
- this . push ( targetSource ? unprocessed : processed ) ;
51
- this . push ( null ) ;
52
- }
53
- } ) ) ;
54
- } ,
55
- webName ( callback )
56
- {
57
- callback ( null , 'testFile.txt' ) ;
58
- } ,
59
- mimeType ( targetSource , callback )
60
- {
61
- callback ( null , targetSource ? 'text/plain' : 'text/html' ) ;
62
- } ,
63
- size ( targetSource , callback )
64
- {
65
- callback ( null , targetSource ? unprocessed . length : processed . length ) ;
66
- } ,
67
- getLocks ( callback )
68
- {
69
- callback ( null , [ ] ) ;
70
- } ,
71
- type ( callback )
72
- {
73
- callback ( null , webdav . ResourceType . File ) ;
74
- }
75
- } , ( e ) => _ ( e , ( ) => {
76
- request ( {
77
- url : url + '/testFile.txt' ,
78
- method : 'GET' ,
79
- headers : {
28
+ test ( 'source' ) ;
29
+ test ( 'translate' ) ;
30
+
31
+ function test ( headerName )
32
+ {
33
+ let processed = '<html><body>processed content</body></html>' ;
34
+ let unprocessed = 'unprocessed content' ;
35
+
36
+ server . rootResource . addChild ( {
37
+ write ( targetSource , callback )
38
+ {
39
+ callback ( null , new stream . Writable ( {
40
+ write : ( chunk , encoding , callback ) => {
41
+ if ( targetSource )
42
+ unprocessed = chunk ;
43
+ else
44
+ processed = chunk ;
45
+
46
+ callback ( null ) ;
47
+ }
48
+ } ) ) ;
49
+ } ,
50
+ read ( targetSource , callback )
51
+ {
52
+ callback ( null , new stream . Readable ( {
53
+ read : function ( size )
54
+ {
55
+ this . push ( targetSource ? unprocessed : processed ) ;
56
+ this . push ( null ) ;
57
+ }
58
+ } ) ) ;
59
+ } ,
60
+ webName ( callback )
61
+ {
62
+ callback ( null , 'testFile.txt' ) ;
63
+ } ,
64
+ mimeType ( targetSource , callback )
65
+ {
66
+ callback ( null , targetSource ? 'text/plain' : 'text/html' ) ;
67
+ } ,
68
+ size ( targetSource , callback )
69
+ {
70
+ callback ( null , targetSource ? unprocessed . length : processed . length ) ;
71
+ } ,
72
+ getLocks ( callback )
73
+ {
74
+ callback ( null , [ ] ) ;
75
+ } ,
76
+ type ( callback )
77
+ {
78
+ callback ( null , webdav . ResourceType . File ) ;
80
79
}
81
- } , expect ( processed , ( ) => {
80
+ } , ( e ) => _ ( e , ( ) => {
82
81
request ( {
83
82
url : url + '/testFile.txt' ,
84
83
method : 'GET' ,
85
84
headers : {
86
- source : 'T'
87
- }
88
- } , expect ( unprocessed , ( ) => {
89
- const old = {
90
- processed,
91
- unprocessed
92
85
}
86
+ } , expect ( processed , ( ) => {
93
87
request ( {
94
88
url : url + '/testFile.txt' ,
95
- method : 'PUT ' ,
89
+ method : 'GET ' ,
96
90
headers : {
97
- } ,
98
- body : processed + 'addon'
99
- } , ( e , res , body ) => _ ( e , ( ) => {
91
+ [ headerName ] : 'T'
92
+ }
93
+ } , expect ( unprocessed , ( ) => {
94
+ const old = {
95
+ processed,
96
+ unprocessed
97
+ }
100
98
request ( {
101
99
url : url + '/testFile.txt' ,
102
100
method : 'PUT' ,
103
101
headers : {
104
- source : 'T'
105
102
} ,
106
- body : unprocessed + 'addonX '
103
+ body : processed + 'addon '
107
104
} , ( e , res , body ) => _ ( e , ( ) => {
108
105
request ( {
109
106
url : url + '/testFile.txt' ,
110
- method : 'GET ' ,
107
+ method : 'PUT ' ,
111
108
headers : {
112
- }
113
- } , expect ( old . processed + 'addon' , ( ) => {
109
+ [ headerName ] : 'T'
110
+ } ,
111
+ body : unprocessed + 'addonX'
112
+ } , ( e , res , body ) => _ ( e , ( ) => {
114
113
request ( {
115
114
url : url + '/testFile.txt' ,
116
115
method : 'GET' ,
117
116
headers : {
118
- source : 'T'
119
117
}
120
- } , expect ( old . unprocessed + 'addonX' , ( ) => {
121
- isValid ( true ) ;
118
+ } , expect ( old . processed + 'addon' , ( ) => {
119
+ request ( {
120
+ url : url + '/testFile.txt' ,
121
+ method : 'GET' ,
122
+ headers : {
123
+ [ headerName ] : 'T'
124
+ }
125
+ } , expect ( old . unprocessed + 'addonX' , ( ) => {
126
+ isValid ( true ) ;
127
+ } ) )
122
128
} ) )
123
129
} ) )
124
130
} ) )
125
131
} ) )
126
132
} ) )
127
133
} ) )
128
- } ) )
134
+ }
129
135
} )
0 commit comments