likyh commented on code in PR #2190:
URL: https://github.com/apache/incubator-devlake/pull/2190#discussion_r897632138
##########
helpers/e2ehelper/data_flow_tester.go:
##########
@@ -71,45 +77,67 @@ func NewDataFlowTester(t *testing.T, pluginName string,
pluginMeta core.PluginMe
panic(err)
}
cfg := config.GetConfig()
+ e2eDbUrl := cfg.GetString(`E2E_DB_URL`)
+ if e2eDbUrl == `` {
+ panic(fmt.Errorf(`e2e can only run with E2E_DB_URL, please set
it in .env`))
+ }
+ cfg.Set(`DB_URL`, cfg.GetString(`E2E_DB_URL`))
db, err := runner.NewGormDb(cfg, logger.Global)
if err != nil {
panic(err)
}
return &DataFlowTester{
Cfg: cfg,
Db: db,
+ Dal: dalgorm.NewDalgorm(db),
T: t,
Name: pluginName,
Plugin: pluginMeta,
Log: logger.Global,
}
}
-// ImportCsv imports records from specified csv file into target table, note
that existing data would be deleted first.
-func (t *DataFlowTester) ImportCsv(csvRelPath string, tableName string) {
+// ImportCsvIntoRawTable imports records from specified csv file into target
table, note that existing data would be deleted first.
+func (t *DataFlowTester) ImportCsvIntoRawTable(csvRelPath string, tableName
string) {
csvIter := pluginhelper.NewCsvFileIterator(csvRelPath)
defer csvIter.Close()
- // create table if not exists
- err := t.Db.Table(tableName).AutoMigrate(&helper.RawData{})
- if err != nil {
- panic(err)
- }
- t.FlushTable(tableName)
+ t.FlushRawTable(tableName)
// load rows and insert into target table
for csvIter.HasNext() {
- // make sure
- result := t.Db.Table(tableName).Create(csvIter.Fetch())
+ toInsertValues := csvIter.Fetch()
+ // FIXME Hack code
+ if t.Db.Dialector.Name() == `postgres` {
+ toInsertValues[`data`] =
strings.Replace(toInsertValues[`data`].(string), `\`, `\\`, -1)
Review Comment:
`json.RawMessage` ?? It's another question.
Here Question is that bytes at raw tables in pg need `\\n` to insert but
only need `\n` in MySQL.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]