-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate logging to use RPC Logging methods (#102)
- Loading branch information
1 parent
a10f0ee
commit 4a25236
Showing
4 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package autolinkplugin | ||
|
||
import ( | ||
"errors" | ||
"github.com/mattermost/mattermost-plugin-autolink/server/autolink" | ||
"github.com/mattermost/mattermost-server/v5/model" | ||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest" | ||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest/mock" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestOnConfigurationChange(t *testing.T) { | ||
|
||
t.Run("Invalid Configuration", func(t *testing.T) { | ||
api := &plugintest.API{} | ||
api.On("LoadPluginConfiguration", | ||
mock.AnythingOfType("*autolinkplugin.Config")).Return(func(dest interface{}) error { | ||
return errors.New("LoadPluginConfiguration Error") | ||
}) | ||
|
||
p := Plugin{} | ||
p.SetAPI(api) | ||
|
||
err := p.OnConfigurationChange() | ||
assert.Error(t, err) | ||
}) | ||
|
||
t.Run("Invalid Autolink", func(t *testing.T) { | ||
conf := Config{ | ||
Links: []autolink.Autolink{ | ||
autolink.Autolink{ | ||
Name: "existing", | ||
Pattern: ")", | ||
Template: "otherthing", | ||
}, | ||
}, | ||
} | ||
|
||
api := &plugintest.API{} | ||
api.On("LoadPluginConfiguration", | ||
mock.AnythingOfType("*autolinkplugin.Config")).Return(func(dest interface{}) error { | ||
*dest.(*Config) = conf | ||
return nil | ||
}) | ||
|
||
api.On("LogError", | ||
mock.AnythingOfType("string"), | ||
mock.AnythingOfType("string"), | ||
mock.AnythingOfType("autolink.Autolink"), | ||
mock.AnythingOfType("string"), | ||
mock.AnythingOfType("string")).Return(nil) | ||
|
||
api.On("UnregisterCommand", mock.AnythingOfType("string"), | ||
mock.AnythingOfType("string")).Return((*model.AppError)(nil)) | ||
|
||
p := New() | ||
p.SetAPI(api) | ||
p.OnConfigurationChange() | ||
|
||
api.AssertNumberOfCalls(t, "LogError", 1) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters