MockInDB mocks a model meta structure which saved in database for testing
(cwd, trainSelect, table string)
| 331 | |
| 332 | // MockInDB mocks a model meta structure which saved in database for testing |
| 333 | func MockInDB(cwd, trainSelect, table string) error { |
| 334 | m := New(cwd, trainSelect) |
| 335 | metaStr := fmt.Sprintf(`{"original_sql": "%s"}`, strings.ReplaceAll(strings.ReplaceAll(trainSelect, "\n", " "), `"`, `\"`)) |
| 336 | if e := decodeMeta(m, []byte(metaStr)); e != nil { |
| 337 | return e |
| 338 | } |
| 339 | if e := ioutil.WriteFile(path.Join(cwd, modelMetaFileName), []byte(metaStr), 0644); e != nil { |
| 340 | return e |
| 341 | } |
| 342 | return m.saveDB(database.GetTestingDBSingleton().URL(), table, database.GetSessionFromTestingDB()) |
| 343 | } |