- Clear the product table.
- Add a new product using the POST API.
- Retrieve the product with a GET API to verify its creation.
- Delete the product using the DELETE API.
- Attempt to retrieve the deleted product to ensure it has been removed.
Adding a Product and Validating Creation
The first code block shows how to prepare a product payload, add the product using the POST API, and validate the returned product details.End-to-End Delete Product Test
The following test demonstrates how to clear existing data, add a product named “connector”, verify its addition, and then delete it. Finally, it confirms that a GET request after deletion returns a 404 Not Found status.In the application code (for example, in app.go), the DELETE API must correctly handle the removal of a product by its ID. Following the deletion, a GET request for the same product ID should yield a 404 status, confirming the deletion was successful.
Example Test Output
When running the tests usinggo test, you might encounter output similar to the following if there is a discrepancy between expected and actual status codes: