Skip to content

Commit 3dd7054

Browse files
committed
fix: remove extra testing infra since it is no longer used, add additional configs, refactor function
1 parent feead33 commit 3dd7054

17 files changed

+158
-431
lines changed

.github/workflows/code_quality.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v3
28-
- name: Start Docker compose containers
29-
if: ${{ matrix.work_dir == 'openapi-generator' }}
30-
run: docker-compose -f "docker-compose.yaml" up -d --build
3128
- name: Setup Dart
3229
uses: dart-lang/setup-dart@v1.5.0
3330
with:
@@ -54,9 +51,6 @@ jobs:
5451
verbose: true
5552
flags: ${{ matrix.work_dir }}
5653
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
57-
- name: Stop Docker Container
58-
if: ${{ matrix.work_dir == 'openapi-generator' && always() }}
59-
run: docker-compose -f "docker-compose.yaml" down
6054

6155
build:
6256
name: Build example project 🛠️

openapi-generator/docker-compose.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

openapi-generator/test/builder_test.dart

Lines changed: 0 additions & 107 deletions
This file was deleted.

openapi-generator/test/generator_test.dart

Lines changed: 111 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:io';
22

33
import 'package:analyzer/dart/element/type.dart';
4-
import 'package:build_test/build_test.dart';
54
import 'package:logging/logging.dart';
65
import 'package:mockito/mockito.dart';
76
import 'package:openapi_generator/src/models/command.dart';
@@ -30,15 +29,8 @@ void main() {
3029
mockedArgs = MockGeneratorArguments();
3130
mockRunner = MockCommandRunner();
3231
mockedAnnotations = MockConstantReader();
33-
defaultAnnotations = (await resolveSource(
34-
File('$testSpecPath/next_gen_builder_test_config.dart')
35-
.readAsStringSync(),
36-
(resolver) async =>
37-
(await resolver.findLibraryByName('test_lib'))!))
38-
.getClass('TestClassConfig')!
39-
.metadata
40-
.map((e) => ConstantReader(e.computeConstantValue()!))
41-
.first;
32+
defaultAnnotations =
33+
await loadAnnoation('next_gen_builder_test_config.dart');
4234
realArguments = GeneratorArguments(annotations: defaultAnnotations);
4335
});
4436

@@ -117,16 +109,8 @@ void main() {
117109
test('flutter when wrapper is fvm', () async {
118110
final logs = <LogRecord>[];
119111
logger.onRecord.listen(logs.add);
120-
final annotations = (await resolveSource(
121-
File('$testSpecPath/next_gen_builder_fvm_test_config.dart')
122-
.readAsStringSync(),
123-
(resolver) async =>
124-
(await resolver.findLibraryByName('test_lib'))!))
125-
.getClass('TestClassConfig')!
126-
.metadata
127-
.map((e) => ConstantReader(e.computeConstantValue()!))
128-
.first;
129-
112+
final annotations =
113+
await loadAnnoation('next_gen_builder_fvm_test_config.dart');
130114
when(mockRunner.checkForFlutterEnvironemt(
131115
wrapper: argThat(
132116
TypeMatcher<Wrapper>()
@@ -145,15 +129,8 @@ void main() {
145129
test('flutter when wrapper is ./flutter', () async {
146130
final logs = <LogRecord>[];
147131
logger.onRecord.listen(logs.add);
148-
final annotations = (await resolveSource(
149-
File('$testSpecPath/next_gen_builder_flutterw_test_config.dart')
150-
.readAsStringSync(),
151-
(resolver) async =>
152-
(await resolver.findLibraryByName('test_lib'))!))
153-
.getClass('TestClassConfig')!
154-
.metadata
155-
.map((e) => ConstantReader(e.computeConstantValue()!))
156-
.first;
132+
final annotations =
133+
await loadAnnoation('next_gen_builder_flutterw_test_config.dart');
157134

158135
when(mockRunner.checkForFlutterEnvironemt(
159136
wrapper: argThat(
@@ -173,15 +150,8 @@ void main() {
173150
test('when defined in pubspec', () async {
174151
final logs = <LogRecord>[];
175152
logger.onRecord.listen(logs.add);
176-
final annotations = (await resolveSource(
177-
File('$testSpecPath/next_gen_builder_flutter_test_config.dart')
178-
.readAsStringSync(),
179-
(resolver) async =>
180-
(await resolver.findLibraryByName('test_lib'))!))
181-
.getClass('TestClassConfig')!
182-
.metadata
183-
.map((e) => ConstantReader(e.computeConstantValue()!))
184-
.first;
153+
final annotations =
154+
await loadAnnoation('next_gen_builder_flutter_test_config.dart');
185155

186156
when(
187157
mockRunner.checkForFlutterEnvironemt(
@@ -201,6 +171,109 @@ void main() {
201171
});
202172
});
203173

174+
group('uses correct generator', () {
175+
test('dart', () async {
176+
final logs = <LogRecord>[];
177+
logger.onRecord.listen(logs.add);
178+
179+
final annotations =
180+
await loadAnnoation('next_gen_builder_local_test_config.dart');
181+
182+
when(mockRunner.runCommand(
183+
command: anyNamed('command'),
184+
workingDirectory: anyNamed('workingDirectory')))
185+
.thenAnswer(
186+
(_) async => ProcessResult(999, 0, 'stdout', 'stderr'));
187+
188+
when(mockRunner.isSpecFileDirty(
189+
cachedSpec: anyNamed('cachedSpec'),
190+
loadedSpec: anyNamed('loadedSpec')))
191+
.thenAnswer((_) async => true);
192+
final args = GeneratorArguments(annotations: annotations);
193+
await OpenapiGenerator(logger: logger, runner: mockRunner)
194+
.generatorV2(
195+
args: args,
196+
baseCommand: 'dart',
197+
annotatedPath: 'annotatedPath');
198+
final generationLogIndex = logs.indexWhere((element) =>
199+
element.message.contains(
200+
'Running following command to generate openapi client - '));
201+
logs.forEach((element) {
202+
print(element.message);
203+
});
204+
final log = logs[generationLogIndex];
205+
expect(log.message, contains('-g=dart'));
206+
final sourceGenLogIndex = logs
207+
.indexWhere((element) => element.message.contains('source gen'));
208+
expect(logs[sourceGenLogIndex].message,
209+
'Skipping source gen because generator does not need it.');
210+
});
211+
test('dio', () async {
212+
final logs = <LogRecord>[];
213+
logger.onRecord.listen(logs.add);
214+
215+
final annotations =
216+
await loadAnnoation('next_gen_builder_test_config.dart');
217+
218+
when(mockRunner.runCommand(
219+
command: anyNamed('command'),
220+
workingDirectory: anyNamed('workingDirectory')))
221+
.thenAnswer(
222+
(_) async => ProcessResult(999, 0, 'stdout', 'stderr'));
223+
224+
when(mockRunner.isSpecFileDirty(
225+
cachedSpec: anyNamed('cachedSpec'),
226+
loadedSpec: anyNamed('loadedSpec')))
227+
.thenAnswer((_) async => true);
228+
final args = GeneratorArguments(annotations: annotations);
229+
await OpenapiGenerator(logger: logger, runner: mockRunner)
230+
.generatorV2(
231+
args: args,
232+
baseCommand: 'dart',
233+
annotatedPath: 'annotatedPath');
234+
final generationLogIndex = logs.indexWhere((element) =>
235+
element.message.contains(
236+
'Running following command to generate openapi client - '));
237+
logs.forEach((element) {
238+
print(element.message);
239+
});
240+
final log = logs[generationLogIndex];
241+
expect(log.message, contains('-g=dart-dio'));
242+
});
243+
test('dioAlt', () async {
244+
final logs = <LogRecord>[];
245+
logger.onRecord.listen(logs.add);
246+
247+
final annotations =
248+
await loadAnnoation('next_gen_builder_dio_alt_test_config.dart');
249+
250+
when(mockRunner.runCommand(
251+
command: anyNamed('command'),
252+
workingDirectory: anyNamed('workingDirectory')))
253+
.thenAnswer(
254+
(_) async => ProcessResult(999, 0, 'stdout', 'stderr'));
255+
256+
when(mockRunner.isSpecFileDirty(
257+
cachedSpec: anyNamed('cachedSpec'),
258+
loadedSpec: anyNamed('loadedSpec')))
259+
.thenAnswer((_) async => true);
260+
final args = GeneratorArguments(annotations: annotations);
261+
await OpenapiGenerator(logger: logger, runner: mockRunner)
262+
.generatorV2(
263+
args: args,
264+
baseCommand: 'dart',
265+
annotatedPath: 'annotatedPath');
266+
final generationLogIndex = logs.indexWhere((element) =>
267+
element.message.contains(
268+
'Running following command to generate openapi client - '));
269+
logs.forEach((element) {
270+
print(element.message);
271+
});
272+
final log = logs[generationLogIndex];
273+
expect(log.message, contains('-g=dart2-api'));
274+
});
275+
});
276+
204277
group('generatorV2', () {
205278
group('completes successfully', () {
206279
late OpenapiGenerator generator;

openapi-generator/test/specs/buckets.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library test_lib;
2+
3+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
4+
5+
@Openapi(
6+
inputSpecFile:
7+
'https://raw.githubusercontent.com/Nexushunter/tagmine-api/main/openapi.yaml',
8+
inputSpec: RemoteSpec(
9+
path:
10+
'https://raw.githubusercontent.com/Nexushunter/tagmine-api/main/openapi.yaml',
11+
),
12+
generatorName: Generator.dioAlt,
13+
useNextGen: true,
14+
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
15+
outputDirectory: './test/specs/output-nextgen/expected-args')
16+
class TestClassConfig {}

openapi-generator/test/specs/next_gen_builder_flutter_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
1010
cachePath: './test/specs/managed-cache.json',
1111
projectPubspecPath: './test/specs/flutter_pubspec.test.yaml',
1212
)
13-
class TestClassConfig extends OpenapiGeneratorConfig {}
13+
class TestClassConfig {}

openapi-generator/test/specs/next_gen_builder_flutterw_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
1414
additionalProperties: AdditionalProperties(wrapper: Wrapper.flutterw),
1515
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
1616
outputDirectory: './test/specs/output-nextgen/expected-args')
17-
class TestClassConfig extends OpenapiGeneratorConfig {}
17+
class TestClassConfig {}

openapi-generator/test/specs/next_gen_builder_fvm_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
1616
useNextGen: true,
1717
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
1818
outputDirectory: './test/specs/output-nextgen/expected-args')
19-
class TestClassConfig extends OpenapiGeneratorConfig {}
19+
class TestClassConfig {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
library test_lib;
2+
3+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
4+
5+
@Openapi(
6+
inputSpecFile:
7+
'https://raw.githubusercontent.com/Nexushunter/tagmine-api/main/openapi.yaml',
8+
inputSpec: InputSpec(
9+
path: './test/specs/openapi.test.yaml',
10+
),
11+
generatorName: Generator.dart,
12+
fetchDependencies: true,
13+
useNextGen: true,
14+
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
15+
outputDirectory: './test/specs/output-nextgen/expected-args')
16+
class TestClassConfig {}

0 commit comments

Comments
 (0)