From 7a36e424d1859e9b4fa42e3b50f6a59fdcc18051 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Wed, 9 Aug 2017 14:41:23 +0300 Subject: [PATCH 1/3] Fix app updating Closes: #212 --- api/datastore/sql/sql.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/datastore/sql/sql.go b/api/datastore/sql/sql.go index f6fbd7e9d..9b4b47b71 100644 --- a/api/datastore/sql/sql.go +++ b/api/datastore/sql/sql.go @@ -206,7 +206,8 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models. if n, err := res.RowsAffected(); err != nil { return err } else if n == 0 { - return models.ErrAppsNotFound + // inside of the transaction, we are querying for the app, so we know that it exists + return nil } return nil }) From b057903feb88658e9cf3eb3a4c9b709c1f420a2e Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Wed, 9 Aug 2017 14:47:46 +0300 Subject: [PATCH 2/3] API test: patch app with the same config it has --- test/fn-api-tests/apps_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/fn-api-tests/apps_test.go b/test/fn-api-tests/apps_test.go index 62e52cfb5..5af05a520 100644 --- a/test/fn-api-tests/apps_test.go +++ b/test/fn-api-tests/apps_test.go @@ -58,6 +58,31 @@ func TestApps(t *testing.T) { DeleteApp(t, s.Context, s.Client, s.AppName) }) + t.Run("patch-app-with-exact-same-config-data", func(t *testing.T) { + t.Parallel() + s := SetupDefaultSuite() + config := map[string]string{ + "A": "a", + } + + CreateApp(t, s.Context, s.Client, s.AppName, config) + cfg := &apps.GetAppsAppParams{ + Context: s.Context, + App: s.AppName, + } + + _, err := s.Client.Apps.GetAppsApp(cfg) + CheckAppResponseError(t, err) + + appUpdatePayload := UpdateApp(t, s.Context, s.Client, s.AppName, config) + _, ok := appUpdatePayload.Payload.App.Config["A"] + if !ok { + t.Error("Error during app update: config map misses required entity `A` with value `a`.") + } + + DeleteApp(t, s.Context, s.Client, s.AppName) + }) + t.Run("patch-override-app-config", func(t *testing.T) { t.Parallel() s := SetupDefaultSuite() From 426772592b12db6707ed0e2d4d2e8d3f8e86ad7e Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Wed, 9 Aug 2017 15:09:48 +0300 Subject: [PATCH 3/3] Fixing tests --- test/fn-api-tests/apps_api.go | 2 +- test/fn-api-tests/apps_test.go | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/test/fn-api-tests/apps_api.go b/test/fn-api-tests/apps_api.go index 54f43f7f6..8ed33437b 100644 --- a/test/fn-api-tests/apps_api.go +++ b/test/fn-api-tests/apps_api.go @@ -72,7 +72,7 @@ func CreateApp(t *testing.T, ctx context.Context, fnclient *client.Functions, ap } } -func UpdateApp(t *testing.T, ctx context.Context, fnclient *client.Functions, appName string, config map[string]string) *apps.PatchAppsAppOK { +func CreateUpdateApp(t *testing.T, ctx context.Context, fnclient *client.Functions, appName string, config map[string]string) *apps.PatchAppsAppOK { CreateApp(t, ctx, fnclient, appName, map[string]string{"A": "a"}) cfg := &apps.PatchAppsAppParams{ App: appName, diff --git a/test/fn-api-tests/apps_test.go b/test/fn-api-tests/apps_test.go index 5af05a520..cec2c31ed 100644 --- a/test/fn-api-tests/apps_test.go +++ b/test/fn-api-tests/apps_test.go @@ -65,16 +65,7 @@ func TestApps(t *testing.T) { "A": "a", } - CreateApp(t, s.Context, s.Client, s.AppName, config) - cfg := &apps.GetAppsAppParams{ - Context: s.Context, - App: s.AppName, - } - - _, err := s.Client.Apps.GetAppsApp(cfg) - CheckAppResponseError(t, err) - - appUpdatePayload := UpdateApp(t, s.Context, s.Client, s.AppName, config) + appUpdatePayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config) _, ok := appUpdatePayload.Payload.App.Config["A"] if !ok { t.Error("Error during app update: config map misses required entity `A` with value `a`.") @@ -89,7 +80,7 @@ func TestApps(t *testing.T) { config := map[string]string{ "A": "b", } - appPayload := UpdateApp(t, s.Context, s.Client, s.AppName, config) + appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config) val, ok := appPayload.Payload.App.Config["A"] if !ok { t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.") @@ -106,7 +97,7 @@ func TestApps(t *testing.T) { config := map[string]string{ "B": "b", } - appPayload := UpdateApp(t, s.Context, s.Client, s.AppName, config) + appPayload := CreateUpdateApp(t, s.Context, s.Client, s.AppName, config) val, ok := appPayload.Payload.App.Config["B"] if !ok { t.Error("Error during app config inspect: config map misses required entity `B` with value `b`.")