Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: optimize integration tests (#3888)
Danny Xue6c26e1167f6
diff --git a/bin/server/cmd/profile_dev.go b/bin/server/cmd/profile_dev.goindex 8b19714620..07f1d34613 100644--- a/bin/server/cmd/profile_dev.go+++ b/bin/server/cmd/profile_dev.go@@ -16,6 +16,7 @@ func activeProfile(dataDir string) config.Profile {p.PgUser = "bbdev"p.DataDir = dataDirp.BackupRunnerInterval = 10 * time.Second+ p.AppRunnerInterval = 30 * time.Secondp.MetricConnectionKey = "3zcZLeX3ahvlueEJqNyJysGfVAErsjjT"return p}diff --git a/bin/server/cmd/profile_release.go b/bin/server/cmd/profile_release.goindex eb377db5dd..aaa607a6a6 100644--- a/bin/server/cmd/profile_release.go+++ b/bin/server/cmd/profile_release.go@@ -16,6 +16,7 @@ func activeProfile(dataDir string) config.Profile {p.PgUser = "bb"p.DataDir = dataDirp.BackupRunnerInterval = 10 * time.Minute+ p.AppRunnerInterval = 30 * time.Secondp.MetricConnectionKey = "so9lLwj5zLjH09sxNabsyVNYSsAHn68F"return p}diff --git a/server/component/config/profile.go b/server/component/config/profile.goindex 74307828d8..912a957723 100644--- a/server/component/config/profile.go+++ b/server/component/config/profile.go@@ -35,6 +35,8 @@ type Profile struct {Demo bool// DemoDataDir points to where to populate the initial data.DemoDataDir string+ // AppRunnerInterval is the interval for application runner.+ AppRunnerInterval time.Duration// BackupRunnerInterval is the interval for backup runner.BackupRunnerInterval time.Duration// BackupStorageBackend is the backup storage backend.diff --git a/server/runner/apprun/runner.go b/server/runner/apprun/runner.goindex 6c4ed27197..38434dc1a8 100644--- a/server/runner/apprun/runner.go+++ b/server/runner/apprun/runner.go@@ -20,10 +20,6 @@ import ("github.com/bytebase/bytebase/store")-const (- runnerInterval = time.Duration(60) * time.Second-)-// NewRunner returns a runner.func NewRunner(store *store.Store, activityManager *activity.Manager, feishuProvider *feishu.Provider, profile config.Profile) *Runner {return &Runner{@@ -44,10 +40,10 @@ type Runner struct {// Run runs the ApplicationRunner.func (r *Runner) Run(ctx context.Context, wg *sync.WaitGroup) {- ticker := time.NewTicker(runnerInterval)+ ticker := time.NewTicker(r.profile.AppRunnerInterval)defer ticker.Stop()defer wg.Done()- log.Debug(fmt.Sprintf("Application runner started and will run every %v", runnerInterval))+ log.Debug(fmt.Sprintf("Application runner started and will run every %v", r.profile.AppRunnerInterval))// Try to update approval definition if external approval is enabled, because our approval definition may have changed.if err := r.tryUpdateApprovalDefinition(ctx); err != nil {log.Error("failed to update approval definition on application runner start", zap.Error(err))diff --git a/store/demo/prod/10000##reset.sql b/store/demo/prod/10000##reset.sqlindex 6e74825595..8da14801c0 100644--- a/store/demo/prod/10000##reset.sql+++ b/store/demo/prod/10000##reset.sql@@ -1,9 +1,13 @@-- For testing, we reset data on each run--- Do not reset bb.auth.secret so that we don't need to re-login after restart+-- Do not reset bb.auth.secret so that we don't need to re-login after restart.+-- Do not reset bb.enterprise.license so that the dev license is preserved after restart.DELETE FROMsettingWHERE- name != 'bb.auth.secret';+ name != 'bb.auth.secret' AND name != 'bb.enterprise.license';+-- We have to change the creator and updater to system robot, otherwise, we will get foreign key check errors on+-- resetting principal table.+UPDATE setting SET creator_id = 1, updater_id = 1 WHERE name = 'bb.enterprise.license';DELETE FROManomaly;@@ -23,6 +27,9 @@ DELETE FROMDELETE FROMactivity;+DELETE FROM+ sheet_organizer;+DELETE FROMsheet;@@ -38,6 +45,9 @@ DELETE FROMDELETE FROMtask_run;+DELETE FROM+ task_dag;+DELETE FROMtask;diff --git a/store/demo/prod/10051##policy.sql b/store/demo/prod/10051##policy.sqlindex 69ddc01aed..f8b8eabb65 100644--- a/store/demo/prod/10051##policy.sql+++ b/store/demo/prod/10051##policy.sql@@ -3,7 +3,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -12,6 +13,7 @@ VALUES5101,101,101,+ 'ENVIRONMENT',5001,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_NEVER"}'@@ -22,7 +24,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -31,6 +34,7 @@ VALUES5102,101,101,+ 'ENVIRONMENT',5002,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_NEVER"}'@@ -41,7 +45,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -50,6 +55,7 @@ VALUES5103,101,101,+ 'ENVIRONMENT',5003,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_ALWAYS"}'@@ -60,7 +66,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -69,6 +76,7 @@ VALUES5104,101,101,+ 'ENVIRONMENT',5004,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_NEVER"}'@@ -79,7 +87,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -88,6 +97,7 @@ VALUES5105,101,101,+ 'ENVIRONMENT',5005,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_NEVER"}'@@ -98,7 +108,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -107,6 +118,7 @@ VALUES5106,101,101,+ 'ENVIRONMENT',5003,'bb.policy.backup-plan','{"schedule":"WEEKLY"}'@@ -117,7 +129,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -126,6 +139,7 @@ VALUES5107,101,101,+ 'ENVIRONMENT',5004,'bb.policy.backup-plan','{"schedule":"DAILY"}'@@ -137,7 +151,8 @@ INSERT INTOid,creator_id,updater_id,- environment_id,+ resource_type,+ resource_id,type,payload)@@ -146,11 +161,12 @@ VALUES5108,101,101,+ 'ENVIRONMENT',5004,'bb.policy.pipeline-approval','{"value":"MANUAL_APPROVAL_ALWAYS"}')- ON CONFLICT(environment_id, type) DO UPDATE SET+ ON CONFLICT(resource_type, resource_id, type) DO UPDATE SETpayload = excluded.payload;ALTER SEQUENCE policy_id_seq RESTART WITH 5109;diff --git a/store/demo/prod/10061#instance_user.sql b/store/demo/prod/10061##instance_user.sqlsimilarity index 100%rename from store/demo/prod/10061#instance_user.sqlrename to store/demo/prod/10061##instance_user.sqldiff --git a/store/demo/prod/10111##task_dag.sql b/store/demo/prod/10111##task_dag.sqlnew file mode 100644index 0000000000..1bcd701318--- /dev/null+++ b/store/demo/prod/10111##task_dag.sql@@ -0,0 +1 @@+ALTER SEQUENCE task_dag_id_seq RESTART WITH 11101;diff --git a/store/demo/prod/10130##issue.sql b/store/demo/prod/10130##issue.sqlindex d15b494c2d..e05fb1e987 100644--- a/store/demo/prod/10130##issue.sql+++ b/store/demo/prod/10130##issue.sql@@ -274,4 +274,4 @@ VALUES102);-ALTER SEQUENCE issue_id_seq RESTART WITH 13010;+ALTER SEQUENCE issue_id_seq RESTART WITH 13012;diff --git a/store/demo/prod/10180##repository.sql b/store/demo/prod/10180##repository.sqlindex 88b2303c69..99d4daaa9f 100644--- a/store/demo/prod/10180##repository.sql+++ b/store/demo/prod/10180##repository.sql@@ -13,6 +13,7 @@ INSERT INTObase_directory,file_path_template,schema_path_template,+ sheet_path_template,external_id,external_webhook_id,webhook_url_host,@@ -36,6 +37,7 @@ VALUES'bytebase','{{ENV_NAME}}/{{DB_NAME}}##{{VERSION}}##{{TYPE}}##{{DESCRIPTION}}.sql','{{ENV_NAME}}/.{{DB_NAME}}##LATEST.sql',+ 'script/{{NAME}}.sql',-- Refers to the bytebase-demo/blog'13',-- Refers to the webhook in bytebase-demo/blog@@ -62,6 +64,7 @@ INSERT INTObase_directory,file_path_template,schema_path_template,+ sheet_path_template,external_id,external_webhook_id,webhook_url_host,@@ -85,6 +88,7 @@ VALUES'bytebase','{{ENV_NAME}}/{{DB_NAME}}##{{VERSION}}##{{TYPE}}##{{DESCRIPTION}}.sql','{{ENV_NAME}}/.{{DB_NAME}}##LATEST.sql',+ 'script/{{ENV_NAME}}##{{DB_NAME}}##{{NAME}}.sql',-- Refers to the bytebase-demo/shop'14',-- Refers to the webhook in bytebase-demo/shopdiff --git a/store/demo/prod/10220##sheet.sql b/store/demo/prod/10220##sheet.sqlindex fcd1af89b7..cd3cbf7ee7 100644--- a/store/demo/prod/10220##sheet.sql+++ b/store/demo/prod/10220##sheet.sql@@ -1,4 +1,3 @@--- Sheet for principal 101 "Demo Owner"INSERT INTOsheet (id,@@ -7,7 +6,8 @@ INSERT INTOproject_id,database_id,name,- statement+ statement,+ visibility)VALUES(@@ -16,8 +16,74 @@ VALUES101,3001,7019,- 'my-sheet',- 'SELECT * FROM demo'+ 'My test cases',+ 'SELECT * FROM test_case',+ 'PRIVATE');-ALTER SEQUENCE sheet_id_seq RESTART WITH 22002;+INSERT INTO+ sheet (+ id,+ row_status,+ creator_id,+ updater_id,+ project_id,+ name,+ statement,+ visibility+ )+VALUES+ (+ 22002,+ 'ARCHIVED',+ 101,+ 101,+ 3002,+ 'My starred items',+ 'SELECT * FROM item WHERE starred=true',+ 'PRIVATE'+ );++INSERT INTO+ sheet (+ id,+ creator_id,+ updater_id,+ project_id,+ name,+ statement,+ visibility+ )+VALUES+ (+ 22003,+ 102,+ 102,+ 3002,+ 'All coupon of our shop',+ 'SELECT * FROM coupon WHERE shop_id=101',+ 'PROJECT'+ );++INSERT INTO+ sheet (+ id,+ creator_id,+ updater_id,+ project_id,+ name,+ statement,+ visibility+ )+VALUES+ (+ 22004,+ 103,+ 103,+ 3003,+ 'All blogs from Alex',+ 'SELECT * FROM blog WHERE author="Alex"',+ 'PUBLIC'+ );++ALTER SEQUENCE sheet_id_seq RESTART WITH 22005;diff --git a/store/demo/prod/10221##sheet_organizer.sql b/store/demo/prod/10221##sheet_organizer.sqlnew file mode 100644index 0000000000..f81eba639c--- /dev/null+++ b/store/demo/prod/10221##sheet_organizer.sql@@ -0,0 +1,69 @@+INSERT INTO+ sheet_organizer (+ id,+ sheet_id,+ principal_id,+ starred,+ pinned+ )+VALUES+ (+ 22101,+ 22001,+ 101,+ false,+ false+ );++INSERT INTO+ sheet_organizer (+ id,+ sheet_id,+ principal_id,+ starred,+ pinned+ )+VALUES+ (+ 22102,+ 22002,+ 101,+ true,+ false+ );++INSERT INTO+ sheet_organizer (+ id,+ sheet_id,+ principal_id,+ starred,+ pinned+ )+VALUES+ (+ 22103,+ 22003,+ 102,+ false,+ true+ );++INSERT INTO+ sheet_organizer (+ id,+ sheet_id,+ principal_id,+ starred,+ pinned+ )+VALUES+ (+ 22104,+ 22004,+ 102,+ true,+ false+ );++ALTER SEQUENCE sheet_id_seq RESTART WITH 22105;diff --git a/store/demo/schema-migration-history/10001##data.sql b/store/demo/schema-migration-history/10001##data.sqlindex e036d5e13b..236b25ccc5 100644--- a/store/demo/schema-migration-history/10001##data.sql+++ b/store/demo/schema-migration-history/10001##data.sql@@ -17,10 +17,10 @@ INSERT INTO "public"."environment" ("id", "row_status", "creator_id", "created_t(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Test', 0),(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'Prod', 1);-INSERT INTO "public"."policy" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "environment_id", "type", "payload") VALUES-(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_NEVER"}'),-(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 102, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_ALWAYS"}'),-(103, 'NORMAL', 1, 1657272778, 1, 1657272778, 102, 'bb.policy.backup-plan', '{"schedule": "WEEKLY"}');+INSERT INTO "public"."policy" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "resource_type", "resource_id", "type", "payload") VALUES+(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 101, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_NEVER"}'),+(102, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 102, 'bb.policy.pipeline-approval', '{"value": "MANUAL_APPROVAL_ALWAYS"}'),+(103, 'NORMAL', 1, 1657272778, 1, 1657272778, 'ENVIRONMENT', 102, 'bb.policy.backup-plan', '{"schedule": "WEEKLY"}');INSERT INTO "public"."instance" ("id", "row_status", "creator_id", "created_ts", "updater_id", "updated_ts", "environment_id", "name", "engine", "engine_version", "host", "port", "external_link") VALUES(101, 'NORMAL', 1, 1657272778, 1, 1657272778, 101, 'Sample Test instance', 'POSTGRES', '14.3', 'host.docker.internal', '5432', ''),diff --git a/tests/schema_update_test.go b/tests/schema_update_test.goindex a89182f72a..094238b583 100644--- a/tests/schema_update_test.go+++ b/tests/schema_update_test.go@@ -1859,19 +1859,19 @@ func postVCSSQLReview(ctl *controller, repo *api.Repository, request *api.VCSSQLfunc TestGetLatestSchema(t *testing.T) {tests := []struct {- name string- dbType db.Type- databaseName string- ddl string- wantSchema string- wantSchemaMetadata string+ name string+ dbType db.Type+ databaseName string+ ddl string+ wantRawSchema string+ wantDatabaseMetadata string}{{name: "PostgreSQL",dbType: db.Postgres,databaseName: "latestSchema",ddl: `CREATE TABLE book(id INT, name TEXT);`,- wantSchema: `SET statement_timeout = 0;+ wantRawSchema: `SET statement_timeout = 0;SET lock_timeout = 0;SET idle_in_transaction_session_timeout = 0;SET client_encoding = 'UTF8';@@ -1892,7 +1892,7 @@ CREATE TABLE public.book ();`,- wantSchemaMetadata: `{"name": "latestSchema", "schemas": [{"name": "public", "tables": [{"name": "book", "columns": [{"Type": "integer", "name": "id", "nullable": true, "position": 1, "hasDefault": true}, {"Type": "text", "name": "name", "nullable": true, "position": 2, "hasDefault": true}], "dataSize": "8192"}]}], "collation": "en_US.UTF-8", "characterSet": "UTF8"}`,+ wantDatabaseMetadata: `{"name": "latestSchema", "schemas": [{"name": "public", "tables": [{"name": "book", "columns": [{"Type": "integer", "name": "id", "nullable": true, "position": 1, "hasDefault": true}, {"Type": "text", "name": "name", "nullable": true, "position": 2, "hasDefault": true}], "dataSize": "8192"}]}], "collation": "en_US.UTF-8", "characterSet": "UTF8"}`,},}a := require.New(t)@@ -1983,10 +1983,10 @@ CREATE TABLE public.book (a.Equal(api.TaskDone, status)latestSchemaDump, err := ctl.getLatestSchemaDump(database.ID)a.NoError(err)- a.Equal(test.wantSchema, latestSchemaDump)+ a.Equal(test.wantRawSchema, latestSchemaDump)latestSchemaMetadata, err := ctl.getLatestSchemaMetadata(database.ID)a.NoError(err)- a.Equal(test.wantSchemaMetadata, latestSchemaMetadata)+ a.Equal(test.wantDatabaseMetadata, latestSchemaMetadata)})}}diff --git a/tests/tags_dev.go b/tests/tags_dev.gonew file mode 100644index 0000000000..bee174be20--- /dev/null+++ b/tests/tags_dev.go@@ -0,0 +1,8 @@+//go:build !release+// +build !release++package tests++import "github.com/bytebase/bytebase/common"++const testReleaseMode = common.ReleaseModeDevdiff --git a/tests/tags_prod.go b/tests/tags_prod.gonew file mode 100644index 0000000000..d02bcdf3e0--- /dev/null+++ b/tests/tags_prod.go@@ -0,0 +1,8 @@+//go:build release+// +build release++package tests++import "github.com/bytebase/bytebase/common"++const testReleaseMode = common.ReleaseModeProddiff --git a/tests/tests.go b/tests/tests.goindex b5935cd01e..31450bbc42 100644--- a/tests/tests.go+++ b/tests/tests.go@@ -264,7 +264,8 @@ func getTestProfile(dataDir, resourceDirOverride string, port int, feishuAPIURLPgUser: "bbtest",DataDir: dataDir,ResourceDirOverride: resourceDirOverride,- DemoDataDir: fmt.Sprintf("demo/%s", common.ReleaseModeDev),+ DemoDataDir: fmt.Sprintf("demo/%s", testReleaseMode),+ AppRunnerInterval: 1 * time.Second,BackupRunnerInterval: 10 * time.Second,BackupStorageBackend: api.BackupStorageBackendLocal,FeishuAPIURL: feishuAPIURL,@@ -281,7 +282,8 @@ func getTestProfileWithExternalPg(dataDir, resourceDirOverride string, port int,PgUser: pgUser,DataDir: dataDir,ResourceDirOverride: resourceDirOverride,- DemoDataDir: fmt.Sprintf("demo/%s", common.ReleaseModeDev),+ DemoDataDir: fmt.Sprintf("demo/%s", testReleaseMode),+ AppRunnerInterval: 1 * time.Second,BackupRunnerInterval: 10 * time.Second,BackupStorageBackend: api.BackupStorageBackendLocal,FeishuAPIURL: feishuAPIURL,