From 2835163b18a4d2c7c01d20d775fa662fe7f5b113 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 26 Feb 2020 14:11:24 +0000 Subject: [PATCH] Fix flaky TestPlugin (#13933) - Fix panic due to not checking for JSON marshal error - Reorder the FileExists check which would fail if we were to pass the -short flag to bypass the slow URL test. In which case, the plugin would have been removed from the filesystem. So we move the check before we remove the plugin. https://mattermost.atlassian.net/browse/MM-22666 --- api4/plugin_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api4/plugin_test.go b/api4/plugin_test.go index 6bcf206be3..1b122b222a 100644 --- a/api4/plugin_test.go +++ b/api4/plugin_test.go @@ -33,7 +33,8 @@ func TestPlugin(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - statesJson, _ := json.Marshal(th.App.Config().PluginSettings.PluginStates) + statesJson, err := json.Marshal(th.App.Config().PluginSettings.PluginStates) + require.Nil(t, err) states := map[string]*model.PluginState{} json.Unmarshal(statesJson, &states) th.App.UpdateConfig(func(cfg *model.Config) { @@ -66,6 +67,11 @@ func TestPlugin(t *testing.T) { CheckNoError(t, resp) assert.Equal(t, "testplugin", manifest.Id) + // Stored in File Store: Install Plugin from URL case + pluginStored, err := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz") + assert.Nil(t, err) + assert.True(t, pluginStored) + ok, resp := th.SystemAdminClient.RemovePlugin(manifest.Id) CheckNoError(t, resp) require.True(t, ok) @@ -88,11 +94,6 @@ func TestPlugin(t *testing.T) { assert.Equal(t, "testplugin", manifest.Id) }) - // Stored in File Store: Install Plugin from URL case - pluginStored, err := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz") - assert.Nil(t, err) - assert.True(t, pluginStored) - th.App.RemovePlugin(manifest.Id) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })