go17/vblog/apps/blog/impl_test.go

50 lines
927 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"
)
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
}
2024-12-15 12:10:11 +08:00
ins, err := blog.GetService().CreateBlog(ctx, req)
2024-12-08 14:46:15 +08:00
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-15 12:10:11 +08:00
ins, err := blog.GetService().QueryBlog(ctx, req)
2024-12-08 14:46:15 +08:00
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")
2025-01-19 09:33:31 +08:00
t.Log(req)
2024-12-08 16:20:18 +08:00
}