Skip to content

Public test API to set URL params #233

@achiku

Description

@achiku

Thank you for creating such a wonderful library!! I have gone through issues/prs, and now put a proposal up. Any comments are welcomed!

Proposal

How do you think about adding a function to set URL params in context, which is implicitly declared as an API only for test. Testing as a public API is borrowed from this slide Advanced Testing with Go.

Background

First of all, as it's discussed in several issues, it's not good idea to make context key public or basic type since it may conflict with other keys set from different packages, and accidentally overwrite values. Secondally, it is also not good idea to make a setVars function public, since it is fundamentally not necessary for this library to work as intended, and widen its API boundary, which tend to increase difficulty to maintain a clean project.

However, it is still useful if library users can add URL params to context for testing. The main reason is that users can separate middlewares, and other routing mechanism aside when they test a function that implements http.Handler interface.

Implementation

Below is just an example.

Related issues/prs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions