Files
opsxdb/server/internal/db/family_e2e_test.go

73 lines
2.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package db
// family_e2e_test.go —— 协议兼容族真实例验收(MySQL 族:TiDB;PG 族:openGauss)。
// 触发:OPSXDB_E2E_TIDB=1 / OPSXDB_E2E_GAUSS=1;验证族内真实例后注册表才可翻 verified。
import (
"context"
"os"
"testing"
"time"
)
// TestE2ETiDB —— 真实 TiDB(pingcap/tidb 单容器,MySQL 协议族)。
func TestE2ETiDB(t *testing.T) {
if os.Getenv("OPSXDB_E2E_TIDB") != "1" {
t.Skip("置 OPSXDB_E2E_TIDB=1 并启动 TiDB :4000 后运行(docker run -p 4000:4000 pingcap/tidb:v7.5.0)")
}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
c := ConnReq{Driver: "tidb", Host: "127.0.0.1", Port: 4000, User: "root"}
if err := TestConnection(c); err != nil {
t.Skipf("TiDB :4000 不可达: %v", err)
}
dbs, err := ListDatabases(ctx, c)
if err != nil || len(dbs) == 0 {
t.Fatalf("ListDatabases = %v, %v", dbs, err)
}
// 建库建表写读
must := func(sql string, db string) ExecResult {
t.Helper()
return ExecSQL(ctx, ConnReq{Driver: "tidb", Host: "127.0.0.1", Port: 4000, User: "root", Database: db, SQL: sql, ConfirmDanger: true})
}
if r := must("CREATE DATABASE IF NOT EXISTS opsxe2e", ""); r.Error != "" {
t.Fatalf("create db: %s", r.Error)
}
if r := must("CREATE TABLE IF NOT EXISTS fam_t(id INT PRIMARY KEY, name VARCHAR(32))", "opsxe2e"); r.Error != "" {
t.Fatalf("create table: %s", r.Error)
}
if r := must(`INSERT INTO fam_t VALUES (1, 'tidb-ok')`, "opsxe2e"); r.Error != "" {
t.Fatalf("insert: %s", r.Error)
}
r := must("SELECT * FROM fam_t", "opsxe2e")
if r.Error != "" || r.RowCount != 1 || r.Rows[0]["name"] != "tidb-ok" {
t.Fatalf("select: err=%s rows=%+v", r.Error, r.Rows)
}
}
// TestE2EOpenGauss —— 真实 openGauss(PG 协议族;Apple Silicon 需 --platform linux/amd64)。
func TestE2EOpenGauss(t *testing.T) {
if os.Getenv("OPSXDB_E2E_GAUSS") != "1" {
t.Skip("置 OPSXDB_E2E_GAUSS=1 并启动 openGauss :5432 后运行")
}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
c := ConnReq{Driver: "gaussdb", Host: "127.0.0.1", Port: 5432, User: "omm", Password: "Demo@123", Database: "postgres"}
if err := TestConnection(c); err != nil {
t.Skipf("openGauss :5432 不可达: %v", err)
}
dbs, err := ListDatabases(ctx, c)
if err != nil || len(dbs) == 0 {
t.Fatalf("ListDatabases = %v, %v", dbs, err)
}
q := ExecSQL(ctx, ConnReq{Driver: "gaussdb", Host: "127.0.0.1", Port: 5432, User: "omm", Password: "Demo@123", Database: "postgres", SQL: "SELECT 1 AS one"})
if q.Error != "" {
t.Fatalf("select: %s", q.Error)
}
if q.RowCount != 1 {
t.Fatalf("rows = %+v", q.Rows)
}
}