[MM-53968] Includes mattermost-plugin-api into the mono repo (#24235)
Include https://github.com/mattermost/mattermost-plugin-api into the mono repo Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Michael Kochell <mjkochell@gmail.com> Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com> Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> Co-authored-by: Christopher Poile <cpoile@gmail.com> Co-authored-by: İlker Göktuğ Öztürk <ilkergoktugozturk@gmail.com> Co-authored-by: Shota Gvinepadze <wineson@gmail.com> Co-authored-by: Ali Farooq <ali.farooq0@pm.me> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Alex Dovenmuehle <adovenmuehle@gmail.com> Co-authored-by: Szymon Gibała <szymongib@gmail.com> Co-authored-by: Lev <1187448+levb@users.noreply.github.com> Co-authored-by: Jason Frerich <jason.frerich@mattermost.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Artur M. Wolff <artur.m.wolff@gmail.com> Co-authored-by: Madhav Hugar <16546715+madhavhugar@users.noreply.github.com> Co-authored-by: Joe <security.joe@pm.me> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: José Peso <trilopin@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bc11b29807
Коммит
3ee5432664
104
server/public/pluginapi/system_test.go
Обычный файл
104
server/public/pluginapi/system_test.go
Обычный файл
@@ -0,0 +1,104 @@
|
||||
package pluginapi_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin/plugintest"
|
||||
"github.com/mattermost/mattermost/server/public/pluginapi"
|
||||
)
|
||||
|
||||
func TestGetManifest(t *testing.T) {
|
||||
t.Run("valid manifest", func(t *testing.T) {
|
||||
content := []byte(`
|
||||
{
|
||||
"id": "some.id",
|
||||
"name": "Some Name"
|
||||
}
|
||||
`)
|
||||
expectedManifest := &model.Manifest{
|
||||
Id: "some.id",
|
||||
Name: "Some Name",
|
||||
}
|
||||
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
tmpfn := filepath.Join(dir, "plugin.json")
|
||||
//nolint:gosec //only used in tests
|
||||
err = os.WriteFile(tmpfn, content, 0o666)
|
||||
require.NoError(t, err)
|
||||
|
||||
api := &plugintest.API{}
|
||||
api.On("GetBundlePath").Return(dir, nil)
|
||||
defer api.AssertExpectations(t)
|
||||
client := pluginapi.NewClient(api, &plugintest.Driver{})
|
||||
m, err := client.System.GetManifest()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedManifest, m)
|
||||
|
||||
// Altering the pointer doesn't alter the result
|
||||
m.Id = "new.id"
|
||||
|
||||
m2, err := client.System.GetManifest()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedManifest, m2)
|
||||
})
|
||||
|
||||
t.Run("GetBundlePath fails", func(t *testing.T) {
|
||||
api := &plugintest.API{}
|
||||
api.On("GetBundlePath").Return("", errors.New(""))
|
||||
defer api.AssertExpectations(t)
|
||||
client := pluginapi.NewClient(api, &plugintest.Driver{})
|
||||
m, err := client.System.GetManifest()
|
||||
require.Error(t, err)
|
||||
require.Nil(t, m)
|
||||
})
|
||||
|
||||
t.Run("No manifest found", func(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
api := &plugintest.API{}
|
||||
api.On("GetBundlePath").Return(dir, nil)
|
||||
defer api.AssertExpectations(t)
|
||||
client := pluginapi.NewClient(api, &plugintest.Driver{})
|
||||
m, err := client.System.GetManifest()
|
||||
require.Error(t, err)
|
||||
require.Nil(t, m)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRequestTrialLicense(t *testing.T) {
|
||||
t.Run("Server version incompatible", func(t *testing.T) {
|
||||
api := &plugintest.API{}
|
||||
defer api.AssertExpectations(t)
|
||||
client := pluginapi.NewClient(api, &plugintest.Driver{})
|
||||
|
||||
api.On("GetServerVersion").Return("5.35.0")
|
||||
err := client.System.RequestTrialLicense("requesterID", 10, true, true)
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "current server version is lower than 5.36", err.Error())
|
||||
})
|
||||
|
||||
t.Run("Server version compatible", func(t *testing.T) {
|
||||
api := &plugintest.API{}
|
||||
defer api.AssertExpectations(t)
|
||||
client := pluginapi.NewClient(api, &plugintest.Driver{})
|
||||
|
||||
api.On("GetServerVersion").Return("5.36.0")
|
||||
api.On("RequestTrialLicense", "requesterID", 10, true, true).Return(nil)
|
||||
|
||||
err := client.System.RequestTrialLicense("requesterID", 10, true, true)
|
||||
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
Ссылка в новой задаче
Block a user