50 lines
927 B
Go
50 lines
927 B
Go
package blog_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"gitlab.com/go-course-project/go17/vblog/apps/blog"
|
|
)
|
|
|
|
var (
|
|
ctx = context.Background()
|
|
)
|
|
|
|
// Required("admin")
|
|
func TestCreateBlog(t *testing.T) {
|
|
req := &blog.CreateBlogRequest{
|
|
Title: "Go项目课1",
|
|
Summary: "全栈项目",
|
|
Content: "GORM + GIN",
|
|
Category: "软件开发",
|
|
Tags: map[string]string{
|
|
"Language": "Golang",
|
|
},
|
|
}
|
|
ins, err := blog.GetService().CreateBlog(ctx, req)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(ins)
|
|
}
|
|
|
|
// SELECT * FROM `blogs` ORDER BY created_at DESC LIMIT 20
|
|
func TestQueryBlog(t *testing.T) {
|
|
req := blog.NewQueryBlogRequest()
|
|
req.Tags = map[string]string{
|
|
"Language": "Golang",
|
|
}
|
|
ins, err := blog.GetService().QueryBlog(ctx, req)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(ins)
|
|
}
|
|
|
|
func TestNewQueryBlogRequest(t *testing.T) {
|
|
req := blog.NewQueryBlogRequest()
|
|
req.SetTag("key1=value1,key2=value2")
|
|
t.Log(req)
|
|
}
|