health.dart 1.7 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'enum_util.dart';
6 7
import 'message.dart';

8
/// A Flutter Driver command that requests an application health check.
9
class GetHealth extends Command {
10
  /// Create a health check command.
11
  const GetHealth({ Duration? timeout }) : super(timeout: timeout);
12

13
  /// Deserializes this command from the value generated by [serialize].
14
  GetHealth.deserialize(Map<String, String> json) : super.deserialize(json);
15 16

  @override
17
  String get kind => 'get_health';
18 19 20

  @override
  bool get requiresRootWidgetAttached => false;
21 22
}

23
/// A description of application state.
24 25 26 27 28 29 30 31
enum HealthStatus {
  /// Application is known to be in a good shape and should be able to respond.
  ok,

  /// Application is not known to be in a good shape and may be unresponsive.
  bad,
}

32
final EnumIndex<HealthStatus> _healthStatusIndex =
33
    EnumIndex<HealthStatus>(HealthStatus.values);
34

35 36
/// A description of the application state, as provided in response to a
/// [FlutterDriver.checkHealth] test.
37
class Health extends Result {
38
  /// Creates a [Health] object with the given [status].
39
  const Health(this.status)
40
    : assert(status != null);
41

42 43 44
  /// The status represented by this object.
  ///
  /// If the application responded, this will be [HealthStatus.ok].
45 46
  final HealthStatus status;

47 48
  /// Deserializes the result from JSON.
  static Health fromJson(Map<String, dynamic> json) {
49
    return Health(_healthStatusIndex.lookupBySimpleName(json['status'] as String));
50 51
  }

52
  @override
pq's avatar
pq committed
53
  Map<String, dynamic> toJson() => <String, dynamic>{
54
    'status': _healthStatusIndex.toSimpleName(status),
55 56
  };
}