go/service_example_test.go
Snider 8b905f3a4a feat: per-file example tests — action, registry, fs, api, string, path, service, error, array
33 new examples across 8 dedicated files. Removed phantom CleanPath
(in RFC spec but never implemented — spec drift caught by examples).

545 tests total, 84.8% coverage. Every major primitive has compilable
examples that serve as test, documentation seed, and godoc content.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-25 18:29:24 +00:00

51 lines
934 B
Go

package core_test
import (
"context"
"fmt"
. "dappco.re/go/core"
)
func ExampleServiceFor() {
c := New(
WithService(func(c *Core) Result {
return c.Service("cache", Service{
OnStart: func() Result { return Result{OK: true} },
})
}),
)
svc := c.Service("cache")
fmt.Println(svc.OK)
// Output: true
}
func ExampleWithService() {
started := false
c := New(
WithService(func(c *Core) Result {
return c.Service("worker", Service{
OnStart: func() Result { started = true; return Result{OK: true} },
})
}),
)
c.ServiceStartup(context.Background(), nil)
fmt.Println(started)
c.ServiceShutdown(context.Background())
// Output: true
}
func ExampleWithServiceLock() {
c := New(
WithService(func(c *Core) Result {
return c.Service("allowed", Service{})
}),
WithServiceLock(),
)
// Can't register after lock
r := c.Service("blocked", Service{})
fmt.Println(r.OK)
// Output: false
}