Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases and implement the mock server #8

Merged
merged 39 commits into from
Aug 14, 2024

Conversation

KATTA-00
Copy link
Contributor

@KATTA-00 KATTA-00 commented Aug 9, 2024

Purpose

  • Added test cases for both the live server and the mock server.
  • Implemented a mock server to support testing.
  • Added a README.md with instructions on how to run the tests.

@ayeshLK
Copy link
Member

ayeshLK commented Aug 12, 2024

Lets rename ballerina/tests/openapi_service.bal file to ballerina/tests/mock_service.bal.

ballerina/tests/test.bal Outdated Show resolved Hide resolved
@ayeshLK
Copy link
Member

ayeshLK commented Aug 12, 2024

Shall we move the types generated for mock-service into the mock_service.bal ?

ballerina/tests/test.bal Outdated Show resolved Hide resolved
@KATTA-00
Copy link
Contributor Author

@ayeshLK changes done!!!

ballerina/tests/test.bal Outdated Show resolved Hide resolved
@KATTA-00 KATTA-00 requested a review from ayeshLK August 12, 2024 09:11
ballerina/tests/test.bal Outdated Show resolved Hide resolved
@KATTA-00 KATTA-00 requested a review from ayeshLK August 12, 2024 09:42
ballerina/tests/test.bal Outdated Show resolved Hide resolved
@KATTA-00 KATTA-00 requested a review from ayeshLK August 12, 2024 10:46
ballerina/tests/mock_service.bal Outdated Show resolved Hide resolved
docs/setup/resources/sample.jsonl Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
}

@test:Config {
dataProvider: dataGen,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to use a data provider for this test suite (as test data in L45 seems to be empty)? If not, better to completely remove the data provider related implementations

Copy link
Contributor Author

@KATTA-00 KATTA-00 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A data provider is used to share a common object within isolated functions. This allows for chaining test cases, where the same file ID, job ID, and model ID can be shared.

For example, after creating a file using testCreateFile, the ID is updated in the shared object and can be used after that.
Since initially the IDs are not there, those are empty.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KATTA-00 Ack. Still um not sure if using data providers for that purpose might be the best option here. @Dilhasha appreciate any inputs on this implementation pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NipunaRanasinghe I found that approach to be effective here, but if there is a better method, I would greatly appreciate knowing about it

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KATTA-00
The purpose of data providers is to allow executing the same test case with different data sets.

From what I understand, you need to make sure the order of execution of these test cases, so it's advisable to use the dependsOn option to guarantee the order.

If there is a dependency among the test cases, you can omit the isolated keyword for test functions. The isolated keyword is explicitly required if you want to allow these test cases to run parallel even though it accesses a global variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dilhasha Ack. The order is configured using the dependson option and the tests are passing fine.
@NipunaRanasinghe What's your opinion? Shall we go with this way or remove isolated?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we get rid of the data provider too?
You can mark the global variable as isolated and access it within lock statements to avoid parallel modification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KATTA-00 as per the offline discussion we had lets remove the isolated qualifier and the data provider implementation from the tests

ballerina/tests/test.bal Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
ballerina/tests/test.bal Outdated Show resolved Hide resolved
ballerina/tests/mock_service.bal Outdated Show resolved Hide resolved
Copy link
Contributor

@NipunaRanasinghe NipunaRanasinghe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NipunaRanasinghe NipunaRanasinghe merged commit 82b5099 into ballerina-platform:main Aug 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants