@cryptotaxi247 / kubo / commits / 3e03ae8f7

gateway: add CurrentCommit to /version

License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>

Lars Gierth committed Nov 24, 2015 at 00:59 UTC 3e03ae8f77f13c933471e2d032474c11a5dc8daf
2 files changed +9 -1
core/corehttp/gateway.go
+3 -1
@@ -8,6 +8,7 @@ import (
8
9 core "github.com/ipfs/go-ipfs/core"
10 id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
11 + config "github.com/ipfs/go-ipfs/repo/config"
12 )
13
14 // Gateway should be instantiated using NewGateway
@@ -58,7 +59,8 @@ func GatewayOption(writable bool) ServeOption {
59 func VersionOption() ServeOption {
60 return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
61 mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
61 - fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
62 + fmt.Fprintf(w, "Commit: %s\n", config.CurrentCommit)
63 + fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
64 fmt.Fprintf(w, "Protocol Version: %s\n", id.IpfsVersion)
65 })
66 return mux, nil
core/corehttp/gateway_test.go
+6
@@ -401,6 +401,8 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
401 }
402
403 func TestVersion(t *testing.T) {
404 + config.CurrentCommit = "theshortcommithash"
405 +
406 ns := mockNamesys{}
407 ts, _ := newTestServerAndNode(t, ns)
408 t.Logf("test server url: %s", ts.URL)
@@ -421,6 +423,10 @@ func TestVersion(t *testing.T) {
423 }
424 s := string(body)
425
426 + if !strings.Contains(s, "Commit: theshortcommithash") {
427 + t.Fatalf("response doesn't contain commit:\n%s", s)
428 + }
429 +
430 if !strings.Contains(s, "Client Version: "+id.ClientVersion) {
431 t.Fatalf("response doesn't contain client version:\n%s", s)
432 }