Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: fix unit tests (#14075)

rebelice638c1e99271a
diff --git a/backend/plugin/parser/tsql/completion_test.go b/backend/plugin/parser/tsql/completion_test.go
index dac6cea8e2..8d6f705354 100644
--- a/backend/plugin/parser/tsql/completion_test.go
+++ b/backend/plugin/parser/tsql/completion_test.go
@@ -4,6 +4,7 @@ import (
"context"
"io"
"os"
+ "sort"
"strings"
"testing"
@@ -70,6 +71,15 @@ func TestCompletion(t *testing.T) {
filteredResult = append(filteredResult, r)
}
}
+ sort.Slice(filteredResult, func(i, j int) bool {
+ if filteredResult[i].Type != filteredResult[j].Type {
+ return filteredResult[i].Type < filteredResult[j].Type
+ }
+ if filteredResult[i].Text != filteredResult[j].Text {
+ return filteredResult[i].Text < filteredResult[j].Text
+ }
+ return filteredResult[i].Definition < filteredResult[j].Definition
+ })
if record {
tests[i].Want = filteredResult
diff --git a/backend/plugin/parser/tsql/test-data/test_completion.yaml b/backend/plugin/parser/tsql/test-data/test_completion.yaml
index 8dd05ed8f2..4af280d051 100644
--- a/backend/plugin/parser/tsql/test-data/test_completion.yaml
+++ b/backend/plugin/parser/tsql/test-data/test_completion.yaml
@@ -3,6 +3,30 @@
select count(1) from t1 where id; SELECT * FROM |
select * from QRTZ_J0B_DETAILS qjd where J0B_NAME like '%gray';
want:
+ - text: EmployeeId
+ type: COLUMN
+ definition: Company.dbo.Address | int, NOT NULL
+ comment: ""
+ - text: Id
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
+ - text: Id
+ type: COLUMN
+ definition: Company.dbo.Employees | int, NOT NULL
+ comment: ""
+ - text: Name
+ type: COLUMN
+ definition: Company.dbo.Employees | varchar, NOT NULL
+ comment: ""
+ - text: SalaryUpBound
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
+ - text: Street
+ type: COLUMN
+ definition: Company.dbo.Address | varchar, NOT NULL
+ comment: ""
- text: Company
type: DATABASE
definition: ""
@@ -31,17 +55,24 @@
type: TABLE
definition: ""
comment: ""
+- description: Column alias can be used in order by clause
+ input: SELECT Id AS IdAlias, Name FROM Employees ORDER BY |;
+ want:
- text: EmployeeId
type: COLUMN
definition: Company.dbo.Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.dbo.Employees | int, NOT NULL
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ definition: Company.dbo.Employees | int, NOT NULL
+ comment: ""
+ - text: IdAlias
+ type: COLUMN
+ definition: ""
comment: ""
- text: Name
type: COLUMN
@@ -55,9 +86,6 @@
type: COLUMN
definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Column alias can be used in order by clause
- input: SELECT Id AS IdAlias, Name FROM Employees ORDER BY |;
- want:
- text: Company
type: DATABASE
definition: ""
@@ -82,37 +110,39 @@
type: TABLE
definition: ""
comment: ""
- - text: EmployeeId
- type: COLUMN
- definition: Company.dbo.Address | int, NOT NULL
- comment: ""
+- description: Table alias referenced by select item
+ input: SELECT tableAlias.| FROM Employees AS tableAlias;
+ want:
- text: Id
type: COLUMN
definition: Company.dbo.Employees | int, NOT NULL
comment: ""
- - text: Id
+ - text: Name
type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ definition: Company.dbo.Employees | varchar, NOT NULL
comment: ""
- - text: IdAlias
+- description: Full column name considering CTE
+ input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT MyCTE_01.| FROM MyCTE_01;
+ want:
+ - text: Id
type: COLUMN
definition: ""
comment: ""
- text: Name
type: COLUMN
- definition: Company.dbo.Employees | varchar, NOT NULL
+ definition: ""
comment: ""
- - text: SalaryUpBound
+- description: Full column name
+ input: SELECT | FROM Employees;
+ want:
+ - text: EmployeeId
type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ definition: Company.dbo.Address | int, NOT NULL
comment: ""
- - text: Street
+ - text: Id
type: COLUMN
- definition: Company.dbo.Address | varchar, NOT NULL
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
comment: ""
-- description: Table alias referenced by select item
- input: SELECT tableAlias.| FROM Employees AS tableAlias;
- want:
- text: Id
type: COLUMN
definition: Company.dbo.Employees | int, NOT NULL
@@ -121,20 +151,14 @@
type: COLUMN
definition: Company.dbo.Employees | varchar, NOT NULL
comment: ""
-- description: Full column name considering CTE
- input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT MyCTE_01.| FROM MyCTE_01;
- want:
- - text: Id
+ - text: SalaryUpBound
type: COLUMN
- definition: ""
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
comment: ""
- - text: Name
+ - text: Street
type: COLUMN
- definition: ""
+ definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Full column name
- input: SELECT | FROM Employees;
- want:
- text: Company
type: DATABASE
definition: ""
@@ -159,17 +183,20 @@
type: TABLE
definition: ""
comment: ""
+- description: Asterisk appearred in select item list
+ input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT |.* FROM MyCTE_01 JOIN dbo.Address ON MyCTE_01.EmployeeID = dbo.Address.EmployeeID
+ want:
- text: EmployeeId
type: COLUMN
definition: Company.dbo.Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.dbo.Employees | int, NOT NULL
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ definition: Company.dbo.Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
@@ -183,9 +210,6 @@
type: COLUMN
definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Asterisk appearred in select item list
- input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT |.* FROM MyCTE_01 JOIN dbo.Address ON MyCTE_01.EmployeeID = dbo.Address.EmployeeID
- want:
- text: Company
type: DATABASE
definition: ""
@@ -214,17 +238,35 @@
type: TABLE
definition: ""
comment: ""
+- description: Completion should not consider CTE if no schema specified
+ input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM MySchema.|
+ want:
+ - text: Id
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
+ - text: SalaryUpBound
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
+ - text: SalaryLevel
+ type: TABLE
+ definition: ""
+ comment: ""
+- description: Completion should consider CTE if no schema specified
+ input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM |
+ want:
- text: EmployeeId
type: COLUMN
definition: Company.dbo.Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.dbo.Employees | int, NOT NULL
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ definition: Company.dbo.Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
@@ -238,24 +280,6 @@
type: COLUMN
definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Completion should not consider CTE if no schema specified
- input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM MySchema.|
- want:
- - text: SalaryLevel
- type: TABLE
- definition: ""
- comment: ""
- - text: Id
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
- - text: SalaryUpBound
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
-- description: Completion should consider CTE if no schema specified
- input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM |
- want:
- text: Company
type: DATABASE
definition: ""
@@ -284,6 +308,9 @@
type: TABLE
definition: ""
comment: ""
+- description: Completion table in specify schema
+ input: SELECT * FROM dbo.|
+ want:
- text: EmployeeId
type: COLUMN
definition: Company.dbo.Address | int, NOT NULL
@@ -292,25 +319,14 @@
type: COLUMN
definition: Company.dbo.Employees | int, NOT NULL
comment: ""
- - text: Id
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
- text: Name
type: COLUMN
definition: Company.dbo.Employees | varchar, NOT NULL
comment: ""
- - text: SalaryUpBound
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
- text: Street
type: COLUMN
definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Completion table in specify schema
- input: SELECT * FROM dbo.|
- want:
- text: Address
type: TABLE
definition: ""
@@ -319,10 +335,17 @@
type: TABLE
definition: ""
comment: ""
+- description: Completion table for simple select
+ input: SELECT * FROM |
+ want:
- text: EmployeeId
type: COLUMN
definition: Company.dbo.Address | int, NOT NULL
comment: ""
+ - text: Id
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
- text: Id
type: COLUMN
definition: Company.dbo.Employees | int, NOT NULL
@@ -331,13 +354,14 @@
type: COLUMN
definition: Company.dbo.Employees | varchar, NOT NULL
comment: ""
+ - text: SalaryUpBound
+ type: COLUMN
+ definition: Company.MySchema.SalaryLevel | int, NOT NULL
+ comment: ""
- text: Street
type: COLUMN
definition: Company.dbo.Address | varchar, NOT NULL
comment: ""
-- description: Completion table for simple select
- input: SELECT * FROM |
- want:
- text: Company
type: DATABASE
definition: ""
@@ -362,27 +386,3 @@
type: TABLE
definition: ""
comment: ""
- - text: EmployeeId
- type: COLUMN
- definition: Company.dbo.Address | int, NOT NULL
- comment: ""
- - text: Id
- type: COLUMN
- definition: Company.dbo.Employees | int, NOT NULL
- comment: ""
- - text: Id
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
- - text: Name
- type: COLUMN
- definition: Company.dbo.Employees | varchar, NOT NULL
- comment: ""
- - text: SalaryUpBound
- type: COLUMN
- definition: Company.MySchema.SalaryLevel | int, NOT NULL
- comment: ""
- - text: Street
- type: COLUMN
- definition: Company.dbo.Address | varchar, NOT NULL
- comment: ""