Documentation
¶
Overview ¶
Package testserver stands in for meshStack's login endpoint and for one endpoint behind it, so that a test can drive the token cache without a backend.
It imports internal/auth for the api key settings. A package whose own tests live in the internal test package therefore cannot use it without creating an import cycle, and has to move those tests to an external test package first.
Index ¶
- type ApiKey
- type Counts
- type GreetingClient
- type Server
- func (s *Server) Counts(t *testing.T) Counts
- func (s *Server) Greeting(t *testing.T, ctx context.Context, greet GreetingClient) error
- func (s *Server) GreetingUrl(t *testing.T) *url.URL
- func (s *Server) MintToken(t *testing.T, validFor time.Duration) string
- func (s *Server) RequireGreeting(t *testing.T, greet GreetingClient)
- func (s *Server) RevokeNewestToken(t *testing.T) (revoked bool)
- func (s *Server) Url(t *testing.T) *url.URL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GreetingClient ¶
GreetingClient is all this package needs of the code under test: a GET that parses a JSON string, carrying whatever authorization the caller wired up.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Greeting ¶
Greeting calls the authorized endpoint and returns what went wrong, for a caller on its own goroutine, where require may not be used.
func (*Server) MintToken ¶
MintToken issues a token this Server honors, exactly as its login endpoint does, for a test that hands one to the code under test directly.
func (*Server) RequireGreeting ¶
func (s *Server) RequireGreeting(t *testing.T, greet GreetingClient)
func (*Server) RevokeNewestToken ¶
RevokeNewestToken stops honoring the newest token still honored, and reports whether there was one. The newest is the one a cache is most likely to be holding, so it is the one that makes a caller refresh.
A concurrent caller must not have a request in flight while this runs. An authorized client retries a 401 exactly once, and the token it retries with can be one it adopted from another process's cache, so revoking during a request can leave a 401 that nothing recovers from.