From 8113279460e4544a4dd9d8029eb4557ba4838698 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 1 Oct 2020 21:39:35 +0200 Subject: [PATCH] [MM-28630] Add ping endpoint to local mode (#15694) --- api4/api.go | 1 + api4/system_local.go | 1 + api4/system_test.go | 33 +++++++++++++++++---------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/api4/api.go b/api4/api.go index 961f5fb3e3..6028b73d50 100644 --- a/api4/api.go +++ b/api4/api.go @@ -318,6 +318,7 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app. api.BaseRoutes.Groups = api.BaseRoutes.ApiRoot.PathPrefix("/groups").Subrouter() api.BaseRoutes.LDAP = api.BaseRoutes.ApiRoot.PathPrefix("/ldap").Subrouter() + api.BaseRoutes.System = api.BaseRoutes.ApiRoot.PathPrefix("/system").Subrouter() api.BaseRoutes.Posts = api.BaseRoutes.ApiRoot.PathPrefix("/posts").Subrouter() api.BaseRoutes.Post = api.BaseRoutes.Posts.PathPrefix("/{post_id:[A-Za-z0-9]+}").Subrouter() api.BaseRoutes.PostsForChannel = api.BaseRoutes.Channel.PathPrefix("/posts").Subrouter() diff --git a/api4/system_local.go b/api4/system_local.go index aef50fb071..2aeafe15b6 100644 --- a/api4/system_local.go +++ b/api4/system_local.go @@ -12,6 +12,7 @@ import ( ) func (api *API) InitSystemLocal() { + api.BaseRoutes.System.Handle("/ping", api.ApiLocal(getSystemPing)).Methods("GET") api.BaseRoutes.ApiRoot.Handle("/logs", api.ApiLocal(getLogs)).Methods("GET") api.BaseRoutes.ApiRoot.Handle("/server_busy", api.ApiLocal(setServerBusy)).Methods("POST") api.BaseRoutes.ApiRoot.Handle("/server_busy", api.ApiLocal(getServerBusyExpires)).Methods("GET") diff --git a/api4/system_test.go b/api4/system_test.go index 078f89e2dd..f950d86276 100644 --- a/api4/system_test.go +++ b/api4/system_test.go @@ -25,10 +25,9 @@ func TestGetPing(t *testing.T) { th := Setup(t) defer th.TearDown() - t.Run("basic ping", func(t *testing.T) { - + th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { t.Run("healthy", func(t *testing.T) { - status, resp := th.Client.GetPing() + status, resp := client.GetPing() CheckNoError(t, resp) assert.Equal(t, model.STATUS_OK, status) }) @@ -40,34 +39,36 @@ func TestGetPing(t *testing.T) { }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = 10 }) - status, resp := th.Client.GetPing() + status, resp := client.GetPing() CheckInternalErrorStatus(t, resp) assert.Equal(t, model.STATUS_UNHEALTHY, status) }) + }, "basic ping") - }) - - t.Run("with server status", func(t *testing.T) { - + th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { t.Run("healthy", func(t *testing.T) { - status, resp := th.Client.GetPingWithServerStatus() + status, resp := client.GetPingWithServerStatus() + CheckNoError(t, resp) assert.Equal(t, model.STATUS_OK, status) }) t.Run("unhealthy", func(t *testing.T) { + oldDriver := th.App.Config().FileSettings.DriverName badDriver := "badDriverName" th.App.Config().FileSettings.DriverName = &badDriver + defer func() { + th.App.Config().FileSettings.DriverName = oldDriver + }() - status, resp := th.Client.GetPingWithServerStatus() + status, resp := client.GetPingWithServerStatus() CheckInternalErrorStatus(t, resp) assert.Equal(t, model.STATUS_UNHEALTHY, status) }) + }, "with server status") - }) - - t.Run("ping feature flag test", func(t *testing.T) { - resp, appErr := th.Client.DoApiGet(th.Client.GetSystemRoute()+"/ping", "") + th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { + resp, appErr := client.DoApiGet(client.GetSystemRoute()+"/ping", "") require.Nil(t, appErr) require.Equal(t, http.StatusOK, resp.StatusCode) respBytes, err := ioutil.ReadAll(resp.Body) @@ -86,7 +87,7 @@ func TestGetPing(t *testing.T) { oldConfig := th.App.Config().Clone() th.App.UpdateConfig(func(cfg *model.Config) { *cfg = *retrievedConfig }) - resp, appErr = th.Client.DoApiGet(th.Client.GetSystemRoute()+"/ping", "") + resp, appErr = client.DoApiGet(client.GetSystemRoute()+"/ping", "") require.Nil(t, appErr) require.Equal(t, http.StatusOK, resp.StatusCode) respBytes, err = ioutil.ReadAll(resp.Body) @@ -94,7 +95,7 @@ func TestGetPing(t *testing.T) { respString = string(respBytes) require.Contains(t, respString, "testvalue") th.App.UpdateConfig(func(cfg *model.Config) { *cfg = *oldConfig }) - }) + }, "ping feature flag test") } func TestGetAudits(t *testing.T) {