Authentication Feature Testing in REST API
Learn how to test the authentication feature in the REST API application.
We'll cover the following...
Test the application
The testing database is already prepared for testing. To create a test, we add a file called api_test.go in the project’s root directory. After creating the file, we add a function called newApp() to create an application for testing.
In the code above, the application for testing purposes is created. This function is similar to the main function inside the main.go file. The difference in this case is that the testing database is used instead of the actual application database.
Before creating the first test, we create the helper function to get the faker or sample data for the item entity. We add a helper function called getItem() after the newApp() function declaration.
As seen in the code above, the getItem() function is created to get the sample data for the item entity. The sample item data is inserted into the database with the SeedItem() function. The SeedItem() function returns the sample data for the item entity that is stored inside the item variable. The item ...