- build.NewApp writes sm-<name>-app: go.mod with a relative framework
replace, go.work, summer.yaml, config/ and a starter plugin
- make:plugin gains an opt-in starter route (GET /{$}) in the same
routes.go template; plain make:plugin output is unchanged
- plugin:add writes go.work use paths relative to the go.work directory
- bonfire accepts new as a bare tool command name
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package build
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestNewAppSmoke writes an app next to a symlinked framework checkout,
|
|
// builds it and lists the starter route.
|
|
func TestNewAppSmoke(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("runs go mod tidy and go build")
|
|
}
|
|
repo, err := filepath.Abs(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
parent := t.TempDir()
|
|
fw := filepath.Join(parent, "summercms")
|
|
if err := os.Symlink(repo, fw); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx := t.Context()
|
|
var log bytes.Buffer
|
|
dir, err := NewApp(ctx, NewOptions{Name: "demo", Parent: parent, Framework: fw}, &log)
|
|
if err != nil {
|
|
t.Fatalf("NewApp: %v\n%s", err, log.String())
|
|
}
|
|
if want := filepath.Join(parent, "sm-demo-app"); dir != want {
|
|
t.Fatalf("dir = %s, want %s", dir, want)
|
|
}
|
|
|
|
mod, err := os.ReadFile(filepath.Join(dir, "go.mod"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Contains(mod, []byte("replace git.golem15.com/golem15/summercms => ../summercms")) {
|
|
t.Fatalf("go.mod lacks the relative framework replace:\n%s", mod)
|
|
}
|
|
work, err := os.ReadFile(filepath.Join(dir, "go.work"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !bytes.Contains(work, []byte("./plugins/demo")) {
|
|
t.Fatalf("go.work lacks ./plugins/demo:\n%s", work)
|
|
}
|
|
for _, line := range strings.Split(string(work), "\n") {
|
|
if strings.HasPrefix(strings.TrimSpace(line), "/") {
|
|
t.Fatalf("go.work has an absolute path %q:\n%s", line, work)
|
|
}
|
|
}
|
|
|
|
var buildOut bytes.Buffer
|
|
if err := App(ctx, dir, &buildOut); err != nil {
|
|
t.Fatalf("build: %v\n%s", err, buildOut.String())
|
|
}
|
|
cmd := exec.CommandContext(ctx, filepath.Join(dir, "bin", "demo"), "route:list")
|
|
cmd.Dir = dir
|
|
listed, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("route:list: %v\n%s", err, listed)
|
|
}
|
|
for _, want := range []string{"/{$}", "golem15.demo"} {
|
|
if !bytes.Contains(listed, []byte(want)) {
|
|
t.Fatalf("route:list lacks %q:\n%s", want, listed)
|
|
}
|
|
}
|
|
}
|