Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: split large test file (#11163)

h3n4la5f055f4592e
diff --git a/backend/plugin/schema/mysql/parse_to_metadata_test.go b/backend/plugin/schema/mysql/parse_to_metadata_test.go
index b8a5da84ea..1342f1740c 100644
--- a/backend/plugin/schema/mysql/parse_to_metadata_test.go
+++ b/backend/plugin/schema/mysql/parse_to_metadata_test.go
@@ -14,46 +14,58 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
-func TestParseToMetadata(t *testing.T) {
- type transformTest struct {
- Schema string
- Metadata string
+type transformTest struct {
+ Schema string
+ Metadata string
+}
+
+func TestParseToMetadata_Partition(t *testing.T) {
+ filepaths := []string{
+ "testdata/parse-to-metadata/partition.yaml",
}
- const (
- record = false
- )
- var (
- filepath = "testdata/parse_to_metadata.yaml"
- )
- a := require.New(t)
- yamlFile, err := os.Open(filepath)
- a.NoError(err)
+ runParseToMetadataTest(t, filepaths, false)
+}
+
+func TestParseToMetadata_Standard(t *testing.T) {
+ filepaths := []string{
+ "testdata/parse-to-metadata/standard.yaml",
+ }
- tests := []transformTest{}
- byteValue, err := io.ReadAll(yamlFile)
- a.NoError(yamlFile.Close())
- a.NoError(err)
- a.NoError(yaml.Unmarshal(byteValue, &tests))
+ runParseToMetadataTest(t, filepaths, false)
+}
- for i, t := range tests {
- result, err := ParseToMetadata("", t.Schema)
+func runParseToMetadataTest(t *testing.T, filepaths []string, record bool) {
+ a := require.New(t)
+ for _, fp := range filepaths {
+ yamlFile, err := os.Open(fp)
a.NoError(err)
- if record {
- tests[i].Metadata = protojson.MarshalOptions{Multiline: true, Indent: " "}.Format(result)
- } else {
- want := &storepb.DatabaseSchemaMetadata{}
- err = protojson.Unmarshal([]byte(t.Metadata), want)
+
+ tests := []transformTest{}
+ byteValue, err := io.ReadAll(yamlFile)
+ a.NoError(yamlFile.Close())
+ a.NoError(err)
+ a.NoError(yaml.Unmarshal(byteValue, &tests))
+
+ for i, t := range tests {
+ result, err := ParseToMetadata("", t.Schema)
a.NoError(err)
- diff := cmp.Diff(want, result, protocmp.Transform())
- a.Equal("", diff)
+ if record {
+ tests[i].Metadata = protojson.MarshalOptions{Multiline: true, Indent: " "}.Format(result)
+ } else {
+ want := &storepb.DatabaseSchemaMetadata{}
+ err = protojson.Unmarshal([]byte(t.Metadata), want)
+ a.NoError(err)
+ diff := cmp.Diff(want, result, protocmp.Transform())
+ a.Equal("", diff)
+ }
}
- }
- if record {
- byteValue, err := yaml.Marshal(tests)
- a.NoError(err)
- err = os.WriteFile(filepath, byteValue, 0644)
- a.NoError(err)
+ if record {
+ byteValue, err := yaml.Marshal(tests)
+ a.NoError(err)
+ err = os.WriteFile(fp, byteValue, 0644)
+ a.NoError(err)
+ }
}
}
diff --git a/backend/plugin/schema/mysql/testdata/parse-to-metadata/partition.yaml b/backend/plugin/schema/mysql/testdata/parse-to-metadata/partition.yaml
new file mode 100644
index 0000000000..70b71bc6f6
--- /dev/null
+++ b/backend/plugin/schema/mysql/testdata/parse-to-metadata/partition.yaml
@@ -0,0 +1,220 @@
+- schema: |-
+ CREATE TABLE `range_partition` (
+ `id` INT,
+ `name` VARCHAR(45) NOT NULL,
+ PRIMARY KEY (`id`, `name`)
+ )
+ PARTITION BY RANGE COLUMNS(id, name)
+ SUBPARTITION BY HASH(id) (
+ PARTITION p0 VALUES LESS THAN (10, 'a') (
+ SUBPARTITION p0s0,
+ SUBPARTITION p0s1
+ ),
+ PARTITION p1 VALUES LESS THAN (20, 'b') (
+ SUBPARTITION p1s0,
+ SUBPARTITION p1s1
+ ),
+ PARTITION p2 VALUES LESS THAN (MAXVALUE, MAXVALUE) (
+ SUBPARTITION p2s0,
+ SUBPARTITION p2s1
+ )
+ );
+ metadata: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "range_partition",
+ "columns": [
+ {
+ "name": "id",
+ "position": 1,
+ "defaultNull": true,
+ "nullable": true,
+ "type": "INT"
+ },
+ {
+ "name": "name",
+ "position": 2,
+ "type": "VARCHAR(45)"
+ }
+ ],
+ "indexes": [
+ {
+ "name": "PRIMARY",
+ "expressions": [
+ "id",
+ "name"
+ ],
+ "keyLength": [
+ "-1",
+ "-1"
+ ],
+ "unique": true,
+ "primary": true,
+ "visible": true
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "RANGE_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "10,'a'",
+ "subpartitions": [
+ {
+ "name": "p0s0",
+ "type": "HASH",
+ "expression": "`id`"
+ },
+ {
+ "name": "p0s1",
+ "type": "HASH",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p1",
+ "type": "RANGE_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "20,'b'",
+ "subpartitions": [
+ {
+ "name": "p1s0",
+ "type": "HASH",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1s1",
+ "type": "HASH",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p2",
+ "type": "RANGE_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "MAXVALUE,MAXVALUE",
+ "subpartitions": [
+ {
+ "name": "p2s0",
+ "type": "HASH",
+ "expression": "`id`"
+ },
+ {
+ "name": "p2s1",
+ "type": "HASH",
+ "expression": "`id`"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+- schema: |-
+ CREATE TABLE `list_partition` (
+ `id` INT,
+ `name` VARCHAR(45) NOT NULL
+ )
+ PARTITION BY LIST COLUMNS(id, name)
+ SUBPARTITION BY KEY(id)
+ SUBPARTITIONS 2
+ (
+ PARTITION p0 VALUES IN (1, 'a'),
+ PARTITION p1 VALUES IN (2, 'b'),
+ PARTITION p2 VALUES IN (3, 'c')
+ );
+ metadata: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "list_partition",
+ "columns": [
+ {
+ "name": "id",
+ "position": 1,
+ "defaultNull": true,
+ "nullable": true,
+ "type": "INT"
+ },
+ {
+ "name": "name",
+ "position": 2,
+ "type": "VARCHAR(45)"
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "LIST_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "(1,'a')",
+ "subpartitions": [
+ {
+ "name": "p0sp0",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ },
+ {
+ "name": "p0sp1",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ }
+ ]
+ },
+ {
+ "name": "p1",
+ "type": "LIST_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "(2,'b')",
+ "subpartitions": [
+ {
+ "name": "p1sp0",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ },
+ {
+ "name": "p1sp1",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ }
+ ]
+ },
+ {
+ "name": "p2",
+ "type": "LIST_COLUMNS",
+ "expression": "`id`,`name`",
+ "value": "(3,'c')",
+ "subpartitions": [
+ {
+ "name": "p2sp0",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ },
+ {
+ "name": "p2sp1",
+ "type": "KEY",
+ "expression": "`id`",
+ "useDefault": "2"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
diff --git a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml b/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml
similarity index 55%
rename from backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
rename to backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml
index 9a9d6cf7ff..3a54028164 100644
--- a/backend/plugin/schema/mysql/testdata/parse_to_metadata.yaml
+++ b/backend/plugin/schema/mysql/testdata/parse-to-metadata/standard.yaml
@@ -269,224 +269,4 @@
]
}
]
- }
-- schema: |-
- CREATE TABLE `range_partition` (
- `id` INT,
- `name` VARCHAR(45) NOT NULL,
- PRIMARY KEY (`id`, `name`)
- )
- PARTITION BY RANGE COLUMNS(id, name)
- SUBPARTITION BY HASH(id) (
- PARTITION p0 VALUES LESS THAN (10, 'a') (
- SUBPARTITION p0s0,
- SUBPARTITION p0s1
- ),
- PARTITION p1 VALUES LESS THAN (20, 'b') (
- SUBPARTITION p1s0,
- SUBPARTITION p1s1
- ),
- PARTITION p2 VALUES LESS THAN (MAXVALUE, MAXVALUE) (
- SUBPARTITION p2s0,
- SUBPARTITION p2s1
- )
- );
- metadata: |-
- {
- "schemas": [
- {
- "tables": [
- {
- "name": "range_partition",
- "columns": [
- {
- "name": "id",
- "position": 1,
- "defaultNull": true,
- "nullable": true,
- "type": "INT"
- },
- {
- "name": "name",
- "position": 2,
- "type": "VARCHAR(45)"
- }
- ],
- "indexes": [
- {
- "name": "PRIMARY",
- "expressions": [
- "id",
- "name"
- ],
- "keyLength": [
- "-1",
- "-1"
- ],
- "unique": true,
- "primary": true,
- "visible": true
- }
- ],
- "partitions": [
- {
- "name": "p0",
- "type": "RANGE_COLUMNS",
- "expression": "`id`,`name`",
- "value": "10,'a'",
- "subpartitions": [
- {
- "name": "p0s0",
- "type": "HASH",
- "expression": "`id`"
- },
- {
- "name": "p0s1",
- "type": "HASH",
- "expression": "`id`"
- }
- ]
- },
- {
- "name": "p1",
- "type": "RANGE_COLUMNS",
- "expression": "`id`,`name`",
- "value": "20,'b'",
- "subpartitions": [
- {
- "name": "p1s0",
- "type": "HASH",
- "expression": "`id`"
- },
- {
- "name": "p1s1",
- "type": "HASH",
- "expression": "`id`"
- }
- ]
- },
- {
- "name": "p2",
- "type": "RANGE_COLUMNS",
- "expression": "`id`,`name`",
- "value": "MAXVALUE,MAXVALUE",
- "subpartitions": [
- {
- "name": "p2s0",
- "type": "HASH",
- "expression": "`id`"
- },
- {
- "name": "p2s1",
- "type": "HASH",
- "expression": "`id`"
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- }
-- schema: |-
- CREATE TABLE `list_partition` (
- `id` INT,
- `name` VARCHAR(45) NOT NULL
- )
- PARTITION BY LIST COLUMNS(id, name)
- SUBPARTITION BY KEY(id)
- SUBPARTITIONS 2
- (
- PARTITION p0 VALUES IN (1, 'a'),
- PARTITION p1 VALUES IN (2, 'b'),
- PARTITION p2 VALUES IN (3, 'c')
- );
- metadata: |-
- {
- "schemas": [
- {
- "tables": [
- {
- "name": "list_partition",
- "columns": [
- {
- "name": "id",
- "position": 1,
- "defaultNull": true,
- "nullable": true,
- "type": "INT"
- },
- {
- "name": "name",
- "position": 2,
- "type": "VARCHAR(45)"
- }
- ],
- "partitions": [
- {
- "name": "p0",
- "type": "LIST_COLUMNS",
- "expression": "`id`,`name`",
- "value": "(1,'a')",
- "subpartitions": [
- {
- "name": "p0sp0",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- },
- {
- "name": "p0sp1",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- }
- ]
- },
- {
- "name": "p1",
- "type": "LIST_COLUMNS",
- "expression": "`id`,`name`",
- "value": "(2,'b')",
- "subpartitions": [
- {
- "name": "p1sp0",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- },
- {
- "name": "p1sp1",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- }
- ]
- },
- {
- "name": "p2",
- "type": "LIST_COLUMNS",
- "expression": "`id`,`name`",
- "value": "(3,'c')",
- "subpartitions": [
- {
- "name": "p2sp0",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- },
- {
- "name": "p2sp1",
- "type": "KEY",
- "expression": "`id`",
- "useDefault": "2"
- }
- ]
- }
- ]
- }
- ]
- }
- ]
- }
+ }
\ No newline at end of file