mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge pull request #347 from fnproject/fix-queries-for-mysql-pg
Split queries to make them work on Postgres and MySQL
This commit is contained in:
@@ -222,20 +222,34 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
|
||||
}
|
||||
|
||||
func (ds *sqlStore) RemoveApp(ctx context.Context, appName string) error {
|
||||
res, err := ds.db.ExecContext(ctx, ds.db.Rebind(
|
||||
`DELETE FROM apps WHERE name = ?;
|
||||
DELETE FROM logs WHERE app_name=?;
|
||||
DELETE FROM calls WHERE app_name=?;
|
||||
DELETE FROM routes WHERE app_name=?;`), appName, appName, appName, appName)
|
||||
return ds.Tx(func(tx *sqlx.Tx) error {
|
||||
res, err := tx.ExecContext(ctx, tx.Rebind(`DELETE FROM apps WHERE name=?`), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = res.RowsAffected()
|
||||
if err == sql.ErrNoRows {
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return models.ErrAppsNotFound
|
||||
}
|
||||
|
||||
deletes := []string{
|
||||
`DELETE FROM logs WHERE app_name=?`,
|
||||
`DELETE FROM calls WHERE app_name=?`,
|
||||
`DELETE FROM routes WHERE app_name=?`,
|
||||
}
|
||||
|
||||
for _, stmt := range deletes {
|
||||
_, err := tx.ExecContext(ctx, tx.Rebind(stmt), appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (ds *sqlStore) GetApp(ctx context.Context, name string) (*models.App, error) {
|
||||
query := ds.db.Rebind(`SELECT name, config FROM apps WHERE name=?`)
|
||||
|
||||
@@ -14,6 +14,9 @@ import (
|
||||
func CheckAppResponseError(t *testing.T, e error) {
|
||||
if e != nil {
|
||||
switch err := e.(type) {
|
||||
case *apps.DeleteAppsAppNotFound:
|
||||
t.Errorf("Unexpected error occurred: %v Original Location: %s", err.Payload.Error.Message, MyCaller())
|
||||
t.FailNow()
|
||||
case *apps.DeleteAppsAppDefault:
|
||||
t.Errorf("Unexpected error occurred: %v. Status code: %v Orig Location: %s", err.Payload.Error.Message, err.Code(), MyCaller())
|
||||
t.FailNow()
|
||||
|
||||
@@ -11,6 +11,20 @@ import (
|
||||
|
||||
func TestApps(t *testing.T) {
|
||||
|
||||
t.Run("delete-app-not-found-test", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
cfg := &apps.DeleteAppsAppParams{
|
||||
App: "missing-app",
|
||||
Context: s.Context,
|
||||
}
|
||||
cfg.WithTimeout(time.Second * 60)
|
||||
_, err := s.Client.Apps.DeleteAppsApp(cfg)
|
||||
if err == nil {
|
||||
t.Errorf("Error during app delete: we should get HTTP 404, but got: %s", err.Error())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("app-not-found-test", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := SetupDefaultSuite()
|
||||
|
||||
Reference in New Issue
Block a user