aboutsummaryrefslogtreecommitdiff
path: root/pkg/database
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--pkg/database/train_stop.go4
-rw-r--r--pkg/database/train_stop_test.go9
2 files changed, 8 insertions, 5 deletions
diff --git a/pkg/database/train_stop.go b/pkg/database/train_stop.go
index 27fb910..452f6c3 100644
--- a/pkg/database/train_stop.go
+++ b/pkg/database/train_stop.go
@@ -1,6 +1,8 @@
package database
-import "git.adyxax.org/adyxax/trains/pkg/model"
+import (
+ "git.adyxax.org/adyxax/trains/pkg/model"
+)
func (env *DBEnv) ReplaceAndImportTrainStops(trainStops []model.TrainStop) error {
pre_query := `DELETE FROM train_stops;`
diff --git a/pkg/database/train_stop_test.go b/pkg/database/train_stop_test.go
index 9ee9c03..f593d51 100644
--- a/pkg/database/train_stop_test.go
+++ b/pkg/database/train_stop_test.go
@@ -73,7 +73,7 @@ func TestReplaceAndImportTrainStopsWithSQLMock(t *testing.T) {
}
defer dbCannotInsertError.Close()
mockCannotInsertError.ExpectBegin()
- mockCannotInsertError.ExpectExec(`DELETE FROM`)
+ mockCannotInsertError.ExpectExec(`DELETE FROM`).WillReturnResult(sqlmock.NewResult(1, 1))
// Transaction commit error
dbCommitError, mockCommitError, err := sqlmock.New()
if err != nil {
@@ -81,8 +81,9 @@ func TestReplaceAndImportTrainStopsWithSQLMock(t *testing.T) {
}
defer dbCommitError.Close()
mockCommitError.ExpectBegin()
- mockCommitError.ExpectExec(`DELETE FROM`)
- mockCommitError.ExpectExec(`INSERT INTO`)
+ mockCommitError.ExpectExec(`DELETE FROM`).WillReturnResult(sqlmock.NewResult(1, 1))
+ mockCommitError.ExpectExec(`INSERT INTO`).WillReturnResult(sqlmock.NewResult(1, 1))
+ mockCommitError.ExpectExec(`INSERT INTO`).WillReturnResult(sqlmock.NewResult(1, 1))
// Test cases
testCases := []struct {
name string
@@ -92,7 +93,7 @@ func TestReplaceAndImportTrainStopsWithSQLMock(t *testing.T) {
{"begin transaction error", &DBEnv{db: dbBeginError}, &TransactionError{}},
{"query error cannot delete from", &DBEnv{db: dbCannotDeleteFrom}, &QueryError{}},
{"query error cannot insert into", &DBEnv{db: dbCannotInsertError}, &QueryError{}},
- // TODO FIX THIS TEST {"commit transaction error", &DBEnv{db: dbCommitError}, &TransactionError{}},
+ {"commit transaction error", &DBEnv{db: dbCommitError}, &TransactionError{}},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {