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

Function TestActionCheckCommand

backend/tests/action_test.go:21–477  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestActionCheckCommand(t *testing.T) {
22 t.Parallel()
23
24 t.Run("ValidMigrations", func(t *testing.T) {
25 t.Parallel()
26 a := require.New(t)
27 ctx := context.Background()
28 ctl := &controller{}
29
30 ctx, err := ctl.StartServerWithExternalPg(ctx)
31 a.NoError(err)
32 defer ctl.Close(ctx)
33
34 // Create test instance and database
35 database := ctl.createTestDatabase(ctx, t)
36
37 // Create test data directory
38 testDataDir := t.TempDir()
39 validMigrationsDir := filepath.Join(testDataDir, "valid-migrations")
40 err = os.MkdirAll(validMigrationsDir, 0755)
41 a.NoError(err)
42
43 // Create a valid migration file
44 migrationContent := `CREATE TABLE users (
45 id INTEGER PRIMARY KEY AUTOINCREMENT,
46 username TEXT NOT NULL UNIQUE,
47 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
48);`
49 err = os.WriteFile(filepath.Join(validMigrationsDir, "00001_create_users.sql"), []byte(migrationContent), 0644)
50 a.NoError(err)
51
52 // Execute check command using backend test credentials
53 result, err := executeActionCommand(ctx,
54 "check",
55 "--url", ctl.rootURL,
56 "--service-account", "demo@example.com",
57 "--service-account-secret", "1024bytebase",
58 "--project", ctl.project.Name,
59 "--targets", database.Name,
60 "--file-pattern", filepath.Join(validMigrationsDir, "*.sql"),
61 "--check-release", "FAIL_ON_ERROR",
62 )
63
64 a.NoError(err, "Check command should succeed for valid migrations")
65
66 // E2E Verification for check command:
67 // The key expectation is that check validates files without modifying target databases
68
69 // Verify database was NOT modified (this is the critical check)
70 // Query database to ensure no tables were created
71 metadata, err := ctl.databaseServiceClient.GetDatabaseMetadata(ctx, connect.NewRequest(&v1pb.GetDatabaseMetadataRequest{
72 Name: database.Name + "/metadata",
73 }))
74 a.NoError(err)
75 // Verify no user tables exist (only SQLite system tables)
76 for _, schema := range metadata.Msg.Schemas {
77 for _, table := range schema.Tables {
78 a.NotEqual("users", table.Name, "Check command should not create tables")

Callers

nothing calls this directly

Calls 12

CloseMethod · 0.95
createTestDatabaseMethod · 0.95
executeActionCommandFunction · 0.85
JoinMethod · 0.80
GetDatabaseMetadataMethod · 0.65
CreateDatabaseGroupMethod · 0.65
CloseMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected