- 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
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package httpapi
|
|
|
|
import "testing"
|
|
|
|
func TestVersionIsForSignedInUsers(t *testing.T) {
|
|
h := newTestAPIWith(t, func(d *Deps) { d.Build = Build{Version: "1.2.3", Revision: "abc1234", Modified: true} })
|
|
if r := do(t, h, "GET", "/api/v1/version", "", nil); r.Code != 401 {
|
|
t.Fatalf("without a token: %d, want 401", r.Code)
|
|
}
|
|
tok := registerAndLogin(t, h)
|
|
r := do(t, h, "GET", "/api/v1/version", tok, nil)
|
|
if r.Code != 200 {
|
|
t.Fatalf("version: %d %v", r.Code, r.Body)
|
|
}
|
|
if str(r.Body, "version") != "1.2.3" || str(r.Body, "revision") != "abc1234" || r.Body["modified"] != true {
|
|
t.Errorf("body = %v", r.Body)
|
|
}
|
|
}
|
|
|
|
func TestVersionWithoutARevisionHasNone(t *testing.T) {
|
|
h := newTestAPIWith(t, func(d *Deps) { d.Build = Build{Version: "1.2.3"} })
|
|
tok := registerAndLogin(t, h)
|
|
r := do(t, h, "GET", "/api/v1/version", tok, nil)
|
|
if r.Code != 200 || str(r.Body, "version") != "1.2.3" {
|
|
t.Fatalf("version: %d %v", r.Code, r.Body)
|
|
}
|
|
if _, ok := r.Body["revision"]; ok {
|
|
t.Errorf("revision should be left out: %v", r.Body)
|
|
}
|
|
if _, ok := r.Body["modified"]; ok {
|
|
t.Errorf("modified should be left out: %v", r.Body)
|
|
}
|
|
}
|