Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(sql-review): sort adviceList in test to avoid unordered iterating map (#6608)
h3n4l20a90e28715c
diff --git a/backend/plugin/advisor/mysql/test/index_type_no_blob.yaml b/backend/plugin/advisor/mysql/test/index_type_no_blob.yamlindex 184a472765..ef671ba1ea 100644--- a/backend/plugin/advisor/mysql/test/index_type_no_blob.yaml+++ b/backend/plugin/advisor/mysql/test/index_type_no_blob.yaml@@ -17,13 +17,13 @@- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ content: Columns in index must not be BLOB but `t`.`lb` is longblobline: 1details: ""- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`lb` is longblob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblobline: 1details: ""- statement: CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id INT, UNIQUE INDEX(b(1), mb(2), lb(3), id))@@ -37,13 +37,13 @@- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ content: Columns in index must not be BLOB but `t`.`lb` is longblobline: 1details: ""- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`lb` is longblob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblobline: 1details: ""- statement: CREATE TABLE t(b BLOB, mb MEDIUMBLOB, lb LONGBLOB, id iNT, INDEX(b(1), mb(2), lb(3), id))@@ -57,13 +57,13 @@- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ content: Columns in index must not be BLOB but `t`.`lb` is longblobline: 1details: ""- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`lb` is longblob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblobline: 1details: ""- statement: CREATE TABLE t(id INT, PRIMARY KEY(id))@@ -97,13 +97,13 @@- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ content: Columns in index must not be BLOB but `t`.`lb` is longblobline: 3details: ""- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`lb` is longblob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblobline: 3details: ""- statement: |-@@ -119,13 +119,13 @@- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`mb` is mediumblob+ content: Columns in index must not be BLOB but `t`.`lb` is longblobline: 3details: ""- status: WARNcode: 804title: index.type-no-blob- content: Columns in index must not be BLOB but `t`.`lb` is longblob+ content: Columns in index must not be BLOB but `t`.`mb` is mediumblobline: 3details: ""- statement: |-diff --git a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml b/backend/plugin/advisor/mysql/test/naming_index_fk.yamlindex 10a69d82d3..149bba0c69 100644--- a/backend/plugin/advisor/mysql/test/naming_index_fk.yaml+++ b/backend/plugin/advisor/mysql/test/naming_index_fk.yaml@@ -19,13 +19,13 @@- status: WARNcode: 305title: naming.index.fk- content: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk`+ content: Foreign key `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk` in table `tech_book` mismatches the naming convention, its length should be within 64 charactersline: 2details: ""- status: WARNcode: 305title: naming.index.fk- content: Foreign key `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ content: Foreign key in table `tech_book` mismatches the naming convention, expect "^$|^fk_tech_book_author_id_author_id$" but found `rvemempmcmmhutaskvcidmwaldtfjdgmcpkhmibtadfydtkexpuzczrrneucthfwk`line: 2details: ""- statement: CREATE TABLE book(id INT, author_id INT, FOREIGN KEY fk_book_author_id_author_id (author_id) REFERENCES author (id))diff --git a/backend/plugin/advisor/mysql/test/naming_index_idx.yaml b/backend/plugin/advisor/mysql/test/naming_index_idx.yamlindex 378d44a3b5..4d2151138f 100644--- a/backend/plugin/advisor/mysql/test/naming_index_idx.yaml+++ b/backend/plugin/advisor/mysql/test/naming_index_idx.yaml@@ -19,13 +19,13 @@- status: WARNcode: 303title: naming.index.idx- content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw`+ content: Index `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw` in table `tech_book` mismatches the naming convention, its length should be within 64 charactersline: 2details: ""- status: WARNcode: 303title: naming.index.idx- content: Index `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ content: Index in table `tech_book` mismatches the naming convention, expect "^$|^idx_tech_book_id_name$" but found `afvjwsgrbgqzjfrkmbcoxzstznuypasijbbcdykoboredqovetzfcmmqliaelyavw`line: 2details: ""- statement: ALTER TABLE tech_book RENAME INDEX old_index TO idx_tech_book_id_namediff --git a/backend/plugin/advisor/mysql/test/naming_index_uk.yaml b/backend/plugin/advisor/mysql/test/naming_index_uk.yamlindex 9c02353147..abe7b98e56 100644--- a/backend/plugin/advisor/mysql/test/naming_index_uk.yaml+++ b/backend/plugin/advisor/mysql/test/naming_index_uk.yaml@@ -19,13 +19,13 @@- status: WARNcode: 304title: naming.index.uk- content: Unique key in table `tech_book` mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy`+ content: Unique key `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy` in table `tech_book` mismatches the naming convention, its length should be within 64 charactersline: 2details: ""- status: WARNcode: 304title: naming.index.uk- content: Unique key `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy` in table `tech_book` mismatches the naming convention, its length should be within 64 characters+ content: Unique key in table `tech_book` mismatches the naming convention, expect "^$|^uk_tech_book_id_name$" but found `qtzmquwvlnttctfluoouxelxeliltcfzzstrtyocogwwyiyrflmrkbhbfasynlacy`line: 2details: ""- statement: ALTER TABLE tech_book ADD UNIQUE uk_tech_book_id_name (id, name)diff --git a/backend/plugin/advisor/mysql/test/naming_table.yaml b/backend/plugin/advisor/mysql/test/naming_table.yamlindex d7678b4175..c6990b158a 100644--- a/backend/plugin/advisor/mysql/test/naming_table.yaml+++ b/backend/plugin/advisor/mysql/test/naming_table.yaml@@ -51,13 +51,13 @@- status: WARNcode: 301title: naming.table- content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'line: 2details: ""- status: WARNcode: 301title: naming.table- content: '`LiteraryBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'+ content: '`TechBook` mismatches table naming convention, naming format should be "^[a-z]+(_[a-z]+)*$"'line: 2details: ""- statement: CREATE TABLE literary_book(a int);RENAME TABLE tech_book TO tech_book_copy, literary_book TO literary_book_copydiff --git a/backend/plugin/advisor/oracle/test/naming_identifier_no_keyword.yaml b/backend/plugin/advisor/oracle/test/naming_identifier_no_keyword.yamlindex 8d119ee2e5..4738505d42 100644--- a/backend/plugin/advisor/oracle/test/naming_identifier_no_keyword.yaml+++ b/backend/plugin/advisor/oracle/test/naming_identifier_no_keyword.yaml@@ -3,13 +3,13 @@- status: WARNcode: 308title: naming.identifier.no-keyword- content: Identifier "table" is a keyword and should be avoided+ content: Identifier "NAME" is a keyword and should be avoidedline: 1details: ""- status: WARNcode: 308title: naming.identifier.no-keyword- content: Identifier "NAME" is a keyword and should be avoided+ content: Identifier "table" is a keyword and should be avoidedline: 1details: ""- statement: CREATE TABLE "rlcmidzlevbivwvcntihenpoibtsdfasdfasdfiutqeb"(id int, name varchar(255))diff --git a/backend/plugin/advisor/utils_for_tests.go b/backend/plugin/advisor/utils_for_tests.goindex a395e1484a..5a31370394 100644--- a/backend/plugin/advisor/utils_for_tests.go+++ b/backend/plugin/advisor/utils_for_tests.go@@ -14,6 +14,7 @@ import ("github.com/pkg/errors""github.com/stretchr/testify/require"+ "golang.org/x/exp/slices""gopkg.in/yaml.v3""github.com/bytebase/bytebase/backend/plugin/advisor/catalog"@@ -185,6 +186,13 @@ func RunSQLReviewRuleTest(t *testing.T, rule SQLReviewRuleType, dbType db.Type,}adviceList, err := SQLReviewCheck(tc.Statement, ruleList, ctx)+ // Sort adviceList by (line, content)+ slices.SortFunc[Advice](adviceList, func(i, j Advice) bool {+ if i.Line != j.Line {+ return i.Line < j.Line+ }+ return i.Content < j.Content+ })require.NoError(t, err)if record {tests[i].Want = adviceList