Replacing require.nil in api layer (#16906)

* Replacing require.nil in api layer

* Fixing some tests

* Fixing tests

* Addressing PR review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2021-02-17 09:52:18 +01:00
коммит произвёл GitHub
родитель 9992a27a90
Коммит 31a80a5351
22 изменённых файлов: 226 добавлений и 227 удалений

Просмотреть файл

@@ -34,7 +34,7 @@ func TestPlugin(t *testing.T) {
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
statesJson, err := json.Marshal(th.App.Config().PluginSettings.PluginStates)
require.Nil(t, err)
require.NoError(t, err)
states := map[string]*model.PluginState{}
json.Unmarshal(statesJson, &states)
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -68,8 +68,8 @@ 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)
pluginStored, appErr := th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
assert.Nil(t, appErr)
assert.True(t, pluginStored)
ok, resp := client.RemovePlugin(manifest.Id)
@@ -127,8 +127,8 @@ func TestPlugin(t *testing.T) {
assert.Equal(t, "testplugin", manifest.Id)
// Stored in File Store: Upload Plugin case
pluginStored, err = th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
assert.Nil(t, err)
pluginStored, appErr = th.App.FileExists("./plugins/" + manifest.Id + ".tar.gz")
assert.Nil(t, appErr)
assert.True(t, pluginStored)
// Upload error cases
@@ -296,8 +296,8 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
// Stored in File Store: Upload Plugin case
expectedPath := filepath.Join("./plugins", manifest.Id) + ".tar.gz"
pluginStored, err := th.App.FileExists(expectedPath)
require.Nil(t, err)
pluginStored, appErr := th.App.FileExists(expectedPath)
require.Nil(t, appErr)
require.True(t, pluginStored)
messages := testCluster.GetMessages()
@@ -320,8 +320,8 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
require.Equal(t, "testplugin", manifest.Id)
// Successful remove
webSocketClient, err := th.CreateWebSocketSystemAdminClient()
require.Nil(t, err)
webSocketClient, appErr := th.CreateWebSocketSystemAdminClient()
require.Nil(t, appErr)
webSocketClient.Listen()
defer webSocketClient.Close()
done := make(chan bool)
@@ -359,8 +359,8 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
actualMessages = findClusterMessages(model.CLUSTER_EVENT_REMOVE_PLUGIN, messages)
require.Equal(t, []*model.ClusterMessage{expectedRemoveMessage}, actualMessages)
pluginStored, err = th.App.FileExists(expectedPath)
require.Nil(t, err)
pluginStored, appErr = th.App.FileExists(expectedPath)
require.Nil(t, appErr)
require.False(t, pluginStored)
}
@@ -1255,9 +1255,9 @@ func TestInstallMarketplacePlugin(t *testing.T) {
path, _ := fileutils.FindDir("tests")
signatureFilename := "testplugin2.tar.gz.sig"
signatureFileReader, err := os.Open(filepath.Join(path, signatureFilename))
require.Nil(t, err)
require.NoError(t, err)
sigFile, err := ioutil.ReadAll(signatureFileReader)
require.Nil(t, err)
require.NoError(t, err)
pluginSignature := base64.StdEncoding.EncodeToString(sigFile)
tarData, err := ioutil.ReadFile(filepath.Join(path, "testplugin2.tar.gz"))
@@ -1420,15 +1420,15 @@ func TestInstallMarketplacePlugin(t *testing.T) {
require.Equal(t, "1.2.3", manifest.Version)
filePath := filepath.Join("plugins", "testplugin2.tar.gz.sig")
savedSigFile, err := th.App.ReadFile(filePath)
require.Nil(t, err)
savedSigFile, appErr := th.App.ReadFile(filePath)
require.Nil(t, appErr)
require.EqualValues(t, sigFile, savedSigFile)
ok, resp := client.RemovePlugin(manifest.Id)
CheckNoError(t, resp)
assert.True(t, ok)
exists, err := th.App.FileExists(filePath)
require.Nil(t, err)
exists, appErr := th.App.FileExists(filePath)
require.Nil(t, appErr)
require.False(t, exists)
appErr = th.App.DeletePublicKey("pub_key")
@@ -1564,9 +1564,9 @@ func TestInstallMarketplacePlugin(t *testing.T) {
th2.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
pluginSignatureFile, err := os.Open(filepath.Join(path, "testplugin.tar.gz.asc"))
require.Nil(t, err)
require.NoError(t, err)
pluginSignatureData, err := ioutil.ReadAll(pluginSignatureFile)
require.Nil(t, err)
require.NoError(t, err)
key, err := os.Open(filepath.Join(path, "development-private-key.asc"))
require.NoError(t, err)