Skip to main content
The Go SDK provides some testing utilities to test your Restate handlers. This uses Testcontainers to run a Restate Server in a Docker container and provides a client to let you test your Restate handlers.

Testing handlers

If you have a service as follows:
type Greeter struct{}

func (Greeter) Greet(ctx restate.Context, req string) (string, error) {
  return fmt.Sprintf("Hello %s!", req), nil
}
Then you can test it via:
import (
  "testing"

  restate "github.com/restatedev/sdk-go"
  restateingress "github.com/restatedev/sdk-go/ingress"
  restatetest "github.com/restatedev/sdk-go/testing"
  "github.com/stretchr/testify/require"
)

func TestWithTestcontainers(t *testing.T) {
  tEnv := restatetest.Start(t, restate.Reflect(Greeter{}))
  client := tEnv.Ingress()

  out, err := restateingress.Service[string, string](client, "Greeter", "Greet").
    Request(t.Context(), "Francesco")
  require.NoError(t, err)
  require.Equal(t, "You said hi to Francesco!", out)
}