linode / linodego

Go client for Linode REST v4 API
MIT License
139 stars 82 forks source link

test: Add new unit test framework with JSON fixtures #589

Closed ykim-akamai closed 3 weeks ago

ykim-akamai commented 1 month ago

📝 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.