Files
go-admin/test/e2e-apporder/main.go
zhangwenjian 3a5afeb518 test: install and uninstall the example application end to end
Everything under `migrate install` was covered with an injected engine and a
hand-built schema, which is where the shapes belong. What none of it could
catch is the wiring: whether an application's init() reaches both registries,
whether the installer finds a manifest through app.Snapshot, whether the
seeder writes what the uninstaller goes looking for, and whether the command
exits non-zero when a migration fails - which a deployment reads to decide
whether to start the new version.

This builds a go-admin binary with the example application linked in, migrates
a real database with it, and drives the whole sequence: framework migrations
only, install, install again, put a row in the application's own table,
uninstall, reinstall.

It lives in its own module. A tagged import in the main module would still be
resolved by `go mod tidy`, which considers every build tag and would go
looking for github.com/go-admin-team/example-app-order on the network - a
repository that does not exist, because the example is a directory inside this
one. That was checked rather than assumed: tidy fails there with "Repository
not found". A build tag of `ignore` is skipped by tidy but cannot be turned on
either, because the standard library uses it for files that are not meant to
build at all. A separate module with replace directives is invisible to the
main module's tidy, its build, its tests and checksilent, and needs no
go.work.

Three degradations turn it red: the example application not registering a
manifest, the uninstall not clearing sys_migration - where the reinstall then
seeds nothing and the assertion reads "menus = 0, want 4" - and the seeder not
recording its grants, where the uninstall then leaves every policy behind.
2026-09-09 16:40:15 +08:00

29 lines
1.1 KiB
Go

// Command e2e-apporder is a go-admin binary with the example application
// linked into it.
//
// It exists because there is otherwise nothing to install. `migrate install
// order` looks the code up in the registries an application fills from its
// own init(), and an application the binary was not built with registers
// nothing - so every path through the installer past its first check went
// untested, and so did the seeding, the ledger and the uninstall against
// anything but a hand-built fixture.
//
// This lives in its own module, not behind a build tag in the main one. A
// tagged import there would still be resolved by `go mod tidy`, which
// considers every build tag and would go looking for
// github.com/go-admin-team/example-app-order on the network - a repository
// that does not exist, because the example is a directory inside this one.
// A separate module with replace directives is invisible to the main
// module's tidy, its build and its tests, and needs no go.work.
package main
import (
_ "github.com/go-admin-team/example-app-order/migration"
"go-admin/cmd"
)
func main() {
cmd.Execute()
}