mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
gateway: add CurrentCommit to /version
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
|
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
|
||||||
|
config "github.com/ipfs/go-ipfs/repo/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Gateway should be instantiated using NewGateway
|
// Gateway should be instantiated using NewGateway
|
||||||
@ -58,6 +59,7 @@ func GatewayOption(writable bool) ServeOption {
|
|||||||
func VersionOption() ServeOption {
|
func VersionOption() ServeOption {
|
||||||
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
||||||
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "Commit: %s\n", config.CurrentCommit)
|
||||||
fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
|
fmt.Fprintf(w, "Client Version: %s\n", id.ClientVersion)
|
||||||
fmt.Fprintf(w, "Protocol Version: %s\n", id.IpfsVersion)
|
fmt.Fprintf(w, "Protocol Version: %s\n", id.IpfsVersion)
|
||||||
})
|
})
|
||||||
|
@ -401,6 +401,8 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVersion(t *testing.T) {
|
func TestVersion(t *testing.T) {
|
||||||
|
config.CurrentCommit = "theshortcommithash"
|
||||||
|
|
||||||
ns := mockNamesys{}
|
ns := mockNamesys{}
|
||||||
ts, _ := newTestServerAndNode(t, ns)
|
ts, _ := newTestServerAndNode(t, ns)
|
||||||
t.Logf("test server url: %s", ts.URL)
|
t.Logf("test server url: %s", ts.URL)
|
||||||
@ -421,6 +423,10 @@ func TestVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
s := string(body)
|
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) {
|
if !strings.Contains(s, "Client Version: "+id.ClientVersion) {
|
||||||
t.Fatalf("response doesn't contain client version:\n%s", s)
|
t.Fatalf("response doesn't contain client version:\n%s", s)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user