manifest_test.dart 5.22 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 6
import 'dart:io';

7 8 9 10 11 12 13
import 'package:test/test.dart';

import 'package:flutter_devicelab/framework/manifest.dart';

void main() {
  group('production manifest', () {
    test('must be valid', () {
14
      final Manifest manifest = loadTaskManifest();
15 16
      expect(manifest.tasks, isNotEmpty);

17
      final ManifestTask task = manifest.tasks.firstWhere((ManifestTask task) => task.name == 'flutter_gallery__start_up');
18 19
      expect(task.description, 'Measures the startup time of the Flutter Gallery app on Android.\n');
      expect(task.stage, 'devicelab');
20
      expect(task.requiredAgentCapabilities, <String>['linux/android']);
21 22 23 24 25 26

      for (ManifestTask task in manifest.tasks) {
        final File taskFile = new File('bin/tasks/${task.name}.dart');
        expect(taskFile.existsSync(), true,
          reason: 'File ${taskFile.path} corresponding to manifest task "${task.name}" not found');
      }
27 28 29 30 31 32 33 34 35 36 37 38
    });
  });

  group('manifest parser', () {
    void testManifestError(
      String testDescription,
      String errorMessage,
      String yaml,
    ) {
      test(testDescription, () {
        try {
          loadTaskManifest(yaml);
39
        } on ManifestError catch (error) {
40 41 42 43 44
          expect(error.message, errorMessage);
        }
      });
    }

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    test('accepts task with minimum amount of configuration', () {
      final Manifest manifest = loadTaskManifest('''
tasks:
  minimum_configuration_task:
    description: Description is mandatory.
    stage: stage_is_mandatory_too
    required_agent_capabilities: ["so-is-capability"]
''');

      expect(manifest.tasks.single.description, 'Description is mandatory.');
      expect(manifest.tasks.single.stage, 'stage_is_mandatory_too');
      expect(manifest.tasks.single.requiredAgentCapabilities, <String>['so-is-capability']);
      expect(manifest.tasks.single.isFlaky, false);
      expect(manifest.tasks.single.timeoutInMinutes, null);
    });

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    testManifestError(
      'invalid top-level type',
      'Manifest must be a dictionary but was YamlScalar: null',
      '',
    );

    testManifestError(
      'invalid top-level key',
      'Unrecognized property "bad" in manifest. Allowed properties: tasks',
      '''
      bad:
        key: yes
      ''',
    );

    testManifestError(
      'invalid tasks list type',
      'Value of "tasks" must be a dictionary but was YamlList: [a, b]',
      '''
      tasks:
        - a
        - b
      '''
    );

    testManifestError(
      'invalid task name type',
      'Task name must be a string but was int: 1',
      '''
      tasks:
        1: 2
      '''
    );

    testManifestError(
      'invalid task type',
      'Value of task "foo" must be a dictionary but was int: 2',
      '''
      tasks:
        foo: 2
      '''
    );

    testManifestError(
      'invalid task property',
106
      'Unrecognized property "bar" in Value of task "foo". Allowed properties: description, stage, required_agent_capabilities, flaky, timeout_in_minutes',
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
      '''
      tasks:
        foo:
          bar: 2
      '''
    );

    testManifestError(
      'invalid required_agent_capabilities type',
      'required_agent_capabilities must be a list but was int: 1',
      '''
      tasks:
        foo:
          required_agent_capabilities: 1
      '''
    );

    testManifestError(
      'invalid required_agent_capabilities element type',
      'required_agent_capabilities[0] must be a string but was int: 1',
      '''
      tasks:
        foo:
          required_agent_capabilities: [1]
      '''
    );

    testManifestError(
      'missing description',
      'Task description must not be empty in task "foo".',
      '''
      tasks:
        foo:
          required_agent_capabilities: ["a"]
      '''
    );

    testManifestError(
      'missing stage',
      'Task stage must not be empty in task "foo".',
      '''
      tasks:
        foo:
          description: b
          required_agent_capabilities: ["a"]
      '''
    );

    testManifestError(
156
      'missing required_agent_capabilities',
157 158 159 160 161 162 163 164 165
      'requiredAgentCapabilities must not be empty in task "foo".',
      '''
      tasks:
        foo:
          description: b
          stage: c
          required_agent_capabilities: []
      '''
    );
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

    testManifestError(
      'bad flaky type',
      'flaky must be a boolean but was String: not-a-boolean',
      '''
      tasks:
        foo:
          description: b
          stage: c
          required_agent_capabilities: ["a"]
          flaky: not-a-boolean
      '''
    );

    test('accepts boolean flaky option', () {
      final Manifest manifest = loadTaskManifest('''
tasks:
  flaky_task:
    description: d
    stage: s
    required_agent_capabilities: ["c"]
    flaky: true
''');

      expect(manifest.tasks.single.name, 'flaky_task');
      expect(manifest.tasks.single.isFlaky, isTrue);
    });

    test('accepts custom timeout_in_minutes option', () {
      final Manifest manifest = loadTaskManifest('''
tasks:
  task_with_custom_timeout:
    description: d
    stage: s
    required_agent_capabilities: ["c"]
    timeout_in_minutes: 120
''');

      expect(manifest.tasks.single.timeoutInMinutes, 120);
    });
206 207
  });
}