(endpoint, filePath, options, contentType, done)
| 141 | }; |
| 142 | |
| 143 | function testsWithOptions(endpoint, filePath, options, contentType, done) { |
| 144 | var ENDPOINT = endpoint; |
| 145 | var fileSuffixPath = filePath; |
| 146 | var requestPath = path.join(ENDPOINT, fileSuffixPath); |
| 147 | var fileOnDisk = path.join(STATIC_FILES_PATH, fileSuffixPath); |
| 148 | if (fileSuffixPath.endsWith('/')) { |
| 149 | fileOnDisk = path.join(fileOnDisk, 'index.html'); |
| 150 | } |
| 151 | var fileContent = fs.readFileSync(fileOnDisk, 'utf8'); |
| 152 | var fileStat = fs.statSync(fileOnDisk); |
| 153 | SERVER.get( |
| 154 | ENDPOINT + '/*', |
| 155 | restify.plugins.serveStaticFiles( |
| 156 | path.resolve(STATIC_FILES_PATH), |
| 157 | options |
| 158 | ) |
| 159 | ); |
| 160 | |
| 161 | CLIENT.get(encodeURI(requestPath), function(err, req, res, obj) { |
| 162 | assert.ifError(err); |
| 163 | assert.equal(fileContent, obj); |
| 164 | // Verify headers |
| 165 | assert.equal(res.headers['cache-control'], 'public, max-age=3600'); |
| 166 | assert.equal( |
| 167 | res.headers['content-type'], |
| 168 | contentType //'text/html; charset=UTF-8' |
| 169 | ); |
| 170 | assert.notExists(res.headers.etag); |
| 171 | assert.equal( |
| 172 | res.headers['last-modified'], |
| 173 | fileStat.mtime.toUTCString() |
| 174 | ); |
| 175 | assert.equal(res.headers['restify-plugin-x'], 'awesome'); |
| 176 | done(); |
| 177 | }); |
| 178 | } |
| 179 | |
| 180 | it('serve static file', function(done) { |
| 181 | testsWithOptions( |
no test coverage detected