Digging Deeper
Testing
Use Laravel Go’s laraveltest package with tenancy installed:
pkg := tenancy.New(func(cfg *tenancy.Config) {
cfg.Drivers = []db.Driver{sqlite.Driver}
cfg.CentralDomains = []string{"localhost"}
cfg.Database.TemplateURL = "sqlite:" + filepath.Join(dir, "{database}")
cfg.TenantMigrations = migrations
cfg.Identification.SingleDomainTenants = true
})
client := laraveltest.New(t, laravel.Options{
Drivers: []db.Driver{sqlite.Driver},
Packages: []laravel.Package{pkg},
Config: laraveltest.Config(),
Routes: laravel.Routes{
Web: func(route *routing.Router, _ *config.Config) {
route.Middleware(pkg.PreventCentral(), pkg.ByDomain()).Group(func(route *routing.Router) {
route.Get("/app", home)
})
},
},
}, laraveltest.RefreshDatabase)Drive domain identification with absolute URLs (http://acme.test/…) so
Request.Host is set.
Call tenancy.End(ctx) between manual Initialize calls when a test must
return to the central
context.
Package test map
| File | Covers |
|---|---|
security_test.go |
Cross-tenant isolation, fail-closed ID, pool reuse, filesystem escapes |
identification_test.go |
Domain, subdomain, path, request data, Origin, multi-domain, EnsureTenant |
early_test.go |
Early identification + universal / route modes |
lifecycle_test.go |
Create/provision/delete, Run, pipelines, From |
herd_test.go |
Herd domain rewrite, aliases, soft-fail, opt-out |
single_database_test.go |
BelongsToTenant scoping |
bootstrappers_test.go |
Cache, session, queue, filesystem, Central |
commands_test.go |
`tenants:list |
config_test.go / context_test.go |
Env/validation and context helpers |