Skip to content
Permalink
Browse files

Dart fix template tests (#4015)

* Clean up samples directory before fixing tests

- removed from samples/client/petstore/dart2 :
  - purge_test.sh (doesn't seem to be used and not helpful)
  - openapi folder (is to be re-generated with more meaningful name)
- updated dart2-petstore.sh to generate client library with new name
- used updated shell script to re-generate client library
- updated CI/.drone.yml to use the new client library for tests

* Update petstore tests to use faked http client

- skipped all of the tests that hit a live endpoint
- made a fake http client that can be set to check for expected values
   and/or return a provided response
- added some files with test data recorded from live api calls
- updated the README to reflect changes to tests

* Update .drone.yml so CI will run the tests
  • Loading branch information...
nickmeinhold authored and wing328 committed Oct 2, 2019
1 parent 8383f26 commit 41acae19e4fe3317f587bf70c1999c879890cf06
Showing with 1,018 additions and 17 deletions.
  1. +1 −1 CI/.drone.yml
  2. +1 −1 bin/dart2-petstore.sh
  3. +27 −1 samples/client/petstore/dart2/petstore/README.md
  4. +355 −0 samples/client/petstore/dart2/petstore/pubspec.lock
  5. +6 −3 samples/client/petstore/dart2/petstore/pubspec.yaml
  6. +133 −0 samples/client/petstore/dart2/petstore/test/fake_client.dart
  7. +1 −0 samples/client/petstore/dart2/petstore/test/file_upload_response.json
  8. +1 −0 samples/client/petstore/dart2/petstore/test/inventory_response.json
  9. +231 −0 samples/client/petstore/dart2/petstore/test/pet_faked_client_test.dart
  10. +3 −3 samples/client/petstore/dart2/petstore/test/pet_test.dart
  11. +85 −0 samples/client/petstore/dart2/petstore/test/store_faked_client_test.dart
  12. +2 −2 samples/client/petstore/dart2/petstore/test/store_test.dart
  13. +170 −0 samples/client/petstore/dart2/petstore/test/user_faked_client_test.dart
  14. +2 −2 samples/client/petstore/dart2/petstore/test/user_test.dart
  15. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/.gitignore
  16. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/.openapi-generator-ignore
  17. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/.openapi-generator/VERSION
  18. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/.travis.yml
  19. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/README.md
  20. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/ApiResponse.md
  21. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/Category.md
  22. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/Order.md
  23. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/Pet.md
  24. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/PetApi.md
  25. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/StoreApi.md
  26. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/Tag.md
  27. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/User.md
  28. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/docs/UserApi.md
  29. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/git_push.sh
  30. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api.dart
  31. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api/pet_api.dart
  32. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api/store_api.dart
  33. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api/user_api.dart
  34. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api_client.dart
  35. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api_exception.dart
  36. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/api_helper.dart
  37. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/auth/api_key_auth.dart
  38. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/auth/authentication.dart
  39. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/auth/http_basic_auth.dart
  40. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/auth/oauth.dart
  41. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/api_response.dart
  42. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/category.dart
  43. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/order.dart
  44. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/pet.dart
  45. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/tag.dart
  46. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/lib/model/user.dart
  47. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/pubspec.yaml
  48. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/api_response_test.dart
  49. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/category_test.dart
  50. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/order_test.dart
  51. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/pet_api_test.dart
  52. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/pet_test.dart
  53. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/store_api_test.dart
  54. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/tag_test.dart
  55. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/user_api_test.dart
  56. 0 samples/client/petstore/dart2/{openapi → petstore_client_lib}/test/user_test.dart
  57. +0 −4 samples/client/petstore/dart2/purge_test.sh
@@ -13,7 +13,7 @@ steps:
commands:
- (cd samples/client/petstore/dart-jaguar/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
- (cd samples/client/petstore/dart-jaguar/flutter_petstore/openapi && pub get && pub run build_runner build --delete-conflicting-outputs)
- (cd samples/client/petstore/dart2/openapi && pub get && pub run test)
- (cd samples/client/petstore/dart2/petstore && pub get && pub run test)
# test Java 11 HTTP client
- name: java11-test
image: openjdk:11.0
@@ -29,5 +29,5 @@ fi
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"

# Generate client
ags="generate -t modules/openapi-generator/src/main/resources/dart2 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/openapi --additional-properties hideGenerationTimestamp=true $@"
ags="generate -t modules/openapi-generator/src/main/resources/dart2 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dart -o samples/client/petstore/dart2/petstore_client_lib --additional-properties hideGenerationTimestamp=true $@"
java $JAVA_OPTS -jar $executable $ags
@@ -1,3 +1,29 @@
# Background

## Current state of tests

TL;DR currently the only tests are e2e tests that were adapted to use a faked http client. While pushing data around as a smoke test has some value, more testing is required. In particular we need comprehensive unit/integration tests.

- an old set of e2e tests are skipped for CI, as they hit a live endpoint and so are inherently flaky
- `pet_test.dart`
- `store_test.dart`
- `user_test.dart`
- the above set of tests were adapted to use a faked http client
- the tests are not really well suited to being used with a stubbed client, many are basically just testing the endpoint logic
- while not a great set of tests, they do have some value as a smoke test for template changes
- the adapted tests and files that contain test data:
- `pet_test_fake_client.dart`
- `store_test_fake_client.dart`
- `user_test_fake_client.dart`
- `fake_client.dart`
- `file_upload_response.json`

## Assumptions

- the tests will be run as part of CI and so have access to dart:io

# Running

## If not already done, resolve dependencies

`pub get`
@@ -8,4 +34,4 @@

## To run all tests in the test folder:

`pub run test test`
`pub run test`

0 comments on commit 41acae1

Please sign in to comment.
You can’t perform that action at this time.