当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
15 Star 22 Fork 17

openGauss/openGauss-connector-go-pq
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
notice_test.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
travelliu 提交于 2022-02-11 15:40 +08:00 . feat: add custom tls
// +build go1.10
package pq
import (
"database/sql"
"database/sql/driver"
"testing"
)
func TestConnectorWithNoticeHandler_Simple(t *testing.T) {
name, err := getTestDsn()
if err != nil {
t.Fatal(err)
}
b, err := NewConnector(name)
if err != nil {
t.Fatal(err)
}
var notice *Error
// Make connector w/ handler to set the local var
c := ConnectorWithNoticeHandler(b, func(n *Error) { notice = n })
raiseNotice(c, t, "Test notice #1")
if notice == nil || notice.Message != "Test notice #1" {
t.Fatalf("Expected notice w/ message, got %v", notice)
}
// Unset the handler on the same connector
prevC := c
if c = ConnectorWithNoticeHandler(c, nil); c != prevC {
t.Fatalf("Expected to not create new connector but did")
}
raiseNotice(c, t, "Test notice #2")
if notice == nil || notice.Message != "Test notice #1" {
t.Fatalf("Expected notice to not change, got %v", notice)
}
// Set it back on the same connector
if c = ConnectorWithNoticeHandler(c, func(n *Error) { notice = n }); c != prevC {
t.Fatal("Expected to not create new connector but did")
}
raiseNotice(c, t, "Test notice #3")
if notice == nil || notice.Message != "Test notice #3" {
t.Fatalf("Expected notice w/ message, got %v", notice)
}
}
func raiseNotice(c driver.Connector, t *testing.T, escapedNotice string) {
db := sql.OpenDB(c)
defer db.Close()
sql := "DO language plpgsql $$ BEGIN RAISE NOTICE '" + escapedNotice + "'; END $$"
if _, err := db.Exec(sql); err != nil {
t.Fatal(err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opengauss/openGauss-connector-go-pq.git
git@gitee.com:opengauss/openGauss-connector-go-pq.git
opengauss
openGauss-connector-go-pq
openGauss-connector-go-pq
master

搜索帮助