MM-16819 Helper function to build path to plugin asset (#13626)
Implement helper method to create a URL to the resource from a directory
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ee86413cdd
Коммит
8327e9b0ba
@@ -103,3 +103,74 @@ func TestInstallPluginFromURL(t *testing.T) {
|
||||
assert.Equal(t, "received 404 status code while downloading plugin from server", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetPluginAssetURL(t *testing.T) {
|
||||
siteURL := "https://mattermost.example.com"
|
||||
api := &plugintest.API{}
|
||||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: &siteURL}})
|
||||
|
||||
p := &plugin.HelpersImpl{API: api}
|
||||
|
||||
t.Run("Valid asset directory was provided", func(t *testing.T) {
|
||||
pluginID := "mattermost-1234"
|
||||
dir := "assets"
|
||||
wantedURL := "https://mattermost.example.com/mattermost-1234/assets"
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dir)
|
||||
|
||||
assert.Equalf(t, wantedURL, gotURL, "GetPluginAssetURL(%q, %q) got=%q; want=%v", pluginID, dir, gotURL, wantedURL)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Valid asset directory path was provided", func(t *testing.T) {
|
||||
pluginID := "mattermost-1234"
|
||||
dirPath := "/mattermost/assets"
|
||||
wantedURL := "https://mattermost.example.com/mattermost-1234/mattermost/assets"
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dirPath)
|
||||
|
||||
assert.Equalf(t, wantedURL, gotURL, "GetPluginAssetURL(%q, %q) got=%q; want=%q", pluginID, dirPath, gotURL, wantedURL)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Valid pluginID was provided", func(t *testing.T) {
|
||||
pluginID := "mattermost-1234"
|
||||
dir := "assets"
|
||||
wantedURL := "https://mattermost.example.com/mattermost-1234/assets"
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dir)
|
||||
|
||||
assert.Equalf(t, wantedURL, gotURL, "GetPluginAssetURL(%q, %q) got=%q; want=%q", pluginID, dir, gotURL, wantedURL)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("Invalid asset directory name was provided", func(t *testing.T) {
|
||||
pluginID := "mattermost-1234"
|
||||
dir := ""
|
||||
want := ""
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dir)
|
||||
|
||||
assert.Emptyf(t, gotURL, "GetPluginAssetURL(%q, %q) got=%s; want=%q", pluginID, dir, gotURL, want)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("Invalid pluginID was provided", func(t *testing.T) {
|
||||
pluginID := ""
|
||||
dir := "assets"
|
||||
want := ""
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dir)
|
||||
|
||||
assert.Emptyf(t, gotURL, "GetPluginAssetURL(%q, %q) got=%q; want=%q", pluginID, dir, gotURL, want)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
siteURL = ""
|
||||
api.On("GetConfig").Return(&model.Config{ServiceSettings: model.ServiceSettings{SiteURL: &siteURL}})
|
||||
|
||||
t.Run("Empty SiteURL was configured", func(t *testing.T) {
|
||||
pluginID := "mattermost-1234"
|
||||
dir := "assets"
|
||||
want := ""
|
||||
gotURL, err := p.GetPluginAssetURL(pluginID, dir)
|
||||
|
||||
assert.Emptyf(t, gotURL, "GetPluginAssetURL(%q, %q) got=%q; want=%q", pluginID, dir, gotURL, want)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user