@@ -236,7 +236,12 @@ func mySQLDoBackup(
236236 time .Sleep (1 * time .Second )
237237
238238 // create table for test data
239- _ , err = db .Exec (fmt .Sprintf ("CREATE TABLE %s(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY ( id ));" , tableName ))
239+ _ , err = db .Exec (
240+ fmt .Sprintf (
241+ "CREATE TABLE %s(id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY ( id ));" ,
242+ tableName ,
243+ ),
244+ )
240245 if err != nil {
241246 return []TestStruct {}, err
242247 }
@@ -248,7 +253,13 @@ func mySQLDoBackup(
248253 }
249254
250255 // create brudi config for mysqldump
251- MySQLBackupConfig := createMySQLConfig (mySQLBackupTarget , useRestic , resticContainer .Address , resticContainer .Port , path )
256+ MySQLBackupConfig := createMySQLConfig (
257+ mySQLBackupTarget ,
258+ useRestic ,
259+ resticContainer .Address ,
260+ resticContainer .Port ,
261+ path ,
262+ )
252263 err = viper .ReadConfig (bytes .NewBuffer (MySQLBackupConfig ))
253264 if err != nil {
254265 return []TestStruct {}, err
@@ -280,7 +291,13 @@ func mySQLDoRestore(
280291 }()
281292
282293 // create a brudi config for mysql restore
283- MySQLRestoreConfig := createMySQLConfig (mySQLRestoreTarget , useRestic , resticContainer .Address , resticContainer .Port , path )
294+ MySQLRestoreConfig := createMySQLConfig (
295+ mySQLRestoreTarget ,
296+ useRestic ,
297+ resticContainer .Address ,
298+ resticContainer .Port ,
299+ path ,
300+ )
284301 err = viper .ReadConfig (bytes .NewBuffer (MySQLRestoreConfig ))
285302 if err != nil {
286303 return []TestStruct {}, err
@@ -408,19 +425,28 @@ func prepareTestData(database *sql.DB) ([]TestStruct, error) {
408425 }
409426 testData := []TestStruct {testStruct1 }
410427 var insert * sql.Rows
428+ defer func () {
429+ err = insert .Close ()
430+ if err != nil {
431+ log .WithError (err ).Error ("failed to close insert" )
432+ }
433+ }()
411434 for idx := range testData {
412- insert , err = database .Query (fmt .Sprintf ("INSERT INTO %s VALUES ( %d, '%s' )" , tableName , testData [idx ].ID , testData [idx ].Name ))
435+ insert , err = database .Query (
436+ fmt .Sprintf (
437+ "INSERT INTO %s VALUES ( %d, '%s' )" ,
438+ tableName ,
439+ testData [idx ].ID ,
440+ testData [idx ].Name ,
441+ ),
442+ )
413443 if err != nil {
414444 return []TestStruct {}, err
415445 }
416446 if insert .Err () != nil {
417447 return []TestStruct {}, insert .Err ()
418448 }
419449 }
420- err = insert .Close ()
421- if err != nil {
422- return []TestStruct {}, err
423- }
424450 return testData , nil
425451}
426452
0 commit comments