-
Notifications
You must be signed in to change notification settings - Fork 696
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
[ChaosCenter]: Add unit test code to chaoshub package in graphql server #3946
[ChaosCenter]: Add unit test code to chaoshub package in graphql server #3946
Conversation
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
It takes approximately 15 seconds for testing now. Because In |
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
This is awesome @namkyu1999 . 🚀🚀 |
Sure! I'll mention it again after I add it. |
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
I added defer function to clean up cloned repository, @amityt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, can we also add a ci job in the github actions to run the uint tests? That would make it possible for the reviewers to know the tests are working/passing without having to run them locally.
Sure! And I'm now writing docs about the test approach, I will update this PR after sharing docs. |
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
…st-code-to-chaos-hub Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
I wrote 'LitmusChaos Unit Test Strategies'. Anyone can comments to make better Docs. I'm currently in the process of modifying the tests in the ChaosHub package according to the docs. |
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
…st-code-to-chaos-hub Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
In GitHub Actions CI build, I separated unit-tests from backend-checks. Also, All backend components image build will be executed after unit-tests. If backend-checks are not executed successfully, unit-tests are not executed. Likely, If unit-tests are not executed successfully, the image build of backend components is not executed. Check this commit : fix: fix GitHub Actions config |
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
HubName: "hub1", | ||
RepoURL: "https://github.com/litmuschaos/chaos-charts", | ||
RepoBranch: "master", | ||
IsPrivate: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add private=true test cases for each of the test types (Sync, clone, pull, etc) too! In the same handler and assert it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@S-ayanide
It's cool but, our current unit test runs an actual git clone job so we need a real private repository and private key to run this job. IMO It's not reasonable for testing with a real private key in the unit test. if we want to test private repository test cases, we need to mock the git clone parts (make a new interface to run GitClone) and not run the actual git clone. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namkyu1999 maybe we can do a negative test with random creds and make sure we get an unauthorized response, because at the end of the day the git clone is handled by go-git and we don't have to test that what we need to test is whether we are calling the go-git package with proper data and imo if we can even get an unauthorized response for a valid private git repo we should be good.
Also if we absolutely want to test private repos we can add a github secret to this repo and then use it as an env in ci for the test to read. Though this may have security concerns, we can minimize it to some extent by limiting the access of the test creds to only 1 dummy repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, then I will make that test cases too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , @namkyu1999 you can add the negative test cases for the git functionalities for now. And for the positive test cases that @gdsoumya mentioned, we can take it in a different PR. We can break these test case PRs in different chunks for more flexibility in tracking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@S-ayanide , I added negative test cases and i will add positive test cases in different pr just like @amityt mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, +1 to @gdsoumya's points, asserting the error response would also count as valid in this case. That could be the first approach we take.
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: namkyu1999 <lak9348@konkuk.ac.kr>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Proposed changes
Add unit test code to chaoshub package. If this approach is valid, I will adopt this approach to all backend components.
This PR changes below...
2.1. Add github.com/stretchr/testify library for better mocking
2.2. Change version of go.mongodb.org/mongo-driver v1.8.2 to v1.11.4 (No side-effect)
GetIconHandler
function in the chaoshub package to the rest_handlers packageYou can check test coverage like below.
I achieved 80% of test coverage now
And you can check UI from this line
go tool cover -html=cover.prof -o cover.html
Issue No. #3892
Types of changes
What types of changes does your code introduce to Litmus? Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Dependency
Special notes for your reviewer: @amityt @S-ayanide @imrajdas @gdsoumya