-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test and Update MInVersionsFixedIn for issue of ALTER PARTITIONED TABLE ADD PRIMARY KEY #2047
Changes from 10 commits
1cd71c6
42b41f9
963492b
32b9858
08fdd6c
69ae778
54607fe
0c4c658
1ecd93b
07b6e4f
aae9b6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,18 +18,21 @@ import ( | |
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/jackc/pgx/v5" | ||
"github.com/jackc/pgx/v5/pgconn" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/testcontainers/testcontainers-go/modules/yugabytedb" | ||
"github.com/yugabyte/yb-voyager/yb-voyager/src/issue" | ||
"github.com/yugabyte/yb-voyager/yb-voyager/src/ybversion" | ||
) | ||
|
||
var ( | ||
yugabytedbContainer *yugabytedb.Container | ||
yugabytedbConnStr string | ||
versions = []string{} | ||
testYbVersion *ybversion.YBVersion | ||
) | ||
|
||
func getConn() (*pgx.Conn, error) { | ||
|
@@ -53,6 +56,23 @@ func getConn() (*pgx.Conn, error) { | |
return conn, nil | ||
} | ||
|
||
func fatalIfError(t *testing.T, err error) { | ||
if err != nil { | ||
t.Fatalf("error: %v", err) | ||
} | ||
} | ||
|
||
func assertErrorCorrectlyThrownForIssueForYBVersion(t *testing.T, execErr error, expectedError string, issue issue.Issue, ybv *ybversion.YBVersion) { | ||
isFixed, err := issue.IsFixedIn(ybv) | ||
fatalIfError(t, err) | ||
|
||
if isFixed { | ||
assert.NoError(t, execErr) | ||
} else { | ||
assert.ErrorContains(t, execErr, expectedError) | ||
} | ||
} | ||
|
||
func getConnWithNoticeHandler(noticeHandler func(*pgconn.PgConn, *pgconn.Notice)) (*pgx.Conn, error) { | ||
ctx := context.Background() | ||
var connStr string | ||
|
@@ -128,12 +148,33 @@ func testUnloggedTableIssue(t *testing.T) { | |
|
||
} | ||
|
||
func testAlterTableAddPKOnPartitionIssue(t *testing.T) { | ||
ctx := context.Background() | ||
conn, err := getConn() | ||
assert.NoError(t, err) | ||
|
||
defer conn.Close(context.Background()) | ||
_, err = conn.Exec(ctx, ` | ||
CREATE TABLE orders2 ( | ||
order_id bigint NOT NULL, | ||
order_date timestamp | ||
) PARTITION BY RANGE (order_date); | ||
ALTER TABLE orders2 ADD PRIMARY KEY (order_id,order_date)`) | ||
|
||
assertErrorCorrectlyThrownForIssueForYBVersion(t, err, "changing primary key of a partitioned table is not yet implemented", alterTableAddPKOnPartitionIssue, testYbVersion) | ||
} | ||
|
||
func TestDDLIssuesInYBVersion(t *testing.T) { | ||
var err error | ||
ybVersion := os.Getenv("YB_VERSION") | ||
if ybVersion == "" { | ||
panic("YB_VERSION env variable is not set. Set YB_VERSIONS=2024.1.3.0-b105 for example") | ||
} | ||
|
||
ybVersionWithoutBuild := strings.Split(ybVersion, "-")[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: so our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, right now it does accept build number as well, but the problem is that I'm planning to raise another PR preventing users from passing the build number in the input to prevent these kinds of issues. |
||
testYbVersion, err = ybversion.NewYBVersion(ybVersionWithoutBuild) | ||
fatalIfError(t, err) | ||
|
||
yugabytedbConnStr = os.Getenv("YB_CONN_STR") | ||
if yugabytedbConnStr == "" { | ||
// spawn yugabytedb container | ||
|
@@ -158,4 +199,7 @@ func TestDDLIssuesInYBVersion(t *testing.T) { | |
success = t.Run(fmt.Sprintf("%s-%s", "unlogged table", ybVersion), testUnloggedTableIssue) | ||
assert.True(t, success) | ||
|
||
success = t.Run(fmt.Sprintf("%s-%s", "alter table add PK on partition", ybVersion), testAlterTableAddPKOnPartitionIssue) | ||
assert.True(t, success) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need to pass
testYbVersion
as its global var