artifactregistrytest

package
v1.113.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 11 Imported by: 0

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

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

func NewTestClient(t *testing.T, baseURL string) *gitlab.Client

NewTestClient builds a *gitlab.Client pointed at baseURL (typically an httptest.Server's URL).

func NewTestExec

func NewTestExec(t *testing.T, srv *httptest.Server, cmdFunc cmdtest.CmdFunc) cmdtest.CmdExecFunc

NewTestExec wires cmdFunc to an api.Client pointed at srv, mirroring how f.ApiClient(hostname).Lab() resolves in production.

func NewTestServer

func NewTestServer(t *testing.T, handler http.HandlerFunc) (*httptest.Server, *atomic.Int32)

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

type WireRequest struct {
	Audience  string `json:"audience"`
	ExpiresIn int    `json:"expires_in"`
}

WireRequest mirrors the JSON body artifactregistry.Client sends to POST /api/v4/token_exchange.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL