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)
| 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. |
| 21 | func 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, |
nothing calls this directly
no test coverage detected