feat(01-01): generate and build hello app from manifest

- Add summer build with validated summer.yaml codegen
- Generate stable main.go and plugins.gen.go then go build
- Smoke-test the built hello binary greeter:hello command
This commit is contained in:
Jakub Zych
2026-09-16 13:01:24 +02:00
parent 96a8d38be2
commit 2078f91a2b
5 changed files with 557 additions and 0 deletions

View File

@@ -2,6 +2,9 @@ package main
import (
"bytes"
"crypto/sha256"
"os"
"os/exec"
"strings"
"testing"
)
@@ -15,3 +18,46 @@ func TestGreeterHelloPrintsAppName(t *testing.T) {
t.Fatalf("output = %q, want %q", got, "hello-app")
}
}
func TestBuiltBinaryGreeterHello(t *testing.T) {
first := runSummerBuild(t)
h1 := generatedHash(t)
second := runSummerBuild(t)
h2 := generatedHash(t)
if h1 != h2 {
t.Fatalf("generated files changed on second build\nfirst:\n%s\nsecond:\n%s", first, second)
}
cmd := exec.Command("./bin/hello", "greeter:hello")
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("bin/hello greeter:hello: %v\n%s", err, out)
}
if got := strings.TrimSpace(string(out)); got != "hello-app" {
t.Fatalf("output = %q, want %q", got, "hello-app")
}
}
func runSummerBuild(t *testing.T) string {
t.Helper()
cmd := exec.Command("go", "run", "../../cmd/summer", "build")
cmd.Dir = "."
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("summer build: %v\n%s", err, out)
}
return string(out)
}
func generatedHash(t *testing.T) [32]byte {
t.Helper()
var buf bytes.Buffer
for _, name := range []string{"main.go", "plugins.gen.go"} {
body, err := os.ReadFile(name)
if err != nil {
t.Fatal(err)
}
buf.Write(body)
}
return sha256.Sum256(buf.Bytes())
}