Imports rewritten to mesh-sdk's (beside, catalogue, overlay). Left in mesh-controller, which holds their modules: TestTheBuilderRequiresTheRegistryTheNpmSeatDelivers (foundation_manifests_test.go), TestGenesisAssignsTheBuildAgentWithNothingProvidingTheRegistry (genesis_registry_test.go, whole file), TestRouteProxyKeepsItsPublicAccountDirectory (public_issuer_test.go), TestEveryManifestInUseClaimsASeatTheMeshDefines (seats_test.go); with controller_is_a_process_test.go and genesis_image_test.go. moduleTree reads mesh-catalog only: mesh-sdk has no modules directory of its own. beside.Dir lays a repository's captured copy out once per process (a mutex and a map, os.MkdirTemp), new test TestTheCapturedCopyIsLaidOutOnce failed first (two directories). The captured copy is refreshed from the mains: mesh-catalog bb0fe93b, mesh-host cdcba9ca, only what these tests read; CAPTURED says how to move it. Unit level 1.16 s (bound 2 s).
63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package beside
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// The captured copy of a repository is laid out once per test process: a second call, in another test,
|
|
// gets the same directory (issue 1379, AC3). Laying it out per test made go/catalogue's tests take 2.14 s
|
|
// against the unit level's 2 s bound; once, 0.81 s.
|
|
func TestTheCapturedCopyIsLaidOutOnce(t *testing.T) {
|
|
t.Setenv(Env, "")
|
|
var first, second string
|
|
t.Run("one", func(t *testing.T) { first = Dir(t, "mesh-catalog") })
|
|
t.Run("two", func(t *testing.T) { second = Dir(t, "mesh-catalog") })
|
|
if first == "" || first != second {
|
|
t.Fatalf("the captured copy was laid out twice: %q and %q", first, second)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(first, "modules")); err != nil {
|
|
t.Fatalf("the copy holds no modules directory: %v", err)
|
|
}
|
|
// And it outlives the test that first asked, which a t.TempDir would not.
|
|
if _, err := os.Stat(first); err != nil {
|
|
t.Fatalf("the copy is gone after the first test ended: %v", err)
|
|
}
|
|
}
|
|
|
|
// With MESH_CHECK_BESIDE naming a directory that lacks the repository, the test fails naming it (AC4; the
|
|
// rule is beside's own, unchanged). Dir fails the test it is given, so it is given a recorder.
|
|
func TestABesideDirectoryWithoutTheRepositoryFailsNamingIt(t *testing.T) {
|
|
empty := t.TempDir()
|
|
t.Setenv(Env, empty)
|
|
r := &recorder{TB: t}
|
|
func() {
|
|
defer func() { _ = recover() }()
|
|
Dir(r, "mesh-catalog")
|
|
}()
|
|
if !r.failed {
|
|
t.Fatal("a repository missing beside the check did not fail the test")
|
|
}
|
|
if want := "mesh-catalog is not beside this check in " + Env + "=" + empty; len(r.msg) < len(want) || r.msg[:len(want)] != want {
|
|
t.Fatalf("the failure does not name the repository and the directory: %q", r.msg)
|
|
}
|
|
}
|
|
|
|
type recorder struct {
|
|
testing.TB
|
|
failed bool
|
|
msg string
|
|
}
|
|
|
|
func (r *recorder) Fatalf(format string, args ...any) {
|
|
r.failed = true
|
|
r.msg = sprintf(format, args...)
|
|
panic(stop{})
|
|
}
|
|
|
|
type stop struct{}
|
|
|
|
func sprintf(format string, args ...any) string { return fmt.Sprintf(format, args...) }
|