|
| 1 | +// Copyright 2026 The Flutter Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. |
| 4 | + |
| 5 | +import 'dart:convert'; |
| 6 | +import 'dart:io'; |
| 7 | + |
| 8 | +import 'package:devtools_shared/src/server/file_system.dart'; |
| 9 | +import 'package:test/test.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + group('IOPersistentProperties', () { |
| 13 | + late Directory tempDir; |
| 14 | + late IOPersistentProperties properties; |
| 15 | + const storeName = 'test_store'; |
| 16 | + |
| 17 | + setUp(() { |
| 18 | + tempDir = Directory.systemTemp.createTempSync('persistent_properties_test'); |
| 19 | + properties = IOPersistentProperties( |
| 20 | + storeName, |
| 21 | + documentDirPath: tempDir.path, |
| 22 | + ); |
| 23 | + }); |
| 24 | + |
| 25 | + tearDown(() { |
| 26 | + tempDir.deleteSync(recursive: true); |
| 27 | + }); |
| 28 | + |
| 29 | + test('remove persists changes to disk', () { |
| 30 | + properties['key1'] = 'value1'; |
| 31 | + properties['key2'] = 'value2'; |
| 32 | + |
| 33 | + final file = File('${tempDir.path}/$storeName'); |
| 34 | + expect(file.existsSync(), isTrue); |
| 35 | + |
| 36 | + var content = file.readAsStringSync(); |
| 37 | + var json = (jsonDecode(content) as Map).cast<String, Object>(); |
| 38 | + expect(json['key1'], 'value1'); |
| 39 | + expect(json['key2'], 'value2'); |
| 40 | + |
| 41 | + properties.remove('key1'); |
| 42 | + |
| 43 | + content = file.readAsStringSync(); |
| 44 | + json = (jsonDecode(content) as Map).cast<String, Object>(); |
| 45 | + expect(json.containsKey('key1'), isFalse); |
| 46 | + expect(json['key2'], 'value2'); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
0 commit comments