Skip to content

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

test: fix unit tests (#14111)

rebelice99b2945fb269
diff --git a/backend/plugin/parser/mysql/completion_test.go b/backend/plugin/parser/mysql/completion_test.go
index 6475af687f..6b31aaf380 100644
--- a/backend/plugin/parser/mysql/completion_test.go
+++ b/backend/plugin/parser/mysql/completion_test.go
@@ -4,6 +4,7 @@ import (
"context"
"io"
"os"
+ "sort"
"testing"
"github.com/stretchr/testify/require"
@@ -56,6 +57,16 @@ 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
} else {
diff --git a/backend/plugin/parser/mysql/test-data/test_completion.yaml b/backend/plugin/parser/mysql/test-data/test_completion.yaml
index 08111345a7..7a888976d2 100644
--- a/backend/plugin/parser/mysql/test-data/test_completion.yaml
+++ b/backend/plugin/parser/mysql/test-data/test_completion.yaml
@@ -20,6 +20,10 @@
comment: ""
- input: INSERT INTO t1(|);
want:
+ - text: c1
+ type: COLUMN
+ definition: t1 | , NOT NULL
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -32,16 +36,20 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: t1 | , NOT NULL
- comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: INSERT INTO t2(c1, |);
want:
+ - text: c1
+ type: COLUMN
+ definition: t2 | , NOT NULL
+ comment: ""
+ - text: c2
+ type: COLUMN
+ definition: t2 | , NOT NULL
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -54,14 +62,6 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: t2 | , NOT NULL
- comment: ""
- - text: c2
- type: COLUMN
- definition: t2 | , NOT NULL
- comment: ""
- text: v1
type: VIEW
definition: ""
@@ -78,6 +78,14 @@
comment: ""
- input: WITH x(x1, x2) AS (SELECT * FROM t2) SELECT | FROM x
want:
+ - text: x1
+ type: COLUMN
+ definition: ""
+ comment: ""
+ - text: x2
+ type: COLUMN
+ definition: ""
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -94,32 +102,12 @@
type: TABLE
definition: ""
comment: ""
- - text: x1
- type: COLUMN
- definition: ""
- comment: ""
- - text: x2
- type: COLUMN
- definition: ""
- comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |
want:
- - text: db
- type: DATABASE
- definition: ""
- comment: ""
- - text: t1
- type: TABLE
- definition: ""
- comment: ""
- - text: t2
- type: TABLE
- definition: ""
- comment: ""
- text: c1
type: COLUMN
definition: t2 | , NOT NULL
@@ -136,12 +124,6 @@
type: COLUMN
definition: ""
comment: ""
- - text: v1
- type: VIEW
- definition: ""
- comment: ""
-- input: SELECT c1 as eid FROM t1 ORDER BY |
- want:
- text: db
type: DATABASE
definition: ""
@@ -154,6 +136,12 @@
type: TABLE
definition: ""
comment: ""
+ - text: v1
+ type: VIEW
+ definition: ""
+ comment: ""
+- input: SELECT c1 as eid FROM t1 ORDER BY |
+ want:
- text: c1
type: COLUMN
definition: t1 | , NOT NULL
@@ -162,12 +150,28 @@
type: COLUMN
definition: ""
comment: ""
+ - text: db
+ type: DATABASE
+ definition: ""
+ comment: ""
+ - text: t1
+ type: TABLE
+ definition: ""
+ comment: ""
+ - text: t2
+ type: TABLE
+ definition: ""
+ comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: SELECT FROM basdkfjasldf;SELECT | FROM t1
want:
+ - text: c1
+ type: COLUMN
+ definition: t1 | , NOT NULL
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -180,16 +184,16 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: t1 | , NOT NULL
- comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: SELECT | FROM (SELECT c1 FROM t1) cc1(cc1c1)
want:
+ - text: cc1c1
+ type: COLUMN
+ definition: ""
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -206,16 +210,16 @@
type: TABLE
definition: ""
comment: ""
- - text: cc1c1
- type: COLUMN
- definition: ""
- comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: SELECT | FROM (SELECT c1 FROM t1) cc1
want:
+ - text: c1
+ type: COLUMN
+ definition: ""
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -232,10 +236,6 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: ""
- comment: ""
- text: v1
type: VIEW
definition: ""
@@ -276,6 +276,10 @@
comment: ""
- input: SELECT | FROM t1
want:
+ - text: c1
+ type: COLUMN
+ definition: t1 | , NOT NULL
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -288,16 +292,20 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: t1 | , NOT NULL
- comment: ""
- text: v1
type: VIEW
definition: ""
comment: ""
- input: SELECT | FROM t2 x
want:
+ - text: c1
+ type: COLUMN
+ definition: t2 | , NOT NULL
+ comment: ""
+ - text: c2
+ type: COLUMN
+ definition: t2 | , NOT NULL
+ comment: ""
- text: db
type: DATABASE
definition: ""
@@ -314,14 +322,6 @@
type: TABLE
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: t2 | , NOT NULL
- comment: ""
- - text: c2
- type: COLUMN
- definition: t2 | , NOT NULL
- comment: ""
- text: v1
type: VIEW
definition: ""
diff --git a/backend/plugin/parser/pg/completion_test.go b/backend/plugin/parser/pg/completion_test.go
index db34275f12..58eb31b3d4 100644
--- a/backend/plugin/parser/pg/completion_test.go
+++ b/backend/plugin/parser/pg/completion_test.go
@@ -4,6 +4,7 @@ import (
"context"
"io"
"os"
+ "sort"
"testing"
"github.com/stretchr/testify/require"
@@ -56,6 +57,16 @@ 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
} else {
diff --git a/backend/plugin/parser/pg/test-data/test_completion.yaml b/backend/plugin/parser/pg/test-data/test_completion.yaml
index d3cf82c851..b1f01dd538 100644
--- a/backend/plugin/parser/pg/test-data/test_completion.yaml
+++ b/backend/plugin/parser/pg/test-data/test_completion.yaml
@@ -50,6 +50,14 @@
comment: ""
- input: WITH x(x1, x2) AS (SELECT * FROM t2) SELECT | FROM x
want:
+ - text: x1
+ type: COLUMN
+ definition: ""
+ comment: ""
+ - text: x2
+ type: COLUMN
+ definition: ""
+ comment: ""
- text: public
type: SCHEMA
definition: ""
@@ -70,16 +78,24 @@
type: VIEW
definition: ""
comment: ""
- - text: x1
+- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |
+ want:
+ - text: c1
+ type: COLUMN
+ definition: public.t2 | int, NOT NULL
+ comment: ""
+ - text: c2
+ type: COLUMN
+ definition: public.t2 | int, NOT NULL
+ comment: ""
+ - text: eid
type: COLUMN
definition: ""
comment: ""
- - text: x2
+ - text: xid
type: COLUMN
definition: ""
comment: ""
-- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |
- want:
- text: public
type: SCHEMA
definition: ""
@@ -96,24 +112,16 @@
type: VIEW
definition: ""
comment: ""
+- input: SELECT c1 as eid FROM t1 ORDER BY |
+ want:
- text: c1
type: COLUMN
- definition: public.t2 | int, NOT NULL
- comment: ""
- - text: c2
- type: COLUMN
- definition: public.t2 | int, NOT NULL
+ definition: public.t1 | int, NOT NULL
comment: ""
- text: eid
type: COLUMN
definition: ""
comment: ""
- - text: xid
- type: COLUMN
- definition: ""
- comment: ""
-- input: SELECT c1 as eid FROM t1 ORDER BY |
- want:
- text: public
type: SCHEMA
definition: ""
@@ -130,16 +138,12 @@
type: VIEW
definition: ""
comment: ""
+- input: SELECT FROM basdkfjasldf;SELECT | FROM t1
+ want:
- text: c1
type: COLUMN
definition: public.t1 | int, NOT NULL
comment: ""
- - text: eid
- type: COLUMN
- definition: ""
- comment: ""
-- input: SELECT FROM basdkfjasldf;SELECT | FROM t1
- want:
- text: public
type: SCHEMA
definition: ""
@@ -156,12 +160,12 @@
type: VIEW
definition: ""
comment: ""
+- input: SELECT | FROM (SELECT c1 FROM t1) cc1
+ want:
- text: c1
type: COLUMN
- definition: public.t1 | int, NOT NULL
+ definition: ""
comment: ""
-- input: SELECT | FROM (SELECT c1 FROM t1) cc1
- want:
- text: public
type: SCHEMA
definition: ""
@@ -182,10 +186,6 @@
type: VIEW
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: ""
- comment: ""
- input: SELECT cc1.| FROM t1 cc1 JOIN t2 on NOT cc1.c1 = t2.c1
want:
- text: c1
@@ -248,6 +248,10 @@
comment: ""
- input: SELECT | FROM t1 x
want:
+ - text: c1
+ type: COLUMN
+ definition: public.t1 | int, NOT NULL
+ comment: ""
- text: public
type: SCHEMA
definition: ""
@@ -268,12 +272,12 @@
type: VIEW
definition: ""
comment: ""
+- input: SELECT | FROM public.t1
+ want:
- text: c1
type: COLUMN
definition: public.t1 | int, NOT NULL
comment: ""
-- input: SELECT | FROM public.t1
- want:
- text: public
type: SCHEMA
definition: ""
@@ -290,7 +294,3 @@
type: VIEW
definition: ""
comment: ""
- - text: c1
- type: COLUMN
- definition: public.t1 | int, NOT NULL
- comment: ""
diff --git a/backend/plugin/parser/plsql/completion_test.go b/backend/plugin/parser/plsql/completion_test.go
index 19ab87f446..2463cf1717 100644
--- a/backend/plugin/parser/plsql/completion_test.go
+++ b/backend/plugin/parser/plsql/completion_test.go
@@ -4,6 +4,7 @@ import (
"context"
"io"
"os"
+ "sort"
"testing"
"github.com/stretchr/testify/require"
@@ -56,6 +57,16 @@ 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
} else {
diff --git a/backend/plugin/parser/plsql/test-data/test_completion.yaml b/backend/plugin/parser/plsql/test-data/test_completion.yaml
index 5bda6a66ee..6c25206f75 100644
--- a/backend/plugin/parser/plsql/test-data/test_completion.yaml
+++ b/backend/plugin/parser/plsql/test-data/test_completion.yaml
@@ -58,6 +58,14 @@
comment: ""
- input: WITH x(x1, x2) AS (SELECT * FROM t2) SELECT | FROM x
want:
+ - text: X1
+ type: COLUMN
+ definition: ""
+ comment: ""
+ - text: X2
+ type: COLUMN
+ definition: ""
+ comment: ""
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -82,20 +90,28 @@
type: TABLE
definition: ""
comment: ""
- - text: X1
- type: COLUMN
+ - text: V1
+ type: VIEW
definition: ""
comment: ""
- - text: X2
+- input: SELECT c1 as eid, c2 as xid FROM t2 GROUP BY |
+ want:
+ - text: C1
+ type: COLUMN
+ definition: SCHEMA1.T2 | int, NOT NULL
+ comment: ""
+ - text: C2
+ type: COLUMN
+ definition: SCHEMA1.T2 | int, NOT NULL
+ comment: ""
+ - text: EID
type: COLUMN
definition: ""
comment: ""
- - text: V1
- type: VIEW
+ - text: XID
+ type: COLUMN
definition: ""
comment: ""
-- input: SELECT c1 as eid, c2 as xid FROM t2 GROUP BY |
- want:
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -116,6 +132,12 @@
type: TABLE
definition: ""
comment: ""
+ - text: V1
+ type: VIEW
+ definition: ""
+ comment: ""
+- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |
+ want:
- text: C1
type: COLUMN
definition: SCHEMA1.T2 | int, NOT NULL
@@ -132,12 +154,6 @@
type: COLUMN
definition: ""
comment: ""
- - text: V1
- type: VIEW
- definition: ""
- comment: ""
-- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |
- want:
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -158,28 +174,20 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T2 | int, NOT NULL
+ - text: V1
+ type: VIEW
+ definition: ""
comment: ""
- - text: C2
+- input: SELECT c1 as eid FROM t1 ORDER BY |
+ want:
+ - text: C1
type: COLUMN
- definition: SCHEMA1.T2 | int, NOT NULL
+ definition: SCHEMA1.T1 | int, NOT NULL
comment: ""
- text: EID
type: COLUMN
definition: ""
comment: ""
- - text: XID
- type: COLUMN
- definition: ""
- comment: ""
- - text: V1
- type: VIEW
- definition: ""
- comment: ""
-- input: SELECT c1 as eid FROM t1 ORDER BY |
- want:
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -200,14 +208,6 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T1 | int, NOT NULL
- comment: ""
- - text: EID
- type: COLUMN
- definition: ""
- comment: ""
- text: V1
type: VIEW
definition: ""
@@ -216,6 +216,10 @@
SELECT FROM basdkfjasldf;
SELECT | FROM t1
want:
+ - text: C1
+ type: COLUMN
+ definition: SCHEMA1.T1 | int, NOT NULL
+ comment: ""
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -236,16 +240,20 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T1 | int, NOT NULL
- comment: ""
- text: V1
type: VIEW
definition: ""
comment: ""
- input: SELECT | FROM (SELECT c1 FROM t1) cc1
want:
+ - text: C1
+ type: COLUMN
+ definition: ""
+ comment: ""
+ - text: C1
+ type: COLUMN
+ definition: SCHEMA1.T1 | int, NOT NULL
+ comment: ""
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -270,14 +278,6 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: ""
- comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T1 | int, NOT NULL
- comment: ""
- text: V1
type: VIEW
definition: ""
@@ -352,6 +352,10 @@
comment: ""
- input: SELECT | FROM t1 x
want:
+ - text: C1
+ type: COLUMN
+ definition: SCHEMA1.T1 | int, NOT NULL
+ comment: ""
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -376,16 +380,16 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T1 | int, NOT NULL
- comment: ""
- text: V1
type: VIEW
definition: ""
comment: ""
- input: SELECT | FROM schema1.t1
want:
+ - text: C1
+ type: COLUMN
+ definition: SCHEMA1.T1 | int, NOT NULL
+ comment: ""
- text: SCHEMA1
type: SCHEMA
definition: ""
@@ -406,10 +410,6 @@
type: TABLE
definition: ""
comment: ""
- - text: C1
- type: COLUMN
- definition: SCHEMA1.T1 | int, NOT NULL
- comment: ""
- text: V1
type: VIEW
definition: ""