Skip to content

Commit

Permalink
fix unlogged table issue
Browse files Browse the repository at this point in the history
  • Loading branch information
makalaaneesh committed Dec 10, 2024
1 parent 59ed193 commit 8fe088b
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions yb-voyager/src/query/queryissue/issues_ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/stretchr/testify/assert"
"github.com/testcontainers/testcontainers-go/modules/yugabytedb"
)
Expand Down Expand Up @@ -52,6 +53,32 @@ func getConn() (*pgx.Conn, error) {
return conn, nil
}

func getConnWithNoticeHandler(noticeHandler func(*pgconn.PgConn, *pgconn.Notice)) (*pgx.Conn, error) {
ctx := context.Background()
var connStr string
var err error
if yugabytedbConnStr != "" {
connStr = yugabytedbConnStr
} else {
connStr, err = yugabytedbContainer.YSQLConnectionString(ctx, "sslmode=disable")
if err != nil {
return nil, err
}
}

conf, err := pgx.ParseConfig(connStr)
if err != nil {
return nil, err
}
conf.OnNotice = noticeHandler
conn, err := pgx.ConnectConfig(ctx, conf)
if err != nil {
return nil, err
}

return conn, nil
}

func testXMLFunctionIssue(t *testing.T) {
ctx := context.Background()
conn, err := getConn()
Expand Down Expand Up @@ -79,13 +106,28 @@ func testStoredGeneratedFunctionsIssue(t *testing.T) {
}

func testUnloggedTableIssue(t *testing.T) {
noticeFound := false
noticeHandler := func(conn *pgconn.PgConn, notice *pgconn.Notice) {
if notice != nil {
if notice.Message != "" {
assert.Equal(t, "unlogged option is currently ignored in YugabyteDB, all non-temp tables will be logged", notice.Message)
noticeFound = true
}
}
}
ctx := context.Background()
conn, err := getConn()
conn, err := getConnWithNoticeHandler(noticeHandler)
assert.NoError(t, err)

defer conn.Close(context.Background())
_, err = conn.Exec(ctx, "CREATE UNLOGGED TABLE unlogged_table (a int)")
assert.ErrorContains(t, err, "UNLOGGED database object not supported yet")
// in 2024.2, UNLOGGED no longer throws an error, just a notice
if noticeFound {
return
} else {
assert.ErrorContains(t, err, "UNLOGGED database object not supported yet")
}

}

func TestDDLIssuesInYBVersion(t *testing.T) {
Expand Down

0 comments on commit 8fe088b

Please sign in to comment.