vtest

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package vtest provides reusable, table-driven test helpers shared by the secret verifier packages.

It is placed under internal/verifier/internal so it can only be imported by verifier packages. The helpers exercise the failure paths that every HTTP verifier must handle safely:

  • a transport error (the server is closed) must yield StatusVerifyError;
  • a cancelled context must yield StatusVerifyError and NEVER StatusVerifiedInactive (a network failure is not evidence the secret is inactive);
  • a 200 response with a malformed JSON body must yield a defined status (the project standardizes this to StatusVerifyError).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, c Case)

Run executes the shared safety suite against the verifier produced by c.New.

It does not contact any real service: a closed httptest server is used for the transport-error and cancellation cases, and a live httptest server that returns 200 with a non-JSON body is used for the malformed-body case.

Types

type Case

type Case struct {
	// Name is the verifier name, used as the subtest prefix.
	Name string

	// New builds the verifier under test.
	New Factory

	// Raw is a representative finding to verify. Its Raw value should be a
	// plausibly formatted secret so the verifier reaches the HTTP call.
	Raw detector.RawFinding

	// MalformedStatus is the status the verifier returns for a 200 response
	// whose body is not valid JSON. Defaults to StatusVerifyError when zero
	// (the project standard). Set explicitly for verifiers that only inspect
	// the status code and do not decode a body.
	MalformedStatus finding.VerificationStatus

	// SkipMalformed skips the malformed-body case for verifiers that never
	// decode a response body on success.
	SkipMalformed bool
}

Case configures the shared verifier suite for one verifier package.

type Factory

type Factory func(apiURL string, client *http.Client) verifier.Verifier

Factory builds a verifier under test, wired to the given base URL and HTTP client. Both the URL and the client originate from a test server so that no real network call is made.

Jump to

Keyboard shortcuts

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