Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
7d0d1afb
Commit
7d0d1afb
authored
Dec 01, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2001 from ipfs/version-commit
gateway: /version tests, add CurrentCommit
parents
34efa3b8
9d0c3f5c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
2 deletions
+43
-2
core/commands/root.go
core/commands/root.go
+1
-0
core/commands/sysdiag.go
core/commands/sysdiag.go
+1
-1
core/corehttp/gateway.go
core/corehttp/gateway.go
+3
-1
core/corehttp/gateway_test.go
core/corehttp/gateway_test.go
+38
-0
No files found.
core/commands/root.go
View file @
7d0d1afb
...
...
@@ -148,6 +148,7 @@ var rootROSubcommands = map[string]*cmds.Command{
},
"refs"
:
RefsROCmd
,
//"resolve": ResolveCmd,
"version"
:
VersionCmd
,
}
func
init
()
{
...
...
core/commands/sysdiag.go
View file @
7d0d1afb
...
...
@@ -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
)
},
}
...
...
core/corehttp/gateway.go
View file @
7d0d1afb
...
...
@@ -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
...
...
core/corehttp/gateway_test.go
View file @
7d0d1afb
...
...
@@ -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,39 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
t
.
Fatalf
(
"expected file in directory listing"
)
}
}
func
TestVersion
(
t
*
testing
.
T
)
{
config
.
CurrentCommit
=
"theshortcommithash"
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
,
"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
)
}
if
!
strings
.
Contains
(
s
,
"Protocol Version: "
+
id
.
IpfsVersion
)
{
t
.
Fatalf
(
"response doesn't contain protocol version:
\n
%s"
,
s
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment