Documentation
¶
Overview ¶
Package artifactregistrytest provides shared test helpers for internal/api/artifactregistry and the commands built on top of it, so their tests don't each redefine the same fake token_exchange server and fake JWT.
Index ¶
- func MakeJWT(t *testing.T, claims jwt.RegisteredClaims) string
- func NewTestClient(t *testing.T, baseURL string) *gitlab.Client
- func NewTestExec(t *testing.T, srv *httptest.Server, cmdFunc cmdtest.CmdFunc) cmdtest.CmdExecFunc
- func NewTestServer(t *testing.T, handler http.HandlerFunc) (*httptest.Server, *atomic.Int32)
- func NewTokenExchangeServer(t *testing.T, wantToken string, gotBody *WireRequest) (*httptest.Server, *atomic.Int32)
- type WireRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeJWT ¶
func MakeJWT(t *testing.T, claims jwt.RegisteredClaims) string
MakeJWT mints a JWT carrying claims. Code under test never verifies token signatures, so any signing key works here.
func NewTestClient ¶
NewTestClient builds a *gitlab.Client pointed at baseURL (typically an httptest.Server's URL).
func NewTestExec ¶
NewTestExec wires cmdFunc to an api.Client pointed at srv, mirroring how f.ApiClient(hostname).Lab() resolves in production.
func NewTestServer ¶
NewTestServer starts a fake token_exchange endpoint and returns it along with a counter of how many requests it received, so tests can assert that invalid input never reaches the network.
func NewTokenExchangeServer ¶
func NewTokenExchangeServer(t *testing.T, wantToken string, gotBody *WireRequest) (*httptest.Server, *atomic.Int32)
NewTokenExchangeServer starts a fake token_exchange endpoint that asserts the request is a well-formed POST to the expected path, decodes its body into gotBody, and always responds with wantToken.
Types ¶
type WireRequest ¶
WireRequest mirrors the JSON body artifactregistry.Client sends to POST /api/v4/token_exchange.