94 lines
2.2 KiB
Go
94 lines
2.2 KiB
Go
package main
|
|
|
|
// v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
|
import (
|
|
"context"
|
|
"mime"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"exporter/database/telegram_resource/public/table"
|
|
|
|
"github.com/dustin/go-humanize"
|
|
. "github.com/go-jet/jet/v2/postgres"
|
|
"github.com/spf13/viper"
|
|
v1pb "github.com/usememos/memos/proto/gen/api/v1"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
"google.golang.org/grpc/metadata"
|
|
)
|
|
|
|
func Test_Mime(t *testing.T) {
|
|
// Test code here
|
|
m := "application/rar"
|
|
m = "video/mp4"
|
|
m = "video/quicktime"
|
|
|
|
t.Log(mime.ExtensionsByType(m))
|
|
}
|
|
|
|
func Test_Size(t *testing.T) {
|
|
// Test code here
|
|
s := 6456390
|
|
t.Logf("Size: %d", s)
|
|
t.Logf("Human: %s", humanize.Bytes(uint64(s)))
|
|
|
|
viper.Set("size", "20MB")
|
|
b := viper.GetSizeInBytes("size")
|
|
t.Logf("Size: %d", s)
|
|
t.Logf("Vize: %d", b)
|
|
}
|
|
|
|
func Test_Sql(t *testing.T) {
|
|
tbl := table.ChannelMessages
|
|
|
|
stmt := tbl.UPDATE().SET(
|
|
tbl.Content.SET(RawString(`CONCAT(content, $var)`, RawArgs{"$var": "hello"})),
|
|
tbl.Media.SET(RawString(`media || $var::jsonb`, RawArgs{"$var": `{"Rogee": "Hello"}`})),
|
|
).WHERE(
|
|
tbl.GroupID.EQ(Int(1)).AND(
|
|
tbl.UUID.EQ(Int64(1)),
|
|
),
|
|
)
|
|
t.Log(stmt.DebugSql())
|
|
}
|
|
|
|
func Test_PublishGrpc(t *testing.T) {
|
|
token := "eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoicm9nZWVjbiIsImlzcyI6Im1lbW9zIiwic3ViIjoiMSIsImF1ZCI6WyJ1c2VyLmFjY2Vzcy10b2tlbiJdLCJpYXQiOjE3MjU2MTA2NzF9.PdF-eH0eSkaLFDl242To57AWkvv71oY57PMysx-nS24"
|
|
// new Grpc Client
|
|
ctx := context.Background()
|
|
target := "10.1.1.3:5230"
|
|
conn, err := grpc.NewClient(
|
|
target,
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{
|
|
"Authorization": "Bearer " + token,
|
|
}))
|
|
|
|
memoSvc := v1pb.NewMemoServiceClient(conn)
|
|
memos, err := memoSvc.ListMemos(ctx, &v1pb.ListMemosRequest{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, memo := range memos.Memos {
|
|
t.Log(memo.Content)
|
|
t.Log("--------------------")
|
|
}
|
|
}
|
|
|
|
func Test_Ext(t *testing.T) {
|
|
name := "abc.jpg"
|
|
ext := filepath.Ext(name)
|
|
t.Logf("Name: %s, Ext: %s", name, ext)
|
|
|
|
name = "abc_jpg"
|
|
ext = filepath.Ext(name)
|
|
t.Logf("Name: %s, Ext: %s", name, ext)
|
|
}
|