oto/test/oto_application_test.dart

97 lines
2.1 KiB
Dart

import 'dart:io';
import 'package:oto/cli/commands/command_exe.dart';
import 'package:oto/oto/application.dart';
import 'package:test/test.dart';
void main() {
setUp(() {
Application.instance.property = {};
Application.instance.commandStates = {};
Application.instance.dataCommandMap = {};
});
test('build returns failure instead of exiting on invalid yaml', () async {
const invalidYaml = '''
property:
workspace: .
commands:
- command: Print
id: hello
param:
message: hi
pipeline:
id: main
workflow:
- exe: doesNotExist
''';
final result =
await Application.instance.build(BuildType.file, yamlContent: invalidYaml);
expect(result.success, isFalse);
expect(result.exitCode, 10);
expect(result.error, isNotNull);
});
test('file build returns success for print-only pipeline', () async {
const yaml = '''
property:
workspace: .
commands:
- command: Print
id: hello
param:
message: hi
pipeline:
id: main
workflow:
- exe: hello
''';
final result =
await Application.instance.build(BuildType.file, yamlContent: yaml);
expect(result.success, isTrue);
expect(result.exitCode, 0);
});
test('file build can run twice in same process', () async {
const yaml = '''
property:
workspace: .
commands:
- command: Print
id: hello
param:
message: hi
pipeline:
id: main
workflow:
- exe: hello
''';
final first =
await Application.instance.build(BuildType.file, yamlContent: yaml);
final second =
await Application.instance.build(BuildType.file, yamlContent: yaml);
expect(first.success, isTrue);
expect(second.success, isTrue);
});
test('CommandExe exe -f handles missing file without LateInitializationError',
() async {
final missing =
'/tmp/oto_missing_${DateTime.now().microsecondsSinceEpoch}.yaml';
expect(File(missing).existsSync(), isFalse);
final command = CommandExe();
final priorExitCode = exitCode;
try {
await command.execute(['-f', missing]);
} finally {
exitCode = priorExitCode;
}
});
}