Skip to content

Commit 8445d82

Browse files
committed
Add test
1 parent ab5a82e commit 8445d82

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

app_dart/lib/src/model/appengine/agent.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Agent extends Model {
1919
this.agentId,
2020
this.healthCheckTimestamp,
2121
this.isHealthy,
22-
this.isHidden,
22+
this.isHidden = false,
2323
this.capabilities,
2424
this.healthDetails,
2525
this.authToken,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2019 The Chromium 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 'dart:convert';
6+
import 'dart:typed_data';
7+
8+
import 'package:cocoon_service/src/model/appengine/agent.dart';
9+
import 'package:cocoon_service/src/request_handlers/get_status.dart';
10+
import 'package:cocoon_service/src/request_handling/body.dart';
11+
import 'package:cocoon_service/src/service/build_status_provider.dart';
12+
import 'package:cocoon_service/src/service/datastore.dart';
13+
import 'package:test/test.dart';
14+
15+
import '../src/datastore/fake_cocoon_config.dart';
16+
import '../src/datastore/fake_datastore.dart';
17+
import '../src/service/fake_build_status_provider.dart';
18+
19+
void main() {
20+
group('GetStatus', () {
21+
FakeConfig config;
22+
FakeDatastoreDB db;
23+
FakeBuildStatusProvider buildStatusProvider;
24+
GetStatus handler;
25+
26+
Future<Map<String, dynamic>> decodeHandlerBody() async {
27+
final Body body = await handler.get();
28+
final List<Uint8List> bytes = await body.serialize().toList();
29+
final String decodedBody =
30+
utf8.decode(bytes.expand((Uint8List bytes) => bytes).toList());
31+
return json.decode(decodedBody);
32+
}
33+
34+
setUp(() {
35+
config = FakeConfig();
36+
buildStatusProvider =
37+
FakeBuildStatusProvider(commitStatuses: <CommitStatus>[]);
38+
db = FakeDatastoreDB();
39+
handler = GetStatus(
40+
config,
41+
datastoreProvider: () => DatastoreService(db: db),
42+
buildStatusProvider: buildStatusProvider,
43+
);
44+
});
45+
46+
test('no statuses or agents', () async {
47+
final Map<String, dynamic> result = await decodeHandlerBody();
48+
expect(result['Statuses'], isEmpty);
49+
expect(result['AgentStatuses'], isEmpty);
50+
});
51+
52+
test('reports agents', () async {
53+
final Agent linux1 = Agent(agentId: 'linux1');
54+
final Agent mac1 = Agent(agentId: 'mac1');
55+
final Agent linux100 = Agent(agentId: 'linux100');
56+
final Agent linux5 = Agent(agentId: 'linux5');
57+
final Agent windows1 = Agent(agentId: 'windows1', isHidden: true);
58+
59+
final List<Agent> reportedAgents = <Agent>[
60+
linux1,
61+
mac1,
62+
linux100,
63+
linux5,
64+
windows1,
65+
];
66+
67+
db.addOnQuery<Agent>((Iterable<Agent> agents) => reportedAgents);
68+
final Map<String, dynamic> result = await decodeHandlerBody();
69+
70+
expect(result['Statuses'], isEmpty);
71+
72+
final List<dynamic> expectedOrderedAgents = <dynamic>[
73+
linux1.toJson(),
74+
linux5.toJson(),
75+
linux100.toJson(),
76+
mac1.toJson(),
77+
];
78+
79+
expect(result['AgentStatuses'], equals(expectedOrderedAgents));
80+
});
81+
});
82+
}

0 commit comments

Comments
 (0)