Skip to content

Commit 7d0d1af

Browse files
committedDec 1, 2015
Merge pull request #2001 from ipfs/version-commit
gateway: /version tests, add CurrentCommit
2 parents 34efa3b + 9d0c3f5 commit 7d0d1af

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed
 

‎core/commands/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ var rootROSubcommands = map[string]*cmds.Command{
148148
},
149149
"refs": RefsROCmd,
150150
//"resolve": ResolveCmd,
151+
"version": VersionCmd,
151152
}
152153

153154
func init() {

‎core/commands/sysdiag.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Prints out information about your computer to aid in easier debugging.
5353
}
5454

5555
info["ipfs_version"] = config.CurrentVersionNumber
56-
info["ipfs_git_sha"] = config.CurrentCommit
56+
info["ipfs_commit"] = config.CurrentCommit
5757
res.SetOutput(info)
5858
},
5959
}

‎core/corehttp/gateway.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
core "github.com/ipfs/go-ipfs/core"
1010
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
11+
config "github.com/ipfs/go-ipfs/repo/config"
1112
)
1213

1314
// Gateway should be instantiated using NewGateway
@@ -58,7 +59,8 @@ func GatewayOption(writable bool) ServeOption {
5859
func VersionOption() ServeOption {
5960
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
6061
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)
6264
fmt.Fprintf(w, "Protocol Version: %s\n", id.IpfsVersion)
6365
})
6466
return mux, nil

‎core/corehttp/gateway_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
1515
namesys "github.com/ipfs/go-ipfs/namesys"
1616
ci "github.com/ipfs/go-ipfs/p2p/crypto"
17+
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
1718
path "github.com/ipfs/go-ipfs/path"
1819
repo "github.com/ipfs/go-ipfs/repo"
1920
config "github.com/ipfs/go-ipfs/repo/config"
@@ -95,6 +96,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
9596

9697
dh.Handler, err = makeHandler(n,
9798
ts.Listener,
99+
VersionOption(),
98100
IPNSHostnameOption(),
99101
GatewayOption(false),
100102
)
@@ -397,3 +399,39 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
397399
t.Fatalf("expected file in directory listing")
398400
}
399401
}
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)
409+
defer ts.Close()
410+
411+
req, err := http.NewRequest("GET", ts.URL+"/version", nil)
412+
if err != nil {
413+
t.Fatal(err)
414+
}
415+
416+
res, err := doWithoutRedirect(req)
417+
if err != nil {
418+
t.Fatal(err)
419+
}
420+
body, err := ioutil.ReadAll(res.Body)
421+
if err != nil {
422+
t.Fatalf("error reading response: %s", err)
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+
}
433+
434+
if !strings.Contains(s, "Protocol Version: "+id.IpfsVersion) {
435+
t.Fatalf("response doesn't contain protocol version:\n%s", s)
436+
}
437+
}

0 commit comments

Comments
 (0)
Please sign in to comment.