(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func TestGetLatestSchema(t *testing.T) { |
| 109 | tests := []struct { |
| 110 | name string |
| 111 | dbType storepb.Engine |
| 112 | instanceID string |
| 113 | databaseName string |
| 114 | ddl string |
| 115 | wantRawSchema string |
| 116 | wantDatabaseMetadata *v1pb.DatabaseMetadata |
| 117 | }{ |
| 118 | { |
| 119 | name: "MySQL", |
| 120 | dbType: storepb.Engine_MYSQL, |
| 121 | instanceID: "latest-schema-mysql", |
| 122 | databaseName: "latestSchema", |
| 123 | ddl: `CREATE TABLE book(id INT, name TEXT);`, |
| 124 | wantRawSchema: "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\n" + |
| 125 | "SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\n" + |
| 126 | "--\n" + |
| 127 | "-- Table structure for `book`\n" + |
| 128 | "--\n" + |
| 129 | "CREATE TABLE `book` (\n" + |
| 130 | " `id` int DEFAULT NULL,\n" + |
| 131 | " `name` text DEFAULT NULL\n" + |
| 132 | ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;\n\n" + |
| 133 | "SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;\n" + |
| 134 | "SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;\n", |
| 135 | wantDatabaseMetadata: &v1pb.DatabaseMetadata{ |
| 136 | Name: "instances/latest-schema-mysql/databases/latestSchema/metadata", |
| 137 | CharacterSet: "utf8mb4", |
| 138 | Collation: "utf8mb4_general_ci", |
| 139 | Schemas: []*v1pb.SchemaMetadata{ |
| 140 | { |
| 141 | Tables: []*v1pb.TableMetadata{ |
| 142 | { |
| 143 | Name: "book", |
| 144 | Engine: "InnoDB", |
| 145 | Collation: "utf8mb4_general_ci", |
| 146 | Charset: "utf8mb4", |
| 147 | DataSize: 16384, |
| 148 | Columns: []*v1pb.ColumnMetadata{ |
| 149 | { |
| 150 | Name: "id", |
| 151 | Position: 1, |
| 152 | Nullable: true, |
| 153 | HasDefault: true, |
| 154 | Default: "NULL", |
| 155 | Type: "int", |
| 156 | }, |
| 157 | { |
| 158 | Name: "name", |
| 159 | Position: 2, |
| 160 | Nullable: true, |
| 161 | Type: "text", |
| 162 | HasDefault: true, |
| 163 | Default: "NULL", |
| 164 | CharacterSet: "utf8mb4", |
| 165 | Collation: "utf8mb4_general_ci", |
nothing calls this directly
no test coverage detected