MCPcopy
hub / github.com/mattermost/mattermost / TestInstallPluginFromURL

Function TestInstallPluginFromURL

server/public/pluginapi/plugin_test.go:19–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestInstallPluginFromURL(t *testing.T) {
20 replace := true
21
22 t.Run("incompatible server version", func(t *testing.T) {
23 api := &plugintest.API{}
24 api.On("GetServerVersion").Return("5.1.0")
25 client := pluginapi.NewClient(api, &plugintest.Driver{})
26
27 _, err := client.Plugin.InstallPluginFromURL("", true)
28
29 assert.Error(t, err)
30 assert.Equal(t, "incompatible server version for plugin, minimum required version: 5.18.0, current version: 5.1.0", err.Error())
31 })
32
33 t.Run("error while parsing the download url", func(t *testing.T) {
34 api := &plugintest.API{}
35 api.On("GetServerVersion").Return("5.19.0")
36 client := pluginapi.NewClient(api, &plugintest.Driver{})
37
38 _, err := client.Plugin.InstallPluginFromURL("http://%41:8080/", replace)
39
40 assert.Error(t, err)
41 assert.Equal(t, "error while parsing url: parse \"http://%41:8080/\": invalid URL escape \"%41\"", err.Error())
42 })
43
44 t.Run("errors out while downloading file", func(t *testing.T) {
45 api := &plugintest.API{}
46 api.On("GetServerVersion").Return("5.19.0")
47 client := pluginapi.NewClient(api, &plugintest.Driver{})
48
49 testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
50 res.WriteHeader(http.StatusInternalServerError)
51 }))
52 defer testServer.Close()
53 url := testServer.URL
54
55 _, err := client.Plugin.InstallPluginFromURL(url, replace)
56
57 assert.Error(t, err)
58 assert.Equal(t, "received 500 status code while downloading plugin from server", err.Error())
59 })
60
61 t.Run("downloads the file successfully", func(t *testing.T) {
62 api := &plugintest.API{}
63 api.On("GetServerVersion").Return("5.19.0")
64 client := pluginapi.NewClient(api, &plugintest.Driver{})
65
66 tarData, err := os.ReadFile(filepath.Join("../../tests", "testplugin.tar.gz"))
67 require.NoError(t, err)
68 expectedManifest := &model.Manifest{Id: "testplugin"}
69 api.On("InstallPlugin", mock.Anything, false).Return(expectedManifest, nil)
70
71 testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
72 res.WriteHeader(http.StatusOK)
73 _, _ = res.Write(tarData)
74 }))
75 defer testServer.Close()
76 url := testServer.URL

Callers

nothing calls this directly

Calls 10

JoinMethod · 0.80
RunMethod · 0.65
InstallPluginFromURLMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
ReadFileMethod · 0.65
WriteMethod · 0.65
EqualMethod · 0.45
WriteHeaderMethod · 0.45
NoErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…