Documentation
¶
Overview ¶
Package harness builds the production router for the server-assembly suites under test/server, a seeded world of users, permissions and repositories behind it, and the application runtime that serve opens.
Role ¶
Test support, outside the modules, for the server-assembly suites under test/server. It is the one place those suites build the router from, so a change to how the router is built edits this package and no suite. Production code never imports it.
Inputs ¶
- Config values from the suites, and Tune functions that adjust one before the router is built.
- The router and its configuration from internal/app (app.NewRouter and app.RouterConfig); the seeding, password hashes and request helpers of test/server/support; an in-memory store and a file-system blob store.
- The application runtime from internal/app (app.OpenRuntime) with the default configuration of internal/app/config, and a fake upstream from the artifacts module's fakeupstream.
- Root-relative fixture paths, which RepoFile resolves through platform/testkit/repopath.
Outputs ¶
- Router: the production http.Handler built from a Config.
- Store: the type of Config.Store, app.RouterStore, as an alias, which a suite's fakes embed.
- Mirrors, MirrorStatus, SearchLimits and DefaultRedirectTTL: the types and the default of the Config fields that suites name, as aliases of those the artifacts module's HTTP adapter declares, so that a suite names them through this package alone.
- ItemWorld, from NewItemWorld: the router over a store seeded with the users reader, deployer and user, the deploy-libs permission, anonymous read of every remote repository when asked for (AnonymousRemotes) and eight local, remote and virtual repositories, and a blob store that signs storage URLs (StorageSigner, SigningBlobs). Do, Item and WantStatus send requests to it and check what they left behind.
- RepoFile: the absolute path of a root-relative fixture.
- App: the application runtime opened as serve opens it, over AppConfig (the default configuration with a temporary data directory) with AppOptions (a cheap password hash and a small signing key), closed when the test ends.
- RemoteWorld, from NewRemoteWorld: the router over an App runtime with the generic remote repository remote in front of a fake upstream, the users reader and denied and the remote-read permission. Request sends requests to it and Update saves a changed remote.
Invariants ¶
- test/server/support never imports this package. internal/app's in-package tests import support, and this package imports internal/app, so the import would close a cycle.
- internal/app's in-package tests never import this package: it imports internal/app, so the import would close a cycle.
- NewItemWorld builds the same world as newItemWorld, the in-package fixture of the router's guards in internal/app (fixtures_test.go), which keep their own copy because they cannot import this package. A change to one is made to the other.
References ¶
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Package placement and names": test/server/support/harness, a package the target document does not name; "Names the migration introduces").
- Decision 0015: docs/research/decisions/0015-testing-and-acceptance.md (server-assembly suites run against the production router).
- docs/testing/server-test-packages.md: how the suites under test/server are laid out and what they share.
- Plan: docs/implementation/plan.md#p9d-modular-monolith-migration, epic TST (https://github.com/weaveplatform/artifactweave/issues/945).
- https://github.com/weaveplatform/artifactweave/issues/997
- https://github.com/weaveplatform/artifactweave/issues/1096 (App and RemoteWorld, for the suites that left internal/app).
- https://github.com/weaveplatform/artifactweave/issues/1097 (the router built through app.NewRouter).
Status ¶
Implemented P9d (issues 997, 1096 and 1097).
Testing ¶
The package has no tests of its own: the suites under test/server exercise it. .testcoverage.yml leaves it out of the coverage gate, and the production handlers it builds stay in the gate.
Index ¶
- Constants
- func App(t *testing.T, mutate func(*config.Config)) *app.Runtime
- func AppConfig(t *testing.T) config.Config
- func AppOptions() app.RuntimeOptions
- func RepoFile(tb testing.TB, rel string) string
- func Router(c Config) http.Handler
- func WantStatus(t *testing.T, rec *httptest.ResponseRecorder, want int)
- type Config
- type ItemWorld
- type MirrorStatus
- type Mirrors
- type RemoteWorld
- type SearchLimits
- type SigningBlobs
- type Store
- type Tune
Constants ¶
const AnonymousRemotes = "anonymous-remotes"
AnonymousRemotes names the permission NewItemWorld gives anonymous when anonymous access is on: read on every remote repository. The seeded Any Remote permission grants anonymous nothing (#383), so anonymous reads remotes through this one, and a test that deletes it takes those reads away.
const DefaultRedirectTTL = itemkit.DefaultRedirectTTL
DefaultRedirectTTL is how long a signed download URL stays valid when Config.Redirect sets no TTL.
Variables ¶
This section is empty.
Functions ¶
func App ¶
App opens the application runtime for t as serve opens it, over AppConfig(t) changed by mutate when mutate is not nil, with AppOptions' costs and a logger that discards, and closes it when t ends. A test that restarts the runtime opens it with app.OpenRuntime instead, since it closes the first runtime itself.
func AppConfig ¶
AppConfig returns the configuration App starts from: config.Default() with its data directory under t's temporary directory, so that each runtime has a store and blob tiers of its own.
func AppOptions ¶
func AppOptions() app.RuntimeOptions
AppOptions returns the costs App opens the runtime with: support.TestHash and the smallest RSA key Go accepts. Every runtime seeds the admin, builds an authenticator and generates a signing key, and production's costs made the suites take minutes under the race detector; verification reads the cost from each stored hash, so every password still checks.
func RepoFile ¶
RepoFile returns the absolute path of rel, a slash-separated path relative to the repository root such as "api/access.openapi.yaml", and fails tb when rel is empty, absolute or has "." or ".." elements. It is repopath.Path rather than a search of its own for go.mod, so every test finds the root one way.
func Router ¶
Router returns the production router built from c by app.NewRouter, with every protocol route, authentication and the middleware the server runs. Suites build the router only through Router, so a change to how the router is built edits this one call.
func WantStatus ¶
func WantStatus(t *testing.T, rec *httptest.ResponseRecorder, want int)
WantStatus fails t, printing the response body, unless rec has the status want.
Types ¶
type Config ¶
type Config = app.RouterConfig
Config is the configuration the production router is built from: the stores, authentication, base URL, compatibility version and every option a suite sets. It is an alias of app.RouterConfig, not a copy, so a suite's composite literals and Tune functions name the type the router takes.
type ItemWorld ¶
ItemWorld is the production router over a seeded in-memory store and a file-system blob store, built by NewItemWorld for one test. Every user's password is "pw": admin; reader (in readers, so it reads everything); deployer (may deploy to libs-local but not delete); user (no rights). Do sends requests to H; DB and Blobs let a test seed state or check what a request left behind.
func NewItemWorld ¶
NewItemWorld builds an ItemWorld for t. The store is seeded as a new server seeds it, then given the users reader, deployer and user; deploy-libs, which lets deployer read and write libs-local; when anonymous is true, anonymous access and the AnonymousRemotes permission; the local repositories libs-local, other-local, server-local (server-generated checksums) and redirect-local (download redirect); the remote up; and the virtual repositories virt (over missing, other-local, libs-local and up, deploying to libs-local), loop (over itself) and virt-nodeploy (over libs-local, with no deployment repository). Blobs are files under t's temporary directory behind StorageSigner. The router's base URL is https://reg.example and it reports Artifactory 7.155.0; tune adjusts that configuration, in order, before the router is built, for tests that need another blob store or a logger they can read. NewItemWorld fails t when any part cannot be built.
func (*ItemWorld) Do ¶
func (w *ItemWorld) Do( method, path, as, body string, headers ...string, ) *httptest.ResponseRecorder
Do sends a request to the world's router as the user as, with the password "pw" over Basic, or without credentials when as is empty. headers are name and value pairs; a trailing name without a value is ignored.
type MirrorStatus ¶
type MirrorStatus = artifactshttp.MirrorStatus
MirrorStatus is one tier's mirror in what Mirrors reports.
type Mirrors ¶
type Mirrors = artifactshttp.Mirrors
Mirrors is the type of Config.Mirrors, the blob mirrors whose state the storage summary reports and whose repair an administrator starts. A suite implements it to choose what the router sees.
type RemoteWorld ¶
type RemoteWorld struct {
T *testing.T
Runtime *app.Runtime
H http.Handler
Upstream *fakeupstream.Server
Repo repo.Config
}
RemoteWorld is the router over an application runtime that App opened, with a generic remote repository in front of a fake upstream, built by NewRemoteWorld for one test. Every user's password is "pw": admin; reader, which may read the remote and fill its cache; denied, which may not read it. A test that changes Repo saves it with Update, and one that needs other router options replaces H with a router over Runtime.
func NewRemoteWorld ¶
func NewRemoteWorld(t *testing.T) *RemoteWorld
NewRemoteWorld builds a RemoteWorld for t: App with the admin password "pw"; the generic remote repository "remote" over a fake upstream, with repo.Defaults' settings; the users reader and denied, whose password hash is support.CheapHash; the permission remote-read, which lets reader read remote and fill its cache (Read and Deploy/Cache, since 7.x fills a remote's cache only for a caller with Deploy/Cache on it, #1587); and the router over the runtime's store, hot blob store, authenticator, token service and keyring and the artifacts module's remote sources and remote HTTP pool, with a logger that discards.
func (*RemoteWorld) Request ¶
func (w *RemoteWorld) Request( method, path, user, body string, headers ...string, ) *httptest.ResponseRecorder
Request sends method path with body to H, as user with the password "pw" when user is not empty and anonymously otherwise, with headers given as name, value pairs, and returns the response.
func (*RemoteWorld) Update ¶
func (w *RemoteWorld) Update()
Update saves Repo, which the test changed, through the runtime's store.
type SearchLimits ¶
type SearchLimits = artifactshttp.SearchLimits
SearchLimits is the type of Config.Search, the result caps of the GET searches.
type SigningBlobs ¶
SigningBlobs makes a blob store a blob.Signer of the routes listed in Routes, with the signing options readable back from the URL, as an object store that signs download URLs would be. Err, when set, fails every signature.
func StorageSigner ¶
func StorageSigner(st blob.Store) SigningBlobs
StorageSigner returns st as SigningBlobs that sign storage URLs only, as an object store without a CDN does. NewItemWorld's blob store is one.
func (SigningBlobs) SignURL ¶
func (b SigningBlobs) SignURL(_ context.Context, sha string, o blob.SignOptions) (string, error)
SignURL returns Err when it is set. Otherwise it returns a URL on the host "<via>.example", such as storage.example, for the blob sha, with the TTL, file name and content type of o in its query, so a test can read back what the server asked to sign. It does not check Signs.
type Store ¶
type Store = app.RouterStore
Store is the type of Config.Store, the metadata store the router is built over: app.RouterStore. It is an alias, so a suite's fake can embed it and wrap whatever store the suite's Tune finds in Config.Store; test files of a module, which may import test support from app but not app itself, name it here.