Skip to content

Instantly share code, notes, and snippets.

@Jimeux
Last active December 22, 2021 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimeux/9c18d890075e9042406484ee7726401e to your computer and use it in GitHub Desktop.
Save Jimeux/9c18d890075e9042406484ee7726401e to your computer and use it in GitHub Desktop.
func TestHandler(t *testing.T) {
logger = ws.NewNopLogger()
t.Run("returns 200 on successful save", func(t *testing.T) {
ddb := &awsiface.MockDDB{}
ddb.PutItemFn = func(ctx context.Context, params *dynamodb.PutItemInput, optFns ...func(*dynamodb.Options)) (*dynamodb.PutItemOutput, error) {
return &dynamodb.PutItemOutput{}, nil
}
repo := ws.NewRepository(ddb, "connections")
svc = ws.NewWebSocketService(nil, repo)
res, err := handler(context.Background(), &events.APIGatewayWebsocketProxyRequest{})
if err != nil {
t.Fatalf("unexpected error: %+v", err)
}
if res.StatusCode != http.StatusOK {
t.Fatalf("did not return valid response: got %d but expected %d", res.StatusCode, http.StatusOK)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment