Documentation
¶
Overview ¶
Package intercomtest provides offline test helpers for code using intercom-go.
The package is built around httptest and does not call Intercom. Tests script expected routes, run SDK calls against the local server, and then inspect the captured requests.
Example:
srv := intercomtest.NewServer(t,
intercomtest.Route("GET", "/me", intercomtest.JSON(200, `{
"type": "admin",
"id": "admin-1",
"email": "admin@example.com"
}`)),
)
client, err := srv.Client("token")
if err != nil {
t.Fatal(err)
}
admin, err := client.Admins.Me(context.Background())
if err != nil {
t.Fatal(err)
}
if admin.Email == nil || *admin.Email != "admin@example.com" {
t.Fatalf("unexpected admin email: %v", admin.Email)
}
req := srv.Request(t, 0)
if req.Method != "GET" || req.Path != "/me" {
t.Fatalf("unexpected request: %s %s", req.Method, req.Path)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler describes one expected Intercom request and the response to return.
type Response ¶
Response describes an HTTP response returned by a scripted route.
type Server ¶
type Server struct {
// URL is the local base URL clients should use.
URL string
// contains filtered or unexported fields
}
Server is an offline Intercom API test server.
func (*Server) RequestCount ¶
RequestCount returns the number of captured requests.
Click to show internal directories.
Click to hide internal directories.