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

Function TestCreateDatabaseGroup

backend/tests/grouping_change_test.go:21–183  ·  view source on GitHub ↗

TestCreateDatabaseGroup tests creating database and verify the grouping result. For each test case: 1. The test provides a number of sqlite instances equal to the number of prepareInstances and creates the specified matchDatabase and unmatchedDatabase in the corresponding instances. 2. The database

(t *testing.T)

Source from the content-addressed store, hash-verified

19// 2. The database group is then created with the specified expr.
20// 3. The results obtained are compared with the results given in prepareInstance and they should be consistent.
21func TestCreateDatabaseGroup(t *testing.T) {
22 t.Parallel()
23 type testCasePrepareInstance struct {
24 instanceTitle string
25 matchedDatabasesName map[string]any
26 }
27 testCases := []struct {
28 name string
29 databaseGroupPlaceholder string
30 databaseGroupExpr string
31 prepareInstances []testCasePrepareInstance
32 }{
33 {
34 name: "all-matched-one-instance",
35 databaseGroupPlaceholder: "all-matched-one-instance",
36 databaseGroupExpr: `(resource.database_name.startsWith("employee_"))`,
37 prepareInstances: []testCasePrepareInstance{
38 {
39 instanceTitle: "TestCreateDatabaseGroups_AllMatched_OneInstance",
40 matchedDatabasesName: map[string]any{
41 "employee_01": nil,
42 "employee_02": nil,
43 },
44 },
45 },
46 },
47 {
48 name: "partial-matched-one-instance",
49 databaseGroupPlaceholder: "partial-matched-one-instance",
50 databaseGroupExpr: `(resource.database_name.startsWith("employee_"))`,
51 prepareInstances: []testCasePrepareInstance{
52 {
53 instanceTitle: "TestCreateDatabaseGroups_PartialMatched_OneInstance",
54 matchedDatabasesName: map[string]any{
55 "employee_01": nil,
56 "employee_02": nil,
57 },
58 },
59 },
60 },
61 {
62 name: "all-matched-many-instances",
63 databaseGroupPlaceholder: "all-matched-many-instances",
64 databaseGroupExpr: `(resource.database_name.startsWith("employee_"))`,
65 prepareInstances: []testCasePrepareInstance{
66 {
67 instanceTitle: "TestCreateDatabaseGroups_AllMatched_ManyInstances_01",
68 matchedDatabasesName: map[string]any{
69 "employee_01": nil,
70 "employee_02": nil,
71 },
72 },
73 {
74 instanceTitle: "TestCreateDatabaseGroups_AllMatched_ManyInstances_02",
75 matchedDatabasesName: map[string]any{
76 "employee_02": nil,
77 "employee_03": nil,
78 "employee_04": nil,

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
createDatabaseMethod · 0.95
generateRandomStringFunction · 0.85
NameMethod · 0.65
CreateInstanceMethod · 0.65
CreateDatabaseGroupMethod · 0.65
GetDatabaseGroupMethod · 0.65
EqualMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected