MCPcopy Index your code
hub / github.com/bytebase/bytebase / TestSQLReviewForPostgreSQL

Function TestSQLReviewForPostgreSQL

backend/tests/sql_review_test.go:62–199  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestSQLReviewForPostgreSQL(t *testing.T) {
63 const (
64 record = false
65 )
66 var (
67 filepath = filepath.Join("test-data", "sql_review_pg.yaml")
68 statements = []string{
69 `CREATE TABLE "user"(
70 id INT,
71 name VARCHAR(255) NOT NULL,
72 room_id INT NOT NULL,
73 creator_id INT NOT NULL,
74 created_ts TIMESTAMP NOT NULL,
75 updater_id INT NOT NULL,
76 updated_ts TIMESTAMP NOT NULL,
77 CONSTRAINT pk_user_id PRIMARY KEY (id),
78 CONSTRAINT uk_user_id_name UNIQUE (id, name)
79 );
80 COMMENT ON TABLE "user" IS 'comment';`,
81 `CREATE TABLE "userTable"(
82 id INT,
83 name VARCHAR(255),
84 "roomId" INT,
85 CONSTRAINT uk1 UNIQUE (id, name),
86 CONSTRAINT fk1 FOREIGN KEY ("roomId") REFERENCES room(id)
87 );
88 COMMENT ON TABLE "userTable" IS 'comment';`,
89 }
90 databaseName = "testsqlreview"
91 )
92
93 t.Parallel()
94 a := require.New(t)
95 ctx := context.Background()
96 ctl := &controller{}
97 tests, err := readTestData(filepath)
98 a.NoError(err)
99 ctx, err = ctl.StartServerWithExternalPg(ctx)
100 a.NoError(err)
101 defer ctl.Close(ctx)
102
103 pgContainer, err := getPgContainer(ctx)
104 defer func() {
105 pgContainer.Close(ctx)
106 }()
107 a.NoError(err)
108
109 pgDB := pgContainer.db
110 err = pgDB.Ping()
111 a.NoError(err)
112
113 _, err = pgDB.Exec(fmt.Sprintf("DROP DATABASE IF EXISTS %v", databaseName))
114 a.NoError(err)
115 _, err = pgDB.Exec("CREATE USER bytebase WITH ENCRYPTED PASSWORD 'bytebase'")
116 a.NoError(err)
117 _, err = pgDB.Exec("ALTER USER bytebase WITH SUPERUSER")
118 a.NoError(err)
119

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
createDatabaseMethod · 0.95
readTestDataFunction · 0.85
getPgContainerFunction · 0.85
generateRandomStringFunction · 0.85
equalReviewResultProtosFunction · 0.85
writeTestDataFunction · 0.85
JoinMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected