go17/vblog/apps/blog/impl_test.go

51 lines
988 B
Go
Raw Normal View History

2024-12-08 14:46:15 +08:00
package blog_test
import (
"context"
"testing"
"gitlab.com/go-course-project/go17/vblog/apps/blog"
"gitlab.com/go-course-project/go17/vblog/apps/blog/impl"
)
var (
ctx = context.Background()
)
// Required("admin")
func TestCreateBlog(t *testing.T) {
req := &blog.CreateBlogRequest{
2024-12-08 16:20:18 +08:00
Title: "Go项目课1",
2024-12-08 14:46:15 +08:00
Summary: "全栈项目",
Content: "GORM + GIN",
Category: "软件开发",
2024-12-08 16:20:18 +08:00
Tags: map[string]string{
"Language": "Golang",
},
2024-12-08 14:46:15 +08:00
}
ins, err := impl.BlogService.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()
2024-12-08 16:20:18 +08:00
req.Tags = map[string]string{
"Language": "Golang",
}
2024-12-08 14:46:15 +08:00
ins, err := impl.BlogService.QueryBlog(ctx, req)
if err != nil {
t.Fatal(err)
}
t.Log(ins)
}
2024-12-08 16:20:18 +08:00
func TestNewQueryBlogRequest(t *testing.T) {
req := blog.NewQueryBlogRequest()
req.SetTag("key1=value1,key2=value2")
t.Log(req.Tags)
}