Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions cmd/micro/cli/new/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ import (
)

// TestZeroToOneContract locks the documented getting-started path:
// `micro new helloworld` must produce an ordinary Go service that can be
// tested by the Go toolchain. The generated module is pointed back at this
// checkout so the contract stays local and deterministic in CI.
// `micro new helloworld` must produce an ordinary Go service that the Go
// toolchain can build. The generated module is pointed back at this checkout
// so the contract stays local and deterministic in CI.
//
// It shells out to `micro new` (which runs `go mod tidy`) and `go build`, so
// it needs the Go toolchain and module access; it is skipped under `-short`.
func TestZeroToOneContract(t *testing.T) {
if testing.Short() {
t.Skip("contract test shells out to the Go toolchain; skipped with -short")
}

repoRoot, err := filepath.Abs(filepath.Join("..", "..", "..", ".."))
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -59,10 +66,10 @@ func TestZeroToOneContract(t *testing.T) {
t.Fatal(err)
}

cmd := exec.Command("go", "test", "./...")
cmd := exec.Command("go", "build", "./...")
cmd.Dir = serviceDir
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("generated service go test ./... failed: %v\n%s", err, out)
t.Fatalf("generated service go build ./... failed: %v\n%s", err, out)
}
}
22 changes: 21 additions & 1 deletion internal/harness/provider-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
Expand Down Expand Up @@ -106,7 +107,26 @@ func runHarness(provider, harness string, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

cmd := exec.CommandContext(ctx, "go", "run", "./internal/harness/"+harness, "-provider", provider)
// Build the harness to a temp binary and run that, rather than `go run`:
// `go run` launches the compiled binary as a child it does not kill on
// context cancellation, so a harness that starts local services could
// outlive the timeout. Running the binary ourselves keeps the timeout
// honest — canceling the context kills the process that does the work.
binDir, err := os.MkdirTemp("", "harness-")
if err != nil {
return err
}
defer os.RemoveAll(binDir)
binPath := filepath.Join(binDir, harness)

build := exec.CommandContext(ctx, "go", "build", "-o", binPath, "./internal/harness/"+harness)
build.Stdout = os.Stdout
build.Stderr = os.Stderr
if err := build.Run(); err != nil {
return fmt.Errorf("build: %w", err)
}

cmd := exec.CommandContext(ctx, binPath, "-provider", provider)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = localRPCEnv(os.Environ())
Expand Down
Loading