- GET /version (signed-in users only) answers the version and, when the binary knows it, the commit it was built from and whether the files had uncommitted changes - the commit is read from the build info Go records in a git checkout, so no build flag is needed - the side menu shows the version under the privacy line, and Settings has an About section with it - the menu's own requests (friends, version) are not counted as requests of an admin page in the Shell tests
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"runtime/debug"
|
|
"testing"
|
|
)
|
|
|
|
func settings(kv ...string) *debug.BuildInfo {
|
|
b := &debug.BuildInfo{}
|
|
for i := 0; i+1 < len(kv); i += 2 {
|
|
b.Settings = append(b.Settings, debug.BuildSetting{Key: kv[i], Value: kv[i+1]})
|
|
}
|
|
return b
|
|
}
|
|
|
|
func TestRevisionIsTheShortCommit(t *testing.T) {
|
|
rev, modified := revision(settings("vcs", "git", "vcs.revision", "69c85a7e1d0f4b2c8a9e3f5d6b7a8c9d0e1f2a3b", "vcs.modified", "false"))
|
|
if rev != "69c85a7" || modified {
|
|
t.Errorf("got %q, %v", rev, modified)
|
|
}
|
|
}
|
|
|
|
func TestRevisionSaysWhenTheTreeWasChanged(t *testing.T) {
|
|
rev, modified := revision(settings("vcs.revision", "69c85a7e1d0f", "vcs.modified", "true"))
|
|
if rev != "69c85a7" || !modified {
|
|
t.Errorf("got %q, %v", rev, modified)
|
|
}
|
|
}
|
|
|
|
func TestRevisionIsEmptyWithoutVersionControlInfo(t *testing.T) {
|
|
if rev, modified := revision(settings()); rev != "" || modified {
|
|
t.Errorf("got %q, %v", rev, modified)
|
|
}
|
|
if rev, modified := revision(nil); rev != "" || modified {
|
|
t.Errorf("nil: got %q, %v", rev, modified)
|
|
}
|
|
}
|
|
|
|
func TestShortRevisionIsKeptWhole(t *testing.T) {
|
|
if rev, _ := revision(settings("vcs.revision", "abc")); rev != "abc" {
|
|
t.Errorf("got %q", rev)
|
|
}
|
|
}
|