(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestGetSQLStatementPrefix(t *testing.T) { |
| 18 | tests := []struct { |
| 19 | engine storepb.Engine |
| 20 | resourceList []base.SchemaResource |
| 21 | columnNames []string |
| 22 | want string |
| 23 | }{ |
| 24 | { |
| 25 | engine: storepb.Engine_MYSQL, |
| 26 | resourceList: nil, |
| 27 | columnNames: []string{"a"}, |
| 28 | want: "INSERT INTO `<table_name>` (`a`) VALUES (", |
| 29 | }, |
| 30 | { |
| 31 | engine: storepb.Engine_MYSQL, |
| 32 | resourceList: []base.SchemaResource{{Database: "db1", Schema: "", Table: "table1"}}, |
| 33 | columnNames: []string{"a", "b"}, |
| 34 | want: "INSERT INTO `table1` (`a`,`b`) VALUES (", |
| 35 | }, |
| 36 | { |
| 37 | engine: storepb.Engine_TIDB, |
| 38 | resourceList: []base.SchemaResource{{Database: "db1", Schema: "", Table: "cbt_plans"}}, |
| 39 | columnNames: []string{"id", "app_code", "locale"}, |
| 40 | want: "INSERT INTO `cbt_plans` (`id`,`app_code`,`locale`) VALUES (", |
| 41 | }, |
| 42 | { |
| 43 | engine: storepb.Engine_POSTGRES, |
| 44 | resourceList: nil, |
| 45 | columnNames: []string{"a"}, |
| 46 | want: "INSERT INTO \"<table_name>\" (\"a\") VALUES (", |
| 47 | }, |
| 48 | { |
| 49 | engine: storepb.Engine_POSTGRES, |
| 50 | resourceList: []base.SchemaResource{{Database: "db1", Schema: "", Table: "table1"}}, |
| 51 | columnNames: []string{"a"}, |
| 52 | want: "INSERT INTO \"table1\" (\"a\") VALUES (", |
| 53 | }, |
| 54 | { |
| 55 | engine: storepb.Engine_POSTGRES, |
| 56 | resourceList: []base.SchemaResource{{Database: "db1", Schema: "schema1", Table: "table1"}}, |
| 57 | columnNames: []string{"a"}, |
| 58 | want: "INSERT INTO \"schema1\".\"table1\" (\"a\") VALUES (", |
| 59 | }, |
| 60 | } |
| 61 | a := assert.New(t) |
| 62 | |
| 63 | for _, test := range tests { |
| 64 | got, err := SQLStatementPrefix(test.engine, test.resourceList, test.columnNames) |
| 65 | a.NoError(err) |
| 66 | a.Equal(test.want, got) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestExportSQL(t *testing.T) { |
| 71 | tests := []struct { |
nothing calls this directly
no test coverage detected