|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:file/memory.dart'; |
5 | 6 | import 'package:flutter_tools/src/base/config.dart';
|
6 | 7 | import 'package:flutter_tools/src/base/file_system.dart';
|
| 8 | +import 'package:flutter_tools/src/base/logger.dart'; |
7 | 9 |
|
8 | 10 | import '../src/common.dart';
|
9 | 11 |
|
10 | 12 | void main() {
|
11 | 13 | Config config;
|
12 |
| - Directory tempDir; |
| 14 | + MemoryFileSystem memoryFileSystem; |
13 | 15 |
|
14 | 16 | setUp(() {
|
15 |
| - tempDir = fs.systemTempDirectory.createTempSync('flutter_config_test.'); |
16 |
| - final File file = fs.file(fs.path.join(tempDir.path, '.settings')); |
| 17 | + memoryFileSystem = MemoryFileSystem(); |
| 18 | + final File file = memoryFileSystem.file('example'); |
17 | 19 | config = Config(file);
|
18 | 20 | });
|
| 21 | + test('Config get set value', () async { |
| 22 | + expect(config.getValue('foo'), null); |
| 23 | + config.setValue('foo', 'bar'); |
| 24 | + expect(config.getValue('foo'), 'bar'); |
| 25 | + expect(config.keys, contains('foo')); |
| 26 | + }); |
| 27 | + |
| 28 | + test('Config get set bool value', () async { |
| 29 | + expect(config.getValue('foo'), null); |
| 30 | + config.setValue('foo', true); |
| 31 | + expect(config.getValue('foo'), true); |
| 32 | + expect(config.keys, contains('foo')); |
| 33 | + }); |
19 | 34 |
|
20 |
| - tearDown(() { |
21 |
| - tryToDelete(tempDir); |
| 35 | + test('Config containsKey', () async { |
| 36 | + expect(config.containsKey('foo'), false); |
| 37 | + config.setValue('foo', 'bar'); |
| 38 | + expect(config.containsKey('foo'), true); |
22 | 39 | });
|
23 | 40 |
|
24 |
| - group('config', () { |
25 |
| - test('get set value', () async { |
26 |
| - expect(config.getValue('foo'), null); |
27 |
| - config.setValue('foo', 'bar'); |
28 |
| - expect(config.getValue('foo'), 'bar'); |
29 |
| - expect(config.keys, contains('foo')); |
30 |
| - }); |
31 |
| - |
32 |
| - test('get set bool value', () async { |
33 |
| - expect(config.getValue('foo'), null); |
34 |
| - config.setValue('foo', true); |
35 |
| - expect(config.getValue('foo'), true); |
36 |
| - expect(config.keys, contains('foo')); |
37 |
| - }); |
38 |
| - |
39 |
| - test('containsKey', () async { |
40 |
| - expect(config.containsKey('foo'), false); |
41 |
| - config.setValue('foo', 'bar'); |
42 |
| - expect(config.containsKey('foo'), true); |
43 |
| - }); |
44 |
| - |
45 |
| - test('removeValue', () async { |
46 |
| - expect(config.getValue('foo'), null); |
47 |
| - config.setValue('foo', 'bar'); |
48 |
| - expect(config.getValue('foo'), 'bar'); |
49 |
| - expect(config.keys, contains('foo')); |
50 |
| - config.removeValue('foo'); |
51 |
| - expect(config.getValue('foo'), null); |
52 |
| - expect(config.keys, isNot(contains('foo'))); |
53 |
| - }); |
| 41 | + test('Config removeValue', () async { |
| 42 | + expect(config.getValue('foo'), null); |
| 43 | + config.setValue('foo', 'bar'); |
| 44 | + expect(config.getValue('foo'), 'bar'); |
| 45 | + expect(config.keys, contains('foo')); |
| 46 | + config.removeValue('foo'); |
| 47 | + expect(config.getValue('foo'), null); |
| 48 | + expect(config.keys, isNot(contains('foo'))); |
| 49 | + }); |
| 50 | + |
| 51 | + test('Config parse error', () { |
| 52 | + final BufferLogger bufferLogger =BufferLogger(); |
| 53 | + final File file = memoryFileSystem.file('example') |
| 54 | + ..writeAsStringSync('{"hello":"bar'); |
| 55 | + config = Config(file, bufferLogger); |
| 56 | + |
| 57 | + expect(file.existsSync(), false); |
| 58 | + expect(bufferLogger.errorText, contains('Failed to decode preferences')); |
54 | 59 | });
|
55 | 60 | }
|
0 commit comments