This is an automated email from the ASF dual-hosted git repository. gfphoenix78 pushed a commit to branch sync-with-upstream in repository https://gitbox.apache.org/repos/asf/cloudberry-gpbackup.git
The following commit(s) were added to refs/heads/sync-with-upstream by this push: new b1d07392 fix(test): Make column encoding check order-insensitive (#19) b1d07392 is described below commit b1d073928341f75817214868c8b6d07667b0d3bf Author: Robert Mu <db...@hotmail.com> AuthorDate: Tue Aug 26 14:26:52 2025 +0800 fix(test): Make column encoding check order-insensitive (#19) The integration test for `GetColumnDefinitions` was failing on Cloudberry because it returned column encoding options in a different order than Greenplum 7. For example, for a default encoding, GPDB7 returned "...,blocksize=32768,compresslevel=0" while Cloudberry returned "...,compresslevel=0,blocksize=32768". The test was performing a strict string comparison on the `Encoding` field, making it brittle and dependent on ordering. This commit fixes the test by making the comparison order-insensitive. Instead of comparing the `Encoding` string directly, the test now: 1. Splits the expected and actual encoding strings into slices of key-value pairs. 2. Uses `gomega.ConsistOf` to assert that both slices contain the same elements, regardless of their order. 3. Continues to use `structmatcher` for all other fields in the `ColumnDefinition` struct. This approach makes the test more robust and correctly validates the encoding options across different database environments without being affected by ordering differences. --- integration/predata_table_defs_queries_test.go | 31 ++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/integration/predata_table_defs_queries_test.go b/integration/predata_table_defs_queries_test.go index e9015760..e60946e0 100644 --- a/integration/predata_table_defs_queries_test.go +++ b/integration/predata_table_defs_queries_test.go @@ -3,6 +3,7 @@ package integration import ( "database/sql" "fmt" + "strings" "github.com/cloudberrydb/gp-common-go-libs/structmatcher" "github.com/cloudberrydb/gp-common-go-libs/testhelper" @@ -94,13 +95,39 @@ PARTITION BY RANGE (year) oid := testutils.OidFromObjectName(connectionPool, "public", "co_atttable", backup.TYPE_RELATION) tableAtts := backup.GetColumnDefinitions(connectionPool)[oid] + // Expected column definitions columnA := backup.ColumnDefinition{Oid: 0, Num: 1, Name: "a", NotNull: false, HasDefault: false, Type: "double precision", Encoding: "compresstype=none,blocksize=32768,compresslevel=0", StatTarget: -1, StorageType: "", DefaultVal: "", Comment: ""} columnB := backup.ColumnDefinition{Oid: 0, Num: 2, Name: "b", NotNull: false, HasDefault: false, Type: "text", Encoding: "blocksize=65536,compresstype=none,compresslevel=0", StatTarget: -1, StorageType: "", DefaultVal: "", Comment: ""} + expectedColumns := []backup.ColumnDefinition{columnA, columnB} Expect(tableAtts).To(HaveLen(2)) - structmatcher.ExpectStructsToMatchExcluding(&columnA, &tableAtts[0], "Oid") - structmatcher.ExpectStructsToMatchExcluding(&columnB, &tableAtts[1], "Oid") + /* + * We cannot use structmatcher directly on the entire struct because CloudberryDB + * may return column encoding options in a different order than Greenplum DB. + * + * For example, for a column with default encoding, Greenplum 7 might return: + * "compresstype=none,blocksize=32768,compresslevel=0" + * While CloudberryDB might return: + * "compresstype=none,compresslevel=0,blocksize=32768" + * + * To handle this, we perform a custom comparison: + * 1. Use structmatcher for all fields *except* the Encoding field. + * 2. Split the Encoding strings into slices and use gomega.ConsistOf to + * perform an order-insensitive comparison on the encoding options. + */ + for i, expected := range expectedColumns { + actual := tableAtts[i] + expectedEncodingOpts := strings.Split(expected.Encoding, ",") + actualEncodingOpts := strings.Split(actual.Encoding, ",") + + // Temporarily clear encoding to use structmatcher for other fields + expected.Encoding = "" + actual.Encoding = "" + + structmatcher.ExpectStructsToMatchExcluding(&expected, &actual, "Oid") + Expect(actualEncodingOpts).To(ConsistOf(expectedEncodingOpts)) + } }) It("returns an empty attribute array for a table with no columns", func() { testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.nocol_atttable()") --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For additional commands, e-mail: commits-h...@cloudberry.apache.org