KubFly SDK for Go / kubflytest
package kubflytest
import "kubfly.io/sdk/kubflytest"
Package kubflytest is the telemetry of a test as the types of reflector — the kubfly-sdk-test module of the Java SDK: a body runs in a root frame of its own, and its capture is everything of the trace of that frame — the frames under it by their parent, on any goroutine the context goes to; the frames of other services of the process it called, by their caller (net/http in the same process); the events and the ends of all of them. Tests in parallel do not see one another: each has its own trace.
capture, err := kubflytest.RunNamed(ctx, "ship", func(ctx context.Context) error { return orders.Ship(ctx, 42) })
items, err := capture.Items(ctx)
for item, err := range items.All() {
if event, ok := item.(*reflector.Event); ok && event.Level == api.LevelError {
t.Error(event.Message())
}
}
Linking the package in registers the collector: the real collector of a bucket (output/bucket.Of) writing into a bucket in memory (bucket/mem), every event from api.LevelTrace and every frame, under the stand "test" — namespace, service, pod and container "test", the instance of the process; reflector reads it, as the bucket of a stand is read: a test sees what Navigator would see, the format included. api.Collectors.Install stays free.
Only the events and the frames have a trace; metrics, alerts, health, traffic and profiles are of the whole process — Process. An event outside any frame belongs to no capture either: it is in Process only. The bucket lives as long as the process and only grows.
Constants
const Name = "test"
Name is the name of the stand and of every level of its tree.
Functions
func Process
func Process() (*reflector.Query, error)
Process is the whole process as reflector reads it: every stream — metrics, alerts, health, traffic, profiles, and the events outside any frame. The interval of the metrics is taken now (api.Collectors.Flush — for every collector of the process), then everything received is written.
Types
type Capture
type Capture struct {
// contains filtered or unexported fields
}
Capture is the capture of one run: the trace of its root frame and the time it began.
func Run
func Run(ctx context.Context, body func(ctx context.Context) error) (*Capture, error)
Run runs a body in a new root frame (sdk/test/capture/run, even inside another frame) and captures its trace. The capture is given with the error of the body too.
func RunNamed
func RunNamed(ctx context.Context, name string, body func(ctx context.Context) error) (*Capture, error)
RunNamed runs a body in a new root frame with the tag test — the name of the test — and captures its trace.
func (*Capture) Items
func (c *Capture) Items(ctx context.Context) (reflector.Timeline[reflector.Item], error)
Items are the items of the capture so far, in the order of time: *reflector.Begin, *reflector.End and *reflector.Event of the frames of its trace, the root frame sdk/test/capture/run included. Everything the collector received until now is written and read anew; what another goroutine is still doing — the end of a frame of a server after its response, a consumer of a broker — may come later: ItemsUntil waits for it. The timeline is a list read once.
func (*Capture) ItemsUntil
func (c *Capture) ItemsUntil(ctx context.Context, until func(item reflector.Item) bool, timeout time.Duration) (reflector.Timeline[reflector.Item], error)
ItemsUntil are the items of the capture once one of them matches, read anew every 10 ms; an error if none matched in time, with the count of the items.
func (*Capture) String
func (c *Capture) String() string
String is the trace.
func (*Capture) Trace
func (c *Capture) Trace() uuid.UUID
Trace is the trace of the capture: that of its root frame.