Documentation
¶
Overview ¶
Package fakeupstream provides deterministic, loopback-only HTTP fixtures for remote repository tests. It models upstream mechanics, not observed Artifactory behavior. Keep ecosystem documents in the adapter tests that understand their schemas.
Index ¶
Constants ¶
const Redacted = "[REDACTED]"
Variables ¶
This section is empty.
Functions ¶
func ClientIdentity ¶
ClientIdentity creates a test-only CA and client certificate for mTLS. Configure Options.TLS with the returned pool and RequireAndVerifyClientCert, then place the certificate in the client's TLS config. No keys are written to disk or logs.
Types ¶
type Auth ¶
type Auth struct{ Username, Password, Token string }
Auth requires either a bearer Token or a basic Username/Password. An empty policy permits anonymous requests. A token takes precedence over basic credentials.
type Barrier ¶
type Barrier struct {
// contains filtered or unexported fields
}
Barrier holds requests until Release. Reached closes when the first waiter arrives. Both releasing repeatedly and sharing one barrier across requests are safe.
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock supplies the same controllable time to the upstream and the cache under test. It does not replace timers: use barriers for network scheduling.
type Fault ¶
type Fault struct {
BeforeHeaders *Barrier
BeforeBody *Barrier
DropConnection bool
TruncateAfter int64
LengthDelta int64
}
Fault interrupts a normal resource without sleeps. TruncateAfter > 0 aborts the connection after that many body bytes. LengthDelta falsifies Content-Length. BeforeBody flushes headers first, allowing clients to observe a stalled body.
type Options ¶
type Options struct {
TLS *tls.Config
Now func() time.Time
Auth Auth
// Secrets also redacts fixture-specific secrets embedded in paths or safe headers.
// Query values, credentials, cookies and unrecognized headers are always redacted.
Secrets []string
}
Options are fixed before starting the server. TLS enables HTTPS; ClientCAs and ClientAuth can require a client certificate. Now defaults to time.Now.
type Request ¶
type Request struct {
Method string
Path string
Host string
Header http.Header
Query url.Values
At time.Time
Authorized bool
VerifiedClientCertificate bool
// contains filtered or unexported fields
}
Request is safe to include in assertion failures. It never contains a request body, URL userinfo, raw query values or credential/cookie header values. HeaderMatches compares a candidate without storing its plaintext in the record.
func (Request) HeaderMatches ¶
type Resource ¶
type Resource struct {
// Method optionally permits one explicit request method instead of GET/HEAD.
Method string
Body []byte
Header http.Header
Modified time.Time
ETag string
Status int
Redirect string
Fault Fault
}
Resource is an atomic response snapshot. Set copies Body and Header. A zero Status serves normal content with HEAD, Range and HTTP validators. Other statuses serve Body verbatim. Redirect uses Status or defaults to 302.
type Server ¶
type Server struct {
URL string
// contains filtered or unexported fields
}
Server owns its listener and connections; New registers cleanup with the test. Set/Delete/Requests/Count may run concurrently with requests.
func NewProxy ¶
NewProxy starts an HTTP forward proxy with optional proxy authentication. Only the supplied running fixtures are reachable: an absolute URL or CONNECT cannot accidentally turn a fault test into a public-registry fetch. CONNECT can tunnel either scheme; the client still verifies the destination's certificate.
func (*Server) Certificate ¶
func (s *Server) Certificate() *x509.Certificate
func (*Server) Count ¶
Count matches the decoded path before redaction; empty method/path match all.