43 lines
835 B
Go
43 lines
835 B
Go
|
package controller_test
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
"gitlab.com/go-course-project/go17/book/controller"
|
||
|
"gitlab.com/go-course-project/go17/book/model"
|
||
|
)
|
||
|
|
||
|
func TestGetBook(t *testing.T) {
|
||
|
book := controller.NewBookController()
|
||
|
ins, err := book.GetBook(context.Background(), &controller.GetBookRequest{
|
||
|
Isbn: 5,
|
||
|
})
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
t.Log(ins)
|
||
|
}
|
||
|
|
||
|
// INSERT INTO `books` (`title`,`author`,`price`,`is_sale`) VALUES ('Go语言','will',10,NULL)
|
||
|
//
|
||
|
// {
|
||
|
// "isbn": 5,
|
||
|
// "title": "Go语言",
|
||
|
// "author": "will",
|
||
|
// "price": 10,
|
||
|
// "is_sale": null
|
||
|
// }
|
||
|
func TestCreateBook(t *testing.T) {
|
||
|
book := controller.NewBookController()
|
||
|
ins, err := book.CreateBook(context.Background(), &model.BookSpec{
|
||
|
Author: "will",
|
||
|
Price: 10,
|
||
|
Title: "Go语言",
|
||
|
})
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
t.Log(ins)
|
||
|
}
|