OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library shelf_static.get_handler_test; |
| 6 |
| 7 import 'dart:io'; |
| 8 import 'package:path/path.dart' as p; |
| 9 import 'package:scheduled_test/descriptor.dart' as d; |
| 10 import 'package:scheduled_test/scheduled_test.dart'; |
| 11 |
| 12 import 'package:shelf_static/shelf_static.dart'; |
| 13 |
| 14 void main() { |
| 15 setUp(() { |
| 16 var tempDir; |
| 17 schedule(() { |
| 18 return Directory.systemTemp.createTemp('shelf_static-test-').then((dir) { |
| 19 tempDir = dir; |
| 20 d.defaultRoot = tempDir.path; |
| 21 }); |
| 22 }); |
| 23 |
| 24 d.file('root.txt', 'root txt').create(); |
| 25 d |
| 26 .dir('files', [ |
| 27 d.file('test.txt', 'test txt content'), |
| 28 d.file('with space.txt', 'with space content') |
| 29 ]) |
| 30 .create(); |
| 31 |
| 32 currentSchedule.onComplete.schedule(() { |
| 33 d.defaultRoot = null; |
| 34 return tempDir.delete(recursive: true); |
| 35 }); |
| 36 }); |
| 37 |
| 38 test('non-existent relative path', () { |
| 39 schedule(() { |
| 40 expect(() => createStaticHandler('random/relative'), throwsArgumentError); |
| 41 }); |
| 42 }); |
| 43 |
| 44 test('existing relative path', () { |
| 45 schedule(() { |
| 46 var existingRelative = p.relative(d.defaultRoot); |
| 47 expect(() => createStaticHandler(existingRelative), returnsNormally); |
| 48 }); |
| 49 }); |
| 50 |
| 51 test('non-existent absolute path', () { |
| 52 schedule(() { |
| 53 var nonExistingAbsolute = p.join(d.defaultRoot, 'not_here'); |
| 54 expect( |
| 55 () => createStaticHandler(nonExistingAbsolute), throwsArgumentError); |
| 56 }); |
| 57 }); |
| 58 |
| 59 test('existing absolute path', () { |
| 60 schedule(() { |
| 61 expect(() => createStaticHandler(d.defaultRoot), returnsNormally); |
| 62 }); |
| 63 }); |
| 64 } |
OLD | NEW |