- list, list --all, list --format=json and an --ansi styled list (D-13, D-16)
- admin:token:create help and a passthrough help; help <cmd> equals --help (D-14)
- error blocks: hint with {bin}, unknown command, -v chain on stderr (D-18)
- CheckDocs gaps in order and sorted; the version header and BuildVersion
- goldens render with color detection cleared; -update rewrites them
76 lines
3.3 KiB
Go
76 lines
3.3 KiB
Go
package bonfire
|
|
|
|
import (
|
|
"runtime/debug"
|
|
"testing"
|
|
)
|
|
|
|
// TestVersionHeader: the list header and BuildVersion for a tagged
|
|
// framework dependency, a replaced (local) one, a go.work build (devel)
|
|
// and the summer tool's own build, read through an injected build info.
|
|
func TestVersionHeader(t *testing.T) {
|
|
headers := []struct {
|
|
v Version
|
|
name string
|
|
want string
|
|
}{
|
|
{Version{App: "v1.4.0", Framework: "v0.3.2"}, "acme", "SummerCMS acme v1.4.0 (framework v0.3.2)"},
|
|
{Version{App: "devel", Framework: "v0.4.0", Local: true}, "acme", "SummerCMS acme devel (framework v0.4.0, local)"},
|
|
{Version{App: "v1.4.1-0.20261021120000-abcdef123456+dirty", Framework: "(devel)"}, "acme", "SummerCMS acme v1.4.1-0.20261021120000-abcdef123456+dirty (framework devel)"},
|
|
// Equal versions collapse to one, as for the summer tool's own build.
|
|
{Version{App: "(devel)", Framework: "(devel)"}, "acme", "SummerCMS acme devel"},
|
|
{Version{App: "v0.4.0", Framework: "v0.4.0"}, "summer", "SummerCMS summer v0.4.0"},
|
|
{Version{App: "v0.4.0", Framework: "v0.4.0", Local: true}, "acme", "SummerCMS acme v0.4.0 (framework v0.4.0, local)"},
|
|
{Version{}, "acme", "SummerCMS acme devel"},
|
|
}
|
|
for _, tc := range headers {
|
|
if got := tc.v.Header(tc.name); got != tc.want {
|
|
t.Errorf("%+v.Header(%q) = %q, want %q", tc.v, tc.name, got, tc.want)
|
|
}
|
|
}
|
|
|
|
dep := func(version string, replaced bool) *debug.Module {
|
|
m := &debug.Module{Path: frameworkModule, Version: version}
|
|
if replaced {
|
|
m.Replace = &debug.Module{Path: "../summercms.go", Version: "(devel)"}
|
|
}
|
|
return m
|
|
}
|
|
builds := []struct {
|
|
name string
|
|
info *debug.BuildInfo
|
|
ok bool
|
|
want Version
|
|
}{
|
|
{"tagged", &debug.BuildInfo{Main: debug.Module{Path: "example.com/acme", Version: "v1.4.0"},
|
|
Deps: []*debug.Module{{Path: "example.com/other", Version: "v9.9.9"}, dep("v0.3.2", false)}},
|
|
true, Version{App: "v1.4.0", Framework: "v0.3.2"}},
|
|
{"replaced", &debug.BuildInfo{Main: debug.Module{Path: "example.com/acme", Version: "(devel)"},
|
|
Deps: []*debug.Module{dep("v0.4.0", true)}},
|
|
true, Version{App: "devel", Framework: "v0.4.0", Local: true}},
|
|
{"go.work", &debug.BuildInfo{Main: debug.Module{Path: "example.com/acme", Version: "v1.4.1-0.20261021120000-abcdef123456+dirty"},
|
|
Deps: []*debug.Module{dep("(devel)", false)}},
|
|
true, Version{App: "v1.4.1-0.20261021120000-abcdef123456+dirty", Framework: "devel"}},
|
|
{"no framework dep", &debug.BuildInfo{Main: debug.Module{Path: "example.com/acme", Version: "v1.0.0"}},
|
|
true, Version{App: "v1.0.0", Framework: "devel"}},
|
|
{"summer", &debug.BuildInfo{Main: debug.Module{Path: frameworkModule, Version: "v0.4.0"}},
|
|
true, Version{App: "v0.4.0", Framework: "v0.4.0"}},
|
|
{"no build info", nil, false, Version{App: "devel", Framework: "devel"}},
|
|
}
|
|
for _, tc := range builds {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
prev := readBuildInfo
|
|
t.Cleanup(func() { readBuildInfo = prev })
|
|
readBuildInfo = func() (*debug.BuildInfo, bool) { return tc.info, tc.ok }
|
|
if got := BuildVersion(); got != tc.want {
|
|
t.Errorf("BuildVersion() = %+v, want %+v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
|
|
// The test binary is built from the framework module itself.
|
|
if got := BuildVersion(); got.App != got.Framework || got.Local {
|
|
t.Errorf("the framework's own build = %+v, want App == Framework", got)
|
|
}
|
|
}
|