31 lines
726 B
Go
31 lines
726 B
Go
package services
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
)
|
|
|
|
func TestApplicationService_DeleteApplication(t *testing.T) {
|
|
db, mock, err := sqlmock.New()
|
|
if err != nil {
|
|
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
s := NewApplicationService(db)
|
|
appID := "test-app-id"
|
|
|
|
mock.ExpectExec("DELETE FROM applications WHERE id = \\$1").
|
|
WithArgs(appID).
|
|
WillReturnResult(sqlmock.NewResult(1, 1))
|
|
|
|
err = s.DeleteApplication(appID)
|
|
if err != nil {
|
|
t.Errorf("error was not expected while deleting application: %s", err)
|
|
}
|
|
|
|
if err := mock.ExpectationsWereMet(); err != nil {
|
|
t.Errorf("there were unfulfilled expectations: %s", err)
|
|
}
|
|
}
|