Zenler Player
Your course is loading. Hang tight.
Introduction to Testing in Go (Golang)
Back to curriculum
0% Complete
0% Complete
Introduction
Asking for help
Mistakes: we all make them.
What we'll cover in this section
Installing Go
Installing an IDE
Installing Docker
What we'll cover in this section
Creating a simple command line application
Writing a our first test for the isPrime() function
Improving our test with table tests
Checking test coverage
Completing our table tests
Improving our program to allow for user entered information
Writing a test for the prompt() function
Writing a test for the intro() function
Testing user input - writing a test for the checkNumbers() function
Updating readUserInput to make it testable, and then testing it
What we'll cover in this section
Running a single test
Running groups of tests (test suites)
What we'll cover in this section
Creating a simple web app
Setting up a route and handler for the home page
Testing our application routes
Testing Handlers: the Home handler
Setting up some simple middleware
Trying out our new addIPToContext middleware
Testing our middleware
Testing ipFromContext
Creating a login form
Setting up a route and stub handler for the login form
What we'll cover in this section
Setting up validation logic
Testing validation logic
Completing the tests for our validation logic
Trying out validation with our login form
What we'll cover in this section
Setting up a test enviroment with testing.M
Simplifying our templates using a layout
Installing a sessions package
Adding session to App config, and creating a SessionManager
Trying out our sessions
Updating our tests
Improving our test for the Home handler
Testing the render function with a bad template
What we'll cover in this section
Installing postgres with Docker
Setting up a database connection
Adding the data package for models and db package for database access
Making sure our web app can connect to our database
Closing our database pool gracefully, and resetting template path in tests
Creating a stub profile page
Adding messages to our template data and template files
Adding true authentication to the Login handler
Testing the Login handler
Adding Auth middleware
Testing Auth middleware
Updating routes & end-to-end tests
Problems with our Login handler test
What we'll cover in this section
Defining an interface type for our repository
Moving our database functions into a repository
Updating application config to use the database repository
Creating a testdb repository
Updating setup_test.go to use the test repository
Updating our tests to use the testdb repository
What we'll cover in this section
Getting started with testing our database
Getting our tests to spin up a docker image with Postgres
Populating our test database with empty tables
Testing InsertUser
Testing AllUsers
Testing GetUser and GetUserByEmail
Testing UpdateUser
Testing DeleteUser
Testing ResetUserPassword
Testing InsertUserImage
Using build tags to separate our integration tests
What we'll cover in this section
Adding a form to the Profile page
Adding the UserImage type to the User type
Updating the profile.page.gohtml file to look for a profile image
Writing a stub handler and a function to process profile image uploads
Implementing the UploadProfilePic handler
Trying things out
Testing image uploads
Testing our upload handler, with an alternative approach
What we'll cover in this section
Setting up an api with our existing code base
Adding stub handlers (endpoints) for our API
Trying out our REST API to make sure things work
Getting started with JWT Authentication
Generating token pairs
Implementing the authenticate handler
Trying out the authentication handler
Testing our authentication handler
Setting up a simple program to generate tokens for testing
Testing generating and validating tokens
Setting up our application middleware
Testing our CORS middleware
Testing our authRequired middleware
Add middleware to routes
Testing API routes
Implementing the handler to refresh tokens
Testing refreshing tokens
Completing the handlers that interact with the User type
Testing the handlers that interact with the User type
Finishing up testing handlers that interact with the data.User type
What we'll cover in this section
Serving HTML for our SPA
Authenticating users with our SPA
Setting a refresh token cookie when authenticating
Allowing users to refresh tokens using a cookie
Automatically refreshing tokens while the user is logged in
Getting a user from our simple SPA with the "Get User" button
Logging web users out
Testing refreshing tokens for Single Page Apps
Testing logging users out of our SPA
Introduction
Introduction
Preview
Asking for help
Mistakes: we all make them.
Setting up for our Development Environment
What we'll cover in this section
Installing Go
Installing an IDE
Installing Docker
Simple Testing
What we'll cover in this section
Creating a simple command line application
Preview
Writing a our first test for the isPrime() function
Improving our test with table tests
Checking test coverage
Completing our table tests
Improving our program to allow for user entered information
Writing a test for the prompt() function
Writing a test for the intro() function
Testing user input - writing a test for the checkNumbers() function
Updating readUserInput to make it testable, and then testing it
Untitled Section
What we'll cover in this section
Running a single test
Running groups of tests (test suites)
Testing Web Applications
What we'll cover in this section
Creating a simple web app
Preview
Setting up a route and handler for the home page
Testing our application routes
Testing Handlers: the Home handler
Setting up some simple middleware
Trying out our new addIPToContext middleware
Testing our middleware
Testing ipFromContext
Creating a login form
Setting up a route and stub handler for the login form
Testing Validation
What we'll cover in this section
Setting up validation logic
Testing validation logic
Completing the tests for our validation logic
Trying out validation with our login form
Testing Sessions
What we'll cover in this section
Setting up a test enviroment with testing.M
Simplifying our templates using a layout
Installing a sessions package
Adding session to App config, and creating a SessionManager
Trying out our sessions
Updating our tests
Improving our test for the Home handler
Testing the render function with a bad template
Testing POST Handlers
What we'll cover in this section
Installing postgres with Docker
Setting up a database connection
Adding the data package for models and db package for database access
Making sure our web app can connect to our database
Closing our database pool gracefully, and resetting template path in tests
Creating a stub profile page
Adding messages to our template data and template files
Adding true authentication to the Login handler
Testing the Login handler
Adding Auth middleware
Testing Auth middleware
Updating routes & end-to-end tests
Problems with our Login handler test
The Repository Pattern
What we'll cover in this section
Defining an interface type for our repository
Moving our database functions into a repository
Updating application config to use the database repository
Creating a testdb repository
Updating setup_test.go to use the test repository
Updating our tests to use the testdb repository
Testing the database with Integration tests
What we'll cover in this section
Getting started with testing our database
Getting our tests to spin up a docker image with Postgres
Populating our test database with empty tables
Testing InsertUser
Testing AllUsers
Testing GetUser and GetUserByEmail
Testing UpdateUser
Testing DeleteUser
Testing ResetUserPassword
Testing InsertUserImage
Using build tags to separate our integration tests
Testing File Uploads
What we'll cover in this section
Adding a form to the Profile page
Adding the UserImage type to the User type
Updating the profile.page.gohtml file to look for a profile image
Writing a stub handler and a function to process profile image uploads
Implementing the UploadProfilePic handler
Trying things out
Testing image uploads
Testing our upload handler, with an alternative approach
Testing REST API's
What we'll cover in this section
Setting up an api with our existing code base
Adding stub handlers (endpoints) for our API
Trying out our REST API to make sure things work
Getting started with JWT Authentication
Generating token pairs
Implementing the authenticate handler
Trying out the authentication handler
Testing our authentication handler
Setting up a simple program to generate tokens for testing
Testing generating and validating tokens
Setting up our application middleware
Testing our CORS middleware
Testing our authRequired middleware
Add middleware to routes
Testing API routes
Implementing the handler to refresh tokens
Testing refreshing tokens
Completing the handlers that interact with the User type
Testing the handlers that interact with the User type
Finishing up testing handlers that interact with the data.User type
Testing an API for Single Page Application (SPA)
What we'll cover in this section
Serving HTML for our SPA
Authenticating users with our SPA
Setting a refresh token cookie when authenticating
Allowing users to refresh tokens using a cookie
Automatically refreshing tokens while the user is logged in
Getting a user from our simple SPA with the "Get User" button
Logging web users out
Testing refreshing tokens for Single Page Apps
Testing logging users out of our SPA
×
This is an unpublished lesson. This lesson will not be shown for students unless you set it as Public.
Back to Dashboard
No contents are available in this lesson!
No lessons available !
Back to Dashboard
Lesson contents locked
Enroll to unlock this lesson.
Enroll to unlock
Next Lesson