blob: 103598601761ceb8693375a9e8f3c7dd02606275 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'sl4f_client.dart';
/// Result from each test step. Usually each step denotes a separate test case
/// but it depends on what `fuchsia.test.Suite#GetTests()` returns.
class TestStep {
/// Name of the step.
String name;
/// Outcome of running step (passed, failed, inconclusive).
String outcome;
/// Time taken by test to run.
int duration_ms; // ignore: non_constant_identifier_names
/// Path to log file.
String primary_log_path; // ignore: non_constant_identifier_names
/// Artifacts generated by a test step. The values can be string and numbers.
Map<String, dynamic> artifacts;
@override
String toString() {
return jsonEncode(this);
}
dynamic toJson() => {
'name': name,
'outcome': outcome,
'duration_ms': duration_ms,
'primary_log_path': primary_log_path,
'artifacts': jsonEncode(artifacts)
};
}
/// Result of a single test.
class TestResult {
/// Outcome of running this test ("passed" if every step passes else "failed").
String outcome;
/// Total time taken to run this test.
int duration_ms; // ignore: non_constant_identifier_names
/// Log path which contains all logs for this test.
String primary_log_path; // ignore: non_constant_identifier_names
/// Series of steps for this test.
List<TestStep> steps;
/// Test completed successfully.
bool successful_completion; // ignore: non_constant_identifier_names
@override
String toString() {
return jsonEncode(this);
}
dynamic toJson() => {
'outcome': outcome,
'duration_ms': duration_ms,
'primary_log_path': primary_log_path,
'steps': jsonEncode(steps)
};
}
class Test {
final Sl4f _sl4f;
Test([Sl4f sl4f]) : _sl4f = sl4f ?? Sl4f.fromEnvironment();
Future<TestResult> runTest(String test) async {
final Map<String, dynamic> response =
await _sl4f.request('test_facade.RunTest', {'test': test});
TestResult result = TestResult()
..outcome = response['outcome']
..duration_ms = response['duration_ms']
..primary_log_path = response['primary_log_path']
..successful_completion = response['successful_completion'];
if (response.containsKey('steps')) {
result.steps = <TestStep>[];
for (dynamic dynStep in response['steps']) {
TestStep step = TestStep()
..name = dynStep['name']
..outcome = dynStep['outcome']
..duration_ms = dynStep['duration_ms']
..primary_log_path = dynStep['primary_log_path']
..artifacts = dynStep['artifacts'];
result.steps.add(step);
}
}
return result;
}
}