From 8ab0ddfe44b709b111544aff3105b0506de00202 Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Tue, 24 Nov 2015 00:59:19 +0100 Subject: [PATCH 1/4] gateway: add tests for /version License: MIT Signed-off-by: Lars Gierth --- core/corehttp/gateway_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 75b7120e3..935085aaf 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -14,6 +14,7 @@ import ( coreunix "github.com/ipfs/go-ipfs/core/coreunix" namesys "github.com/ipfs/go-ipfs/namesys" ci "github.com/ipfs/go-ipfs/p2p/crypto" + id "github.com/ipfs/go-ipfs/p2p/protocol/identify" path "github.com/ipfs/go-ipfs/path" repo "github.com/ipfs/go-ipfs/repo" config "github.com/ipfs/go-ipfs/repo/config" @@ -95,6 +96,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core dh.Handler, err = makeHandler(n, ts.Listener, + VersionOption(), IPNSHostnameOption(), GatewayOption(false), ) @@ -397,3 +399,33 @@ func TestIPNSHostnameBacklinks(t *testing.T) { t.Fatalf("expected file in directory listing") } } + +func TestVersion(t *testing.T) { + ns := mockNamesys{} + ts, _ := newTestServerAndNode(t, ns) + t.Logf("test server url: %s", ts.URL) + defer ts.Close() + + req, err := http.NewRequest("GET", ts.URL+"/version", nil) + if err != nil { + t.Fatal(err) + } + + res, err := doWithoutRedirect(req) + if err != nil { + t.Fatal(err) + } + body, err := ioutil.ReadAll(res.Body) + if err != nil { + t.Fatalf("error reading response: %s", err) + } + s := string(body) + + if !strings.Contains(s, "Client Version: "+id.ClientVersion) { + t.Fatalf("response doesn't contain client version:\n%s", s) + } + + if !strings.Contains(s, "Protocol Version: "+id.IpfsVersion) { + t.Fatalf("response doesn't contain protocol version:\n%s", s) + } +} From 3e03ae8f77f13c933471e2d032474c11a5dc8daf Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Tue, 24 Nov 2015 00:59:51 +0100 Subject: [PATCH 2/4] 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) } From 9beebc9779a765a567b20e5ac9915467685802e9 Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Wed, 25 Nov 2015 02:54:59 +0100 Subject: [PATCH 3/4] commands: enable version for API License: MIT Signed-off-by: Lars Gierth --- core/commands/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/commands/root.go b/core/commands/root.go index ce6721750..41510098b 100644 --- a/core/commands/root.go +++ b/core/commands/root.go @@ -148,6 +148,7 @@ var rootROSubcommands = map[string]*cmds.Command{ }, "refs": RefsROCmd, //"resolve": ResolveCmd, + "version": VersionCmd, } func init() { From 9d0c3f5cb0a39345246623bd45c941488baed728 Mon Sep 17 00:00:00 2001 From: Lars Gierth Date: Wed, 25 Nov 2015 03:15:15 +0100 Subject: [PATCH 4/4] diag: make commit consistent with version command License: MIT Signed-off-by: Lars Gierth --- core/commands/sysdiag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/sysdiag.go b/core/commands/sysdiag.go index 385945887..caa5d70dc 100644 --- a/core/commands/sysdiag.go +++ b/core/commands/sysdiag.go @@ -53,7 +53,7 @@ Prints out information about your computer to aid in easier debugging. } info["ipfs_version"] = config.CurrentVersionNumber - info["ipfs_git_sha"] = config.CurrentCommit + info["ipfs_commit"] = config.CurrentCommit res.SetOutput(info) }, }