December 2017
Intermediate to advanced
316 pages
6h 58m
English
In the previous chapter, we created a URL shortening service. The structure of the URL shortener project we worked on previously looks like this:
├── main.go├── models│ └── models.go└── utils └── encodeutils.go2 directories, 3 files
In the main.go file, we created two API handlers: one for GET and one for POST. We are going to write the unit tests for both of those handlers. Add a file called main_test.go in the root directory of the project:
touch main_test.go
In order to test our API, we need to test our API handlers:
package main_test import ( "testing" "net/http" ) func TestGetOriginalURL(t *testing.T) { // make a dummy reques response, err := http.Get("http://localhost:8000/v1/short/1") ...Read now
Unlock full access