diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/lib/pq@v1.10.7/notice_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-upstream.tar.xz icingadb-upstream.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/lib/pq@v1.10.7/notice_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/notice_test.go b/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/notice_test.go new file mode 100644 index 0000000..e9da9af --- /dev/null +++ b/dependencies/pkg/mod/github.com/lib/pq@v1.10.7/notice_test.go @@ -0,0 +1,50 @@ +//go:build go1.10 +// +build go1.10 + +package pq + +import ( + "database/sql" + "database/sql/driver" + "testing" +) + +func TestConnectorWithNoticeHandler_Simple(t *testing.T) { + b, err := NewConnector("") + 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) + } +} |