health.dart 1.63 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// 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
  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 17

  @override
  final String kind = 'get_health';
18 19
}

20
/// A description of application state.
21 22 23 24 25 26 27 28
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,
}

29 30 31
final EnumIndex<HealthStatus> _healthStatusIndex =
    new EnumIndex<HealthStatus>(HealthStatus.values);

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

39 40 41
  /// The status represented by this object.
  ///
  /// If the application responded, this will be [HealthStatus.ok].
42 43
  final HealthStatus status;

44 45 46 47 48
  /// Deserializes the result from JSON.
  static Health fromJson(Map<String, dynamic> json) {
    return new Health(_healthStatusIndex.lookupBySimpleName(json['status']));
  }

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