mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
169 lines
4.9 KiB
Go
169 lines
4.9 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/hanzoteam/server/server/v8/cmd/mmctl/printer"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func createMarketplacePlugin(name string) *model.MarketplacePlugin {
|
|
return &model.MarketplacePlugin{
|
|
BaseMarketplacePlugin: &model.BaseMarketplacePlugin{
|
|
Manifest: &model.Manifest{Name: name},
|
|
},
|
|
}
|
|
}
|
|
|
|
func (s *MmctlUnitTestSuite) TestPluginMarketplaceInstallCmd() {
|
|
s.Run("Install a valid plugin", func() {
|
|
printer.Clean()
|
|
|
|
id := "myplugin"
|
|
args := []string{id}
|
|
pluginRequest := &model.InstallMarketplacePluginRequest{Id: id}
|
|
manifest := &model.Manifest{Name: "My Plugin", Id: id}
|
|
|
|
s.client.
|
|
EXPECT().
|
|
InstallMarketplacePlugin(context.TODO(), pluginRequest).
|
|
Return(manifest, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceInstallCmdF(s.client, &cobra.Command{}, args)
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Equal(manifest, printer.GetLines()[0])
|
|
})
|
|
|
|
s.Run("Install an invalid plugin", func() {
|
|
printer.Clean()
|
|
|
|
id := "myplugin"
|
|
args := []string{id}
|
|
pluginRequest := &model.InstallMarketplacePluginRequest{Id: id}
|
|
|
|
s.client.
|
|
EXPECT().
|
|
InstallMarketplacePlugin(context.TODO(), pluginRequest).
|
|
Return(nil, &model.Response{}, errors.New("mock error")).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceInstallCmdF(s.client, &cobra.Command{}, args)
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
})
|
|
}
|
|
|
|
func (s *MmctlUnitTestSuite) TestPluginMarketplaceListCmd() {
|
|
s.Run("List honoring pagination flags", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Int("page", 0, "")
|
|
cmd.Flags().Int("per-page", 1, "")
|
|
pluginFilter := &model.MarketplacePluginFilter{Page: 0, PerPage: 1}
|
|
mockPlugin := createMarketplacePlugin("My Plugin")
|
|
plugins := []*model.MarketplacePlugin{mockPlugin}
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), pluginFilter).
|
|
Return(plugins, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceListCmdF(s.client, cmd, []string{})
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Equal(mockPlugin, printer.GetLines()[0])
|
|
})
|
|
|
|
s.Run("List all plugins", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Int("per-page", 1, "")
|
|
cmd.Flags().Bool("all", true, "")
|
|
mockPlugin1 := createMarketplacePlugin("My Plugin One")
|
|
mockPlugin2 := createMarketplacePlugin("My Plugin Two")
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), &model.MarketplacePluginFilter{Page: 0, PerPage: 1}).
|
|
Return([]*model.MarketplacePlugin{mockPlugin1}, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), &model.MarketplacePluginFilter{Page: 1, PerPage: 1}).
|
|
Return([]*model.MarketplacePlugin{mockPlugin2}, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), &model.MarketplacePluginFilter{Page: 2, PerPage: 1}).
|
|
Return([]*model.MarketplacePlugin{}, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceListCmdF(s.client, cmd, []string{})
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 2)
|
|
s.Require().Equal(mockPlugin1, printer.GetLines()[0])
|
|
s.Require().Equal(mockPlugin2, printer.GetLines()[1])
|
|
})
|
|
|
|
s.Run("List all plugins with errors", func() {
|
|
printer.Clean()
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Int("per-page", 200, "")
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), &model.MarketplacePluginFilter{Page: 0, PerPage: 200}).
|
|
Return(nil, &model.Response{}, errors.New("mock error")).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceListCmdF(s.client, cmd, []string{})
|
|
s.Require().Error(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 0)
|
|
})
|
|
|
|
s.Run("List honoring filter and local only flags", func() {
|
|
printer.Clean()
|
|
|
|
filter := "jit"
|
|
cmd := &cobra.Command{}
|
|
cmd.Flags().Int("per-page", 200, "")
|
|
cmd.Flags().String("filter", filter, "")
|
|
cmd.Flags().Bool("local-only", true, "")
|
|
pluginFilter := &model.MarketplacePluginFilter{Page: 0, PerPage: 200, Filter: filter, LocalOnly: true}
|
|
mockPlugin := createMarketplacePlugin("Jitsi")
|
|
plugins := []*model.MarketplacePlugin{mockPlugin}
|
|
|
|
s.client.
|
|
EXPECT().
|
|
GetMarketplacePlugins(context.TODO(), pluginFilter).
|
|
Return(plugins, &model.Response{}, nil).
|
|
Times(1)
|
|
|
|
err := pluginMarketplaceListCmdF(s.client, cmd, []string{})
|
|
s.Require().NoError(err)
|
|
s.Require().Len(printer.GetErrorLines(), 0)
|
|
s.Require().Len(printer.GetLines(), 1)
|
|
s.Require().Equal(mockPlugin, printer.GetLines()[0])
|
|
})
|
|
}
|