Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
GoBlog/plugins_test.go

60 lines
1.2 KiB

package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.goblog.app/app/pkgs/plugintypes"
)
var _ plugintypes.App = &goBlog{}
var _ plugintypes.Database = &database{}
var _ plugintypes.Post = &post{}
var _ plugintypes.PostRenderData = &pluginPostRenderData{}
func TestExecPlugin(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Plugins = []*configPlugin{
{
Path: "./plugins/demo",
Type: "exec",
Import: "demoexec",
},
}
err := app.initConfig(false)
require.NoError(t, err)
err = app.initPlugins()
require.NoError(t, err)
}
func TestMiddlewarePlugin(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Plugins = []*configPlugin{
{
Path: "./plugins/demo",
Type: "middleware",
Import: "demomiddleware",
Config: map[string]any{
"prio": 99,
},
},
}
err := app.initConfig(false)
require.NoError(t, err)
err = app.initPlugins()
require.NoError(t, err)
middlewarePlugins := getPluginsForType[plugintypes.Middleware](app, "middleware")
if assert.Len(t, middlewarePlugins, 1) {
mdw := middlewarePlugins[0]
assert.Equal(t, 99, mdw.Prio())
}
}