- .env (0600) with a fresh lagoon.GenerateAppKey key and the compose DSN; .env.example without a key - compose.yaml runs postgres:16 on 127.0.0.1:54320 with a healthcheck - .gitignore, CLAUDE.md with AGENTS.md as a relative symlink - git init on main and one commit, with a fallback identity only when git has none; git failures are warnings; --no-git skips it - print the next steps after creating the app Claude-Session: https://claude.ai/code/session_01M8Qu9LgCKYy7iYEho52tW8
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package build
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// testAppKey is a fixed, valid app key (base64 of 32 bytes) for hermetic tests.
|
|
const testAppKey = "c3VtbWVyY21zLXRlc3Qta2V5LTMyLWJ5dGVzLWxvbmc="
|
|
|
|
// 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, AppKey: testAppKey, NoGit: true}, &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)
|
|
}
|
|
}
|
|
}
|