MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestClientNext

Function TestClientNext

lambda/runtime_api_client_test.go:21–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19)
20
21func TestClientNext(t *testing.T) {
22 dummyRequestID := "dummy-request-id"
23 dummyPayload := `{"hello": "world"}`
24
25 returnsBody := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26 if r.Method != http.MethodGet || r.URL.Path != "/2018-06-01/runtime/invocation/next" {
27 w.WriteHeader(http.StatusNotImplemented)
28 }
29 w.Header().Add(headerAWSRequestID, dummyRequestID)
30 _, _ = w.Write([]byte(dummyPayload))
31 }))
32 defer returnsBody.Close()
33
34 returnsNoBody := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
35 if r.Method != http.MethodGet || r.URL.Path != "/2018-06-01/runtime/invocation/next" {
36 w.WriteHeader(http.StatusNotImplemented)
37 }
38 w.Header().Add(headerAWSRequestID, dummyRequestID)
39 w.WriteHeader(http.StatusOK)
40 }))
41 defer returnsNoBody.Close()
42
43 t.Run("handles regular response", func(t *testing.T) {
44 invoke, err := newRuntimeAPIClient(serverAddress(returnsBody)).next(context.Background())
45 require.NoError(t, err)
46 assert.Equal(t, dummyRequestID, invoke.id)
47 assert.Equal(t, dummyPayload, invoke.payload.String())
48 })
49
50 t.Run("handles no body", func(t *testing.T) {
51 invoke, err := newRuntimeAPIClient(serverAddress(returnsNoBody)).next(context.Background())
52 require.NoError(t, err)
53 assert.Equal(t, dummyRequestID, invoke.id)
54 assert.Equal(t, 0, len(invoke.payload.Bytes()))
55 })
56
57 t.Run("error on context canceled", func(t *testing.T) {
58 ctx, cancel := context.WithCancel(context.Background())
59 cancel()
60 _, err := newRuntimeAPIClient(serverAddress(returnsNoBody)).next(ctx)
61 require.Error(t, err)
62 })
63}
64
65func TestClientDoneAndError(t *testing.T) {
66 invokeID := "theid"

Callers

nothing calls this directly

Calls 9

newRuntimeAPIClientFunction · 0.85
serverAddressFunction · 0.85
WriteHeaderMethod · 0.80
HeaderMethod · 0.80
WriteMethod · 0.80
CloseMethod · 0.45
nextMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…