课程: Practice It: Go REST API Server

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Check it: Create integration tests

Check it: Create integration tests - Go教程

课程: Practice It: Go REST API Server

Check it: Create integration tests

- [Instructor] Now that you've tried it out, let's look at how I solved it. So let's go down to TestCreateProduct, we did that. So let's add function TestGetProduct. In this case, it's also using the testing library. And the first thing we'll do here is we're going to clear the product table. And after that, we're going to need to add products. Now, we don't have this defined, but we will add it here and then defined it afterwards. And we'll only need one product. And then next what we'll do is we'll create the req, the request. Don't care about the error. And we have http.NewRequest, and that's going to be a GET. Get the end point, which will be product/1. And then we have nil. Then we're going to create the response calling executeRequest. And then we're going to check the response code, should be http.StatusOk, and then the response.Code. Okay. But now we need to add the function addProducts. So we have…

内容