mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-03 21:08:17 +08:00
gateway: add tests for /version
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
This commit is contained in:
@ -14,6 +14,7 @@ import (
|
|||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||||
ci "github.com/ipfs/go-ipfs/p2p/crypto"
|
ci "github.com/ipfs/go-ipfs/p2p/crypto"
|
||||||
|
id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
|
||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
repo "github.com/ipfs/go-ipfs/repo"
|
repo "github.com/ipfs/go-ipfs/repo"
|
||||||
config "github.com/ipfs/go-ipfs/repo/config"
|
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,
|
dh.Handler, err = makeHandler(n,
|
||||||
ts.Listener,
|
ts.Listener,
|
||||||
|
VersionOption(),
|
||||||
IPNSHostnameOption(),
|
IPNSHostnameOption(),
|
||||||
GatewayOption(false),
|
GatewayOption(false),
|
||||||
)
|
)
|
||||||
@ -397,3 +399,33 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
|
|||||||
t.Fatalf("expected file in directory listing")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user