2024-08-13 00:29:27 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2024-08-20 01:36:41 +00:00
|
|
|
"fmt"
|
2024-08-13 00:29:27 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2024-08-29 19:10:29 +00:00
|
|
|
"l12.xyz/x/dal/pkg/adapter"
|
|
|
|
"l12.xyz/x/dal/pkg/proto"
|
2024-08-20 17:34:01 +00:00
|
|
|
|
2024-08-13 00:29:27 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProtoMessagePack(t *testing.T) {
|
|
|
|
message, err := os.ReadFile("proto_test.msgpack")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to read file: %v", err)
|
|
|
|
}
|
|
|
|
req := proto.Request{}
|
2024-08-20 01:36:41 +00:00
|
|
|
fmt.Println(message)
|
2024-08-13 00:29:27 +00:00
|
|
|
req.UnmarshalMsg(message)
|
2024-08-15 07:06:11 +00:00
|
|
|
query, err := req.Parse(adapter.CommonDialect{})
|
2024-08-13 00:29:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to parse query: %v", err)
|
|
|
|
}
|
|
|
|
db := "database.sqlite"
|
|
|
|
if query.Db != db {
|
|
|
|
t.Fatalf("expected db %s, got %s", db, query.Db)
|
|
|
|
}
|
|
|
|
expr := "SELECT * FROM data WHERE a = ? AND b > ?"
|
|
|
|
if query.Expression != expr {
|
|
|
|
t.Fatalf("expected expression %s, got %s", expr, query.Expression)
|
|
|
|
}
|
|
|
|
//fmt.Println(q)
|
|
|
|
}
|