Documentation
¶
Overview ¶
Package protocoltest drives the public HTTP service-protocol seam of a Host without a Restate server. It sends version-5 start/input frames and acknowledges actual Run proposals; it does not emulate retries, timers, or engine durability. Tests inspect observable output and state commands, not driver internals.
frames := protocoltest.Invoke(t, host, protocoltest.Invocation{
Path: "/invoke/Demo/Run",
Input: []byte(`{"v":"input"}`),
})
_ = frames
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Start ¶
Start starts a host after its public drivers/runners have registered handlers. Cleanup stops the endpoint and joins its serving goroutine before returning. Configure a loopback Addr, AllowInsecure, and no Register to keep the endpoint local. This helper does not provision an external Restate server.
host := restate.New(func(host *restate.Builder) {
host.Addr("127.0.0.1:0")
host.AllowInsecure(true)
})
protocoltest.Start(t, host)
Types ¶
type Frame ¶
type Frame struct {
// Type is the numeric service-protocol message type, not an HTTP status.
//
// output := frame.Type == 0x0401
// _ = output
Type uint16
// Body is the protobuf payload, owned independently of the HTTP reader.
//
// _ = Frame{Body: data}.Bytes(1)
Body []byte
}
Frame contains one response message as specified by service protocol v5. Bytes and Uint decode individual fields without depending on SDK internals.
for _, frame := range protocoltest.Invoke(t, host, invocation) {
_ = frame.Bytes(14)
}
func Invoke ¶
Invoke sends an invocation through a started Host and returns all response frames through End, Error, or suspension. HTTP/2 supports full-duplex Run acknowledgments. A bounded context and joined initial writer prevent leaks when the handler or protocol is broken. No external service is contacted.
frames := protocoltest.Invoke(t, host, protocoltest.Invocation{
Path: "/invoke/Demo/Run", Input: []byte(`{"v":"input"}`),
})
_ = frames
func Replay ¶
Replay resubmits the same invocation with the commands and acknowledged Run results from a previous Invoke. The real SDK decides which closures to skip; this helper neither invokes application handlers nor supplies invented results. This checks SDK replay, not persistence or routing by a real Restate server.
first := protocoltest.Invoke(t, host, invocation) replayed := protocoltest.Replay(t, host, invocation, first) _ = replayed
func (Frame) Bytes ¶
Bytes returns a length-delimited field or nil when absent or malformed. It returns a slice of Body; callers must not mutate frames they still inspect.
value := frame.Bytes(14)
_ = protocoltest.Frame{Body: value}.Bytes(1)
func (Frame) Uint ¶
Uint returns a varint field and whether it was explicitly encoded. This distinguishes an optional zero retry delay from an omitted delay. Ordinary proto3 scalar fields can omit their valid zero default, so presence alone is not a validity check for every numeric field.
delay, present := frame.Uint(8) _ = delay _ = present
type Invocation ¶
type Invocation struct {
// Path is the endpoint's native invocation path, including /invoke.
//
// _ = Invocation{Path: "/invoke/Demo/Run"}
Path string
// Key is the logical object/workflow key; empty is valid for a service.
//
// _ = Invocation{Key: "run-42"}
Key string
// Input is valid JSON consumed by the registered native handler.
//
// _ = Invocation{Input: []byte(`{"v":"input"}`)}
Input []byte
// State maps native state keys to their encoded JSON values.
//
// _ = Invocation{State: map[string][]byte{"gen": []byte(`3`)}}
State map[string][]byte
// RetryCount models retries since the last stored journal entry, not a
// completed retry loop.
//
// _ = Invocation{RetryCount: 1}
RetryCount uint64
// contains filtered or unexported fields
}
Invocation supplies one native invocation, not an ingress request. State is an eager snapshot retained only while encoding the request. Invoke copies it onto the wire; nil state means the object has no stored keys.
frames := protocoltest.Invoke(t, host, protocoltest.Invocation{
Path: "/invoke/Demo/Run", Key: "run-42", Input: []byte(`null`),
})
_ = frames
func (Invocation) Bytes ¶
func (invocation Invocation) Bytes() []byte
Bytes builds independent start and input frames for a native HTTP request. One known entry means only input is replayed; Run closures execute in the host.
body := bytes.NewReader(protocoltest.Invocation{Input: []byte(`null`)}.Bytes())
_ = body