|
| 1 | +// Copyright 2014 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:conductor/proto/conductor_state.pb.dart' as pb; |
| 6 | +import 'package:conductor/state.dart'; |
| 7 | +import 'package:file/file.dart'; |
| 8 | +import 'package:file/memory.dart'; |
| 9 | + |
| 10 | +import './common.dart'; |
| 11 | + |
| 12 | +void main() { |
| 13 | + test('writeStateToFile() pretty-prints JSON with 2 spaces', () { |
| 14 | + final MemoryFileSystem fileSystem = MemoryFileSystem.test(); |
| 15 | + final File stateFile = fileSystem.file('/path/to/statefile.json') |
| 16 | + ..createSync(recursive: true); |
| 17 | + const String candidateBranch = 'flutter-2.3-candidate.0'; |
| 18 | + final pb.ConductorState state = pb.ConductorState( |
| 19 | + releaseChannel: 'stable', |
| 20 | + releaseVersion: '2.3.4', |
| 21 | + incrementLevel: 'z', |
| 22 | + engine: pb.Repository( |
| 23 | + candidateBranch: candidateBranch, |
| 24 | + upstream: pb.Remote( |
| 25 | + name: 'upstream', |
| 26 | + url: 'https://github.com/flutter/engine.git', |
| 27 | + ), |
| 28 | + ), |
| 29 | + framework: pb.Repository( |
| 30 | + candidateBranch: candidateBranch, |
| 31 | + upstream: pb.Remote( |
| 32 | + name: 'upstream', |
| 33 | + url: 'https://github.com/flutter/flutter.git', |
| 34 | + ), |
| 35 | + ), |
| 36 | + ); |
| 37 | + writeStateToFile( |
| 38 | + stateFile, |
| 39 | + state, |
| 40 | + <String>['[status] hello world'], |
| 41 | + ); |
| 42 | + final String serializedState = stateFile.readAsStringSync(); |
| 43 | + const String expectedString = ''' |
| 44 | +{ |
| 45 | + "releaseChannel": "stable", |
| 46 | + "releaseVersion": "2.3.4", |
| 47 | + "engine": { |
| 48 | + "candidateBranch": "flutter-2.3-candidate.0", |
| 49 | + "upstream": { |
| 50 | + "name": "upstream", |
| 51 | + "url": "https://github.com/flutter/engine.git" |
| 52 | + } |
| 53 | + }, |
| 54 | + "framework": { |
| 55 | + "candidateBranch": "flutter-2.3-candidate.0", |
| 56 | + "upstream": { |
| 57 | + "name": "upstream", |
| 58 | + "url": "https://github.com/flutter/flutter.git" |
| 59 | + } |
| 60 | + }, |
| 61 | + "logs": [ |
| 62 | + "[status] hello world" |
| 63 | + ], |
| 64 | + "incrementLevel": "z" |
| 65 | +}'''; |
| 66 | + expect(serializedState, expectedString); |
| 67 | + }); |
| 68 | +} |
0 commit comments