diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-10-25 08:17:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-25 08:17:17 -0400 |
commit | 16b845c0d77535ea306339f7a8bd22fc72f8a3c5 (patch) | |
tree | e768b8d1ca5cc3f2e55207ea73c5954b37f708ed /api4/plugin_test.go | |
parent | 9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae (diff) | |
download | chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.gz chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.bz2 chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.zip |
Differentiate between installed and activated states for plugins (#7706)
Diffstat (limited to 'api4/plugin_test.go')
-rw-r--r-- | api4/plugin_test.go | 73 |
1 files changed, 66 insertions, 7 deletions
diff --git a/api4/plugin_test.go b/api4/plugin_test.go index 1feb1b06a..a3f3bd49a 100644 --- a/api4/plugin_test.go +++ b/api4/plugin_test.go @@ -65,12 +65,43 @@ func TestPlugin(t *testing.T) { _, resp = th.Client.UploadPlugin(file) CheckForbiddenStatus(t, resp) - // Successful get - manifests, resp := th.SystemAdminClient.GetPlugins() + // Successful gets + pluginsResp, resp := th.SystemAdminClient.GetPlugins() CheckNoError(t, resp) found := false - for _, m := range manifests { + for _, m := range pluginsResp.Inactive { + if m.Id == manifest.Id { + found = true + } + } + + assert.True(t, found) + + found = false + for _, m := range pluginsResp.Active { + if m.Id == manifest.Id { + found = true + } + } + + assert.False(t, found) + + states := th.App.Config().PluginSettings.PluginStates + defer func() { + th.App.UpdateConfig(func(cfg *model.Config) { cfg.PluginSettings.PluginStates = states }) + }() + + // Successful activate + ok, resp := th.SystemAdminClient.ActivatePlugin(manifest.Id) + CheckNoError(t, resp) + assert.True(t, ok) + + pluginsResp, resp = th.SystemAdminClient.GetPlugins() + CheckNoError(t, resp) + + found = false + for _, m := range pluginsResp.Active { if m.Id == manifest.Id { found = true } @@ -78,6 +109,33 @@ func TestPlugin(t *testing.T) { assert.True(t, found) + // Activate error case + ok, resp = th.SystemAdminClient.ActivatePlugin("junk") + CheckBadRequestStatus(t, resp) + assert.False(t, ok) + + // Successful deactivate + ok, resp = th.SystemAdminClient.DeactivatePlugin(manifest.Id) + CheckNoError(t, resp) + assert.True(t, ok) + + pluginsResp, resp = th.SystemAdminClient.GetPlugins() + CheckNoError(t, resp) + + found = false + for _, m := range pluginsResp.Inactive { + if m.Id == manifest.Id { + found = true + } + } + + assert.True(t, found) + + // Deactivate error case + ok, resp = th.SystemAdminClient.DeactivatePlugin("junk") + CheckBadRequestStatus(t, resp) + assert.False(t, ok) + // Get error cases th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false }) _, resp = th.SystemAdminClient.GetPlugins() @@ -88,7 +146,10 @@ func TestPlugin(t *testing.T) { CheckForbiddenStatus(t, resp) // Successful webapp get - manifests, resp = th.Client.GetWebappPlugins() + _, resp = th.SystemAdminClient.ActivatePlugin(manifest.Id) + CheckNoError(t, resp) + + manifests, resp := th.Client.GetWebappPlugins() CheckNoError(t, resp) found = false @@ -101,15 +162,13 @@ func TestPlugin(t *testing.T) { assert.True(t, found) // Successful remove - ok, resp := th.SystemAdminClient.RemovePlugin(manifest.Id) + ok, resp = th.SystemAdminClient.RemovePlugin(manifest.Id) CheckNoError(t, resp) - assert.True(t, ok) // Remove error cases ok, resp = th.SystemAdminClient.RemovePlugin(manifest.Id) CheckBadRequestStatus(t, resp) - assert.False(t, ok) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false }) |