-
Notifications
You must be signed in to change notification settings - Fork 86
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
test: Add new unit test framework with JSON fixtures #589
test: Add new unit test framework with JSON fixtures #589
Conversation
} | ||
|
||
// loadFixtures loads all JSON files in fixtures directory | ||
func (tf *TestFixtures) loadFixtures() { |
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.
optional: One other potential way to handle this would be using the embed directive with the embed.FS type. I think the current implementation is perfectly acceptable too, just figured I'd share another potential approach 🙂
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.
Appreciate the feedback. I wasn't aware of this option at all, but it seems like a great improvement to implement. This change should enhance performance as the test framework scales with additional tests and components 👍
… into test/new_unit_testing_framework # Conflicts: # test/go.mod
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.
Super clean implementation and everything is working on my end. Great work!
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.
Tested locally and everything is working gread!
Co-authored-by: Lena Garber <[email protected]>
📝 Description
This PR implements new improved unit testing framework that allows writing unit test against JSON fixtures. Here is the list of core files for the framework:
base.go
:Implements the ClientBaseCase struct for setting up the mock Linode client. This file includes utility functions like SetUp, TearDown, and MockGet to simplify mocking API requests for unit tests.
fixtures.go
:Provides the TestFixtures struct for loading and retrieving test fixtures from JSON files. This allows test cases to easily mock API responses using predefined data from the fixtures directory
instance_test.go
:Example test file containing test for List Instances endpoint via command
base.Client.ListInstances(context.Background(), nil)
e.g.
fixtures/linodes_list.json
:JSON fixture file containing mock data for Linode instances. This is used in the unit test to simulate a response from the List Instances API endpoint.
✔️ How to Test
make testunit
📷 Preview
If applicable, include a screenshot or code snippet of this change. Otherwise, please remove this section.