Merge pull request #214 from fnproject/issue/212

Fix app updating
This commit is contained in:
Reed Allman
2017-08-09 10:44:38 -07:00
committed by GitHub
3 changed files with 21 additions and 4 deletions

View File

@@ -206,7 +206,8 @@ func (ds *sqlStore) UpdateApp(ctx context.Context, newapp *models.App) (*models.
if n, err := res.RowsAffected(); err != nil { if n, err := res.RowsAffected(); err != nil {
return err return err
} else if n == 0 { } 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 return nil
}) })

View File

@@ -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"}) CreateApp(t, ctx, fnclient, appName, map[string]string{"A": "a"})
cfg := &apps.PatchAppsAppParams{ cfg := &apps.PatchAppsAppParams{
App: appName, App: appName,

View File

@@ -58,13 +58,29 @@ func TestApps(t *testing.T) {
DeleteApp(t, s.Context, s.Client, s.AppName) 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",
}
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`.")
}
DeleteApp(t, s.Context, s.Client, s.AppName)
})
t.Run("patch-override-app-config", func(t *testing.T) { t.Run("patch-override-app-config", func(t *testing.T) {
t.Parallel() t.Parallel()
s := SetupDefaultSuite() s := SetupDefaultSuite()
config := map[string]string{ config := map[string]string{
"A": "b", "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"] val, ok := appPayload.Payload.App.Config["A"]
if !ok { if !ok {
t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.") t.Error("Error during app config inspect: config map misses required entity `A` with value `a`.")
@@ -81,7 +97,7 @@ func TestApps(t *testing.T) {
config := map[string]string{ config := map[string]string{
"B": "b", "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"] val, ok := appPayload.Payload.App.Config["B"]
if !ok { if !ok {
t.Error("Error during app config inspect: config map misses required entity `B` with value `b`.") t.Error("Error during app config inspect: config map misses required entity `B` with value `b`.")