From 3e03ae8f77f13c933471e2d032474c11a5dc8daf Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Tue, 24 Nov 2015 00:59:51 +0100 Subject: [PATCH] gateway: add CurrentCommit to /version License: MIT Signed-off-by: Lars Gierth --- core/corehttp/gateway.go | 4 +++- core/corehttp/gateway_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/corehttp/gateway.go b/core/corehttp/gateway.go index 2aa95b951..e5d6569a7 100644 --- a/core/corehttp/gateway.go +++ b/core/corehttp/gateway.go @@ -8,6 +8,7 @@ import ( core "github.com/ipfs/go-ipfs/core" id "github.com/ipfs/go-ipfs/p2p/protocol/identify" + config "github.com/ipfs/go-ipfs/repo/config" ) // Gateway should be instantiated using NewGateway @@ -58,7 +59,8 @@ func GatewayOption(writable bool) ServeOption { func VersionOption() ServeOption { return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) { mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion) + fmt.Fprintf(w, "Commit: %s\n", config.CurrentCommit) + fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion) fmt.Fprintf(w, "Protocol Version: %s\n", id.IpfsVersion) }) return mux, nil diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 935085aaf..ffc49c604 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -401,6 +401,8 @@ func TestIPNSHostnameBacklinks(t *testing.T) { } func TestVersion(t *testing.T) { + config.CurrentCommit = "theshortcommithash" + ns := mockNamesys{} ts, _ := newTestServerAndNode(t, ns) t.Logf("test server url: %s", ts.URL) @@ -421,6 +423,10 @@ func TestVersion(t *testing.T) { } s := string(body) + if !strings.Contains(s, "Commit: theshortcommithash") { + t.Fatalf("response doesn't contain commit:\n%s", s) + } + if !strings.Contains(s, "Client Version: "+id.ClientVersion) { t.Fatalf("response doesn't contain client version:\n%s", s) }