Skip to content

Commit 5822666

Browse files
committed
fix: add tests and ensure that the sub processes can be mocked out.
1 parent 7cda1cf commit 5822666

File tree

9 files changed

+1112
-569
lines changed

9 files changed

+1112
-569
lines changed

.github/workflows/code_quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
run: dart pub get
3737
- name: Validate formatting
3838
run: dart format ./ --set-exit-if-changed
39+
- name: Generate Mocks
40+
if: ${{ matrix.work_dir == 'openapi-generator' }}
41+
run: dart run build_runner build --delete-conflicting-outputs
3942
- name: Run analyzer
4043
run: dart analyze --fatal-warnings
4144
- name: Run tests

openapi-generator/lib/src/models/command.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import 'dart:io';
2+
3+
import 'package:openapi_generator/src/determine_flutter_project_status.dart';
4+
import 'package:openapi_generator/src/gen_on_spec_changes.dart';
15
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
26

37
/// Creates a representation of a cli request for Flutter or Dart.
@@ -29,3 +33,52 @@ class Command {
2933
arguments,
3034
);
3135
}
36+
37+
/// CommandRunner provides an abstraction layer to external functions / processes.
38+
class CommandRunner {
39+
const CommandRunner();
40+
41+
Future<ProcessResult> runCommand({
42+
required Command command,
43+
required String workingDirectory,
44+
}) async =>
45+
Process.run(
46+
command.executable,
47+
command.arguments,
48+
workingDirectory: workingDirectory,
49+
runInShell: Platform.isWindows,
50+
);
51+
52+
Future<List<String>> loadAnnotatedFile({required String path}) async {
53+
final f = File(path);
54+
return f.readAsLines();
55+
}
56+
57+
Future<void> writeAnnotatedFile(
58+
{required String path, required List<String> content}) async {
59+
final f = File(path);
60+
return f.writeAsStringSync(content.join('\n'), flush: true);
61+
}
62+
63+
Future<void> cacheSpecFile({
64+
required Map<String, dynamic> updatedSpec,
65+
required String cachedPath,
66+
}) async =>
67+
cacheSpec(outputLocation: cachedPath, spec: updatedSpec);
68+
69+
Future<Map<String, dynamic>> loadSpecFile(
70+
{required InputSpec specConfig, bool isCached = false}) async =>
71+
loadSpec(specConfig: specConfig);
72+
73+
Future<bool> isSpecFileDirty({
74+
required Map<String, dynamic> cachedSpec,
75+
required Map<String, dynamic> loadedSpec,
76+
}) async =>
77+
isSpecDirty(cachedSpec: cachedSpec, loadedSpec: loadedSpec);
78+
79+
Future<bool> checkForFlutterEnvironemt(
80+
{Wrapper? wrapper = Wrapper.none,
81+
String? providedPubspecPath}) async =>
82+
checkPubspecAndWrapperForFlutterSupport(
83+
wrapper: wrapper, providedPubspecPath: providedPubspecPath);
84+
}

0 commit comments

Comments
 (0)