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

Implement Bats test for the script with mocks #51

Open
labbots opened this issue May 14, 2020 · 5 comments
Open

Implement Bats test for the script with mocks #51

labbots opened this issue May 14, 2020 · 5 comments

Comments

@labbots
Copy link
Owner

labbots commented May 14, 2020

Create unit tests for upload and google-oauth2 bash script. The tests must mock curl requests to google drive API so that no real google account is required to run the tests.

@labbots labbots created this issue from a note in Google drive upload (To do) May 14, 2020
@Akianonymus
Copy link
Collaborator

Akianonymus commented May 14, 2020

@labbots So we are going to check if the api is working ?? I don't understand how is that fair for a test, it's more of a google drive api test than upload test. Again, i didn't fully understand your idea.

I thought the purpose of a test script is to test the functionality of the script, which here is uploading files to google drive.

Obviously, we can use credentials safely using github secrets, but need to check if it's fully safe and rational to use

@labbots
Copy link
Owner Author

labbots commented May 14, 2020

@Akianonymus I was intending to have unit tests rather than integration tests. The purpose of the test is to check the functionality of the functions within the script and not to test external service. In this case we know the output of the google drive API are standard and there is no necessity to actually make calls to google drive API. The response from the API could be mocked for various scenario and tested.

@Akianonymus
Copy link
Collaborator

@labbots Ok, understood some of it.

Question, how do we exactly mock it ? do we parse the errors messages, i mean without credentials, it won't tell anything except basic google errors ?

@labbots
Copy link
Owner Author

labbots commented May 14, 2020

I am not exactly sure how mocking works with bats tests. But usually in other programming languages, you define the output for a method based on the provided input. In our case, we need to mock curl request based on different parameter passed on the curl request and test the functionality. I need to do further research on how this could be achieved with unit tests in bash script.

@Akianonymus
Copy link
Collaborator

I propose to use something like this

https://github.com/dylanaraps/pure-bash-bible/blob/master/test.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants