Files
summercms/cmd/summer/main_test.go
Jakub Zych 9b1a25dc94 feat(01-03): add make:plugin and plugin:add scaffolding
- Scaffold a compiling vendor.plugin module with go.mod, plugin.go and config/
- Register the module once in summer.yaml, go.work and the app go.mod
- Keep summer build on the same generate-and-compile path and print elapsed time
2026-09-16 13:47:27 +02:00

68 lines
1.5 KiB
Go

package main
import (
"bytes"
"go/parser"
"go/token"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"testing"
"git.golem15.com/golem15/summercms/bonfire"
)
func TestToolCommandNames(t *testing.T) {
var names []string
for _, c := range toolCommands() {
names = append(names, c.Name)
}
for _, want := range []string{"build", "make:plugin", "plugin:add"} {
if !slices.Contains(names, want) {
t.Fatalf("missing %s in %v", want, names)
}
}
var buf bytes.Buffer
root := bonfire.NewRoot("summer", toolCommands(), &buf)
root.SetArgs([]string{"make:plugin", "--help"})
if err := root.Execute(); err != nil {
t.Fatal(err)
}
if !strings.Contains(buf.String(), "vendor.plugin") {
t.Fatalf("make:plugin help missing argument text:\n%s", buf.String())
}
}
func TestToolDoesNotImportExamplePlugins(t *testing.T) {
roots := []string{".", filepath.Join("..", "..", "internal", "build")}
fset := token.NewFileSet()
for _, root := range roots {
entries, err := os.ReadDir(root)
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
name := entry.Name()
if entry.IsDir() || !strings.HasSuffix(name, ".go") {
continue
}
file, err := parser.ParseFile(fset, filepath.Join(root, name), nil, parser.ImportsOnly)
if err != nil {
t.Fatal(err)
}
for _, spec := range file.Imports {
path, err := strconv.Unquote(spec.Path.Value)
if err != nil {
t.Fatal(err)
}
if strings.Contains(path, "examples/hello") {
t.Fatalf("%s imports %s", name, path)
}
}
}
}
}