本文整理汇总了Golang中github.com/evergreen-ci/evergreen/plugin.PanelManager.RegisterPlugins方法的典型用法代码示例。如果您正苦于以下问题:Golang PanelManager.RegisterPlugins方法的具体用法?Golang PanelManager.RegisterPlugins怎么用?Golang PanelManager.RegisterPlugins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/evergreen-ci/evergreen/plugin.PanelManager
的用法示例。
在下文中一共展示了PanelManager.RegisterPlugins方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUIDataInjection
func TestUIDataInjection(t *testing.T) {
var ppm plugin.PanelManager
Convey("With a simple plugin panel manager", t, func() {
ppm = &plugin.SimplePanelManager{}
Convey("and a registered set of test plugins with injection needs", func() {
funcPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "combine",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(ctx plugin.UIContext) (interface{}, error) {
return ctx.Task.Id + ctx.Build.Id + ctx.Version.Id, nil
},
},
},
},
},
&MockUIPlugin{
NickName: "userhttpapiserver",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(ctx plugin.UIContext) (interface{}, error) {
return fmt.Sprintf("%v.%[email protected]%v", ctx.User.Email, ctx.Settings.ApiUrl), nil
},
},
},
},
},
}
err := ppm.RegisterPlugins(funcPlugins)
So(err, ShouldBeNil)
})
})
}
示例2: TestPanelManagerRegistration
func TestPanelManagerRegistration(t *testing.T) {
var ppm plugin.PanelManager
Convey("With a simple plugin panel manager", t, func() {
ppm = &plugin.SimplePanelManager{}
Convey("and a registered set of test plugins without panels", func() {
uselessPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "no_ui_config",
Conf: nil,
},
&MockUIPlugin{
NickName: "config_with_no_panels",
Conf: &plugin.PanelConfig{
StaticRoot: "wooo",
},
},
}
err := ppm.RegisterPlugins(uselessPlugins)
So(err, ShouldBeNil)
Convey("no ui panel data should be returned for any scope", func() {
data, err := ppm.UIData(plugin.UIContext{}, plugin.TaskPage)
So(err, ShouldBeNil)
So(data["no_ui_config"], ShouldBeNil)
So(data["config_with_no_panels"], ShouldBeNil)
data, err = ppm.UIData(plugin.UIContext{}, plugin.BuildPage)
So(err, ShouldBeNil)
So(data["no_ui_config"], ShouldBeNil)
So(data["config_with_no_panels"], ShouldBeNil)
data, err = ppm.UIData(plugin.UIContext{}, plugin.VersionPage)
So(err, ShouldBeNil)
So(data["no_ui_config"], ShouldBeNil)
So(data["config_with_no_panels"], ShouldBeNil)
})
})
Convey("registering a plugin panel with no page should fail", func() {
badPanelPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "bad_panel",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{PanelHTML: "<marquee> PANEL </marquee>"},
},
},
},
}
err := ppm.RegisterPlugins(badPanelPlugins)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "Page")
})
Convey("registering the same plugin name twice should fail", func() {
conflictingPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "a",
Conf: nil,
},
&MockUIPlugin{
NickName: "a",
Conf: &plugin.PanelConfig{
StaticRoot: "root",
},
},
}
err := ppm.RegisterPlugins(conflictingPlugins)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "already")
})
Convey("registering more than one data function to the same page "+
"for the same plugin should fail", func() {
dataPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "data_function_fan",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return 100, nil
}},
{
Page: plugin.TaskPage,
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return nil, fmt.Errorf("this function just errors")
}},
},
},
},
}
err := ppm.RegisterPlugins(dataPlugins)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldContainSubstring, "function is already registered")
})
})
}
示例3: TestPluginUIDataFunctionErrorHandling
func TestPluginUIDataFunctionErrorHandling(t *testing.T) {
var ppm plugin.PanelManager
Convey("With a simple plugin panel manager", t, func() {
ppm = &plugin.SimplePanelManager{}
Convey("and a set of plugins, some with erroring data functions", func() {
errorPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "error1",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return nil, fmt.Errorf("Error #1")
},
},
},
},
},
&MockUIPlugin{
NickName: "error2",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return nil, fmt.Errorf("Error #2")
},
},
},
},
},
&MockUIPlugin{
NickName: "error3 not found",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(_ plugin.UIContext) (interface{}, error) {
return nil, fmt.Errorf("Error")
},
},
},
},
},
&MockUIPlugin{
NickName: "good",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(_ plugin.UIContext) (interface{}, error) {
return "fine", nil
},
},
},
},
},
}
err := ppm.RegisterPlugins(errorPlugins)
So(err, ShouldBeNil)
data, err := ppm.UIData(plugin.UIContext{}, plugin.TaskPage)
So(err, ShouldNotBeNil)
Convey("non-broken functions should succeed", func() {
So(data["good"], ShouldEqual, "fine")
})
Convey("and reasonable error messages should be produced for failures", func() {
So(err.Error(), ShouldContainSubstring, "error1")
So(err.Error(), ShouldContainSubstring, "Error #1")
So(err.Error(), ShouldContainSubstring, "error2")
So(err.Error(), ShouldContainSubstring, "Error #2")
So(err.Error(), ShouldContainSubstring, "error3")
})
})
Convey("and a plugin that panics", func() {
errorPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "busted",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
DataFunc: func(_ plugin.UIContext) (interface{}, error) {
panic("BOOM")
return "like perfection I am unreachable", nil
},
},
},
},
},
&MockUIPlugin{
//.........这里部分代码省略.........
示例4: TestPanelManagerRetrieval
func TestPanelManagerRetrieval(t *testing.T) {
var ppm plugin.PanelManager
Convey("With a simple plugin panel manager", t, func() {
ppm = &plugin.SimplePanelManager{}
Convey("and a registered set of test plugins with panels", func() {
// These 3 plugins exist to check the sort output of the manager.
// For consistency, plugin panels and includes are ordered by plugin name
// and then by the order of their declaration in the Panels array.
// This test asserts that the panels in A come before B which come
// before C, even though they are not in the plugin array in that order.
testPlugins := []plugin.Plugin{
&MockUIPlugin{
NickName: "A_the_first_letter",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
Includes: []template.HTML{
"0",
"1",
},
PanelHTML: "0",
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return 1000, nil
},
},
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
Includes: []template.HTML{
"2",
"3",
},
PanelHTML: "1",
},
{
Page: plugin.TaskPage,
Position: plugin.PageLeft,
Includes: []template.HTML{
"4",
},
PanelHTML: "X",
},
},
},
},
&MockUIPlugin{
NickName: "C_the_third_letter",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
Includes: []template.HTML{
"7",
"8",
},
PanelHTML: "3",
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return 2112, nil
},
},
},
},
},
&MockUIPlugin{
NickName: "B_the_middle_letter",
Conf: &plugin.PanelConfig{
Panels: []plugin.UIPanel{
{
Page: plugin.TaskPage,
Position: plugin.PageCenter,
Includes: []template.HTML{
"5",
},
PanelHTML: "2",
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return 1776, nil
},
},
{
Page: plugin.TaskPage,
Position: plugin.PageLeft,
Includes: []template.HTML{
"6",
},
PanelHTML: "Z",
},
},
},
},
}
err := ppm.RegisterPlugins(testPlugins)
So(err, ShouldBeNil)
Convey("retrieved includes for the task page should be in correct "+
//.........这里部分代码省略.........