test(14.3-04): cover every summer new branch, key and CLI path
- name rule, existing targets, framework resolution order, inside-checkout refusal - cleanup on failure, key validation, .env 0600, AGENTS.md symlink - first commit identity, configured identity, missing git, --no-git, --no-plugin build - plugin:add relative go.work, plain make:plugin routes, GenerateAppKey, summer new via the CLI
This commit is contained in:
@@ -27,7 +27,7 @@ func TestToolCommandNames(t *testing.T) {
|
||||
|
||||
helpWants := map[string][]string{
|
||||
"make:plugin": {"vendor.plugin"},
|
||||
"new": {"--framework", "name"},
|
||||
"new": {"--framework", "--no-plugin", "--no-git", "name"},
|
||||
"make:model": {"[plugin] [name]", "no-migration"},
|
||||
"make:migration": {"[plugin] [name]"},
|
||||
"make:command": {"[plugin] [name]"},
|
||||
@@ -155,6 +155,76 @@ func TestMakeCommandsViaCLI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewCommandViaCLI runs summer new through the CLI root in a parent
|
||||
// holding a summercms symlink to this checkout.
|
||||
func TestNewCommandViaCLI(t *testing.T) {
|
||||
repo, err := filepath.Abs(filepath.Join("..", ".."))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parent := t.TempDir()
|
||||
if err := os.Symlink(repo, filepath.Join(parent, "summercms")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Chdir(parent)
|
||||
|
||||
run := func(args ...string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
root, err := bonfire.NewRoot("summer", toolCommands(), &buf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
root.SetArgs(args)
|
||||
err = root.Execute()
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
if out, err := run("new"); err == nil {
|
||||
t.Fatalf("new without a name succeeded:\n%s", out)
|
||||
}
|
||||
if out, err := run("new", "Demo"); err == nil {
|
||||
t.Fatalf("new Demo succeeded:\n%s", out)
|
||||
}
|
||||
if _, err := os.Lstat(filepath.Join(parent, "sm-Demo-app")); !os.IsNotExist(err) {
|
||||
t.Fatalf("new Demo left sm-Demo-app: %v", err)
|
||||
}
|
||||
|
||||
out, err := run("new", "demo", "--no-git")
|
||||
if err != nil {
|
||||
t.Fatalf("new demo --no-git: %v\n%s", err, out)
|
||||
}
|
||||
app := filepath.Join(parent, "sm-demo-app")
|
||||
for _, rel := range []string{"summer.yaml", "main.go", "plugins/demo/routes.go"} {
|
||||
if _, err := os.Stat(filepath.Join(app, rel)); err != nil {
|
||||
t.Fatalf("%s missing: %v", rel, err)
|
||||
}
|
||||
}
|
||||
if _, err := os.Lstat(filepath.Join(app, ".git")); !os.IsNotExist(err) {
|
||||
t.Fatalf("--no-git created .git: %v", err)
|
||||
}
|
||||
env, err := os.ReadFile(filepath.Join(app, ".env"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var key string
|
||||
for _, line := range strings.Split(string(env), "\n") {
|
||||
if v, ok := strings.CutPrefix(line, "SUMMER_APP__KEY="); ok {
|
||||
key = v
|
||||
}
|
||||
}
|
||||
if len(key) != 44 {
|
||||
t.Fatalf("SUMMER_APP__KEY = %q, want a 44-character key", key)
|
||||
}
|
||||
for _, want := range []string{"created " + app, "Next steps, inside sm-demo-app:", "summer migrate", "curl http://127.0.0.1:8080/"} {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("output lacks %q:\n%s", want, out)
|
||||
}
|
||||
}
|
||||
if out, err := run("new", "demo", "--no-git"); err == nil || !strings.Contains(err.Error(), "already exists") {
|
||||
t.Fatalf("second new demo: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func copyHelloApp(t *testing.T) string {
|
||||
t.Helper()
|
||||
src, err := filepath.Abs(filepath.Join("..", "..", "examples", "hello"))
|
||||
|
||||
Reference in New Issue
Block a user