gateway: add tests for /version
License: MIT Signed-off-by: Lars Gierth <larsg@systemli.org>
Lars Gierth committed
Nov 24, 2015 at 00:59 UTC
8ab0ddfe44b709b111544aff3105b0506de00202
1 file changed
+32
core/corehttp/gateway_test.go
+32
@@ -14,6 +14,7 @@ import (
14
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
15
namesys "github.com/ipfs/go-ipfs/namesys"
16
ci "github.com/ipfs/go-ipfs/p2p/crypto"
17
+ id "github.com/ipfs/go-ipfs/p2p/protocol/identify"
18
path "github.com/ipfs/go-ipfs/path"
19
repo "github.com/ipfs/go-ipfs/repo"
20
config "github.com/ipfs/go-ipfs/repo/config"
@@ -95,6 +96,7 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
96
97
dh.Handler, err = makeHandler(n,
98
ts.Listener,
99
+ VersionOption(),
100
IPNSHostnameOption(),
101
GatewayOption(false),
102
)
@@ -397,3 +399,33 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
399
t.Fatalf("expected file in directory listing")
400
}
401
}
402
+
403
+func TestVersion(t *testing.T) {
404
+ ns := mockNamesys{}
405
+ ts, _ := newTestServerAndNode(t, ns)
406
+ t.Logf("test server url: %s", ts.URL)
407
+ defer ts.Close()
408
+
409
+ req, err := http.NewRequest("GET", ts.URL+"/version", nil)
410
+ if err != nil {
411
+ t.Fatal(err)
412
+ }
413
+
414
+ res, err := doWithoutRedirect(req)
415
+ if err != nil {
416
+ t.Fatal(err)
417
+ }
418
+ body, err := ioutil.ReadAll(res.Body)
419
+ if err != nil {
420
+ t.Fatalf("error reading response: %s", err)
421
+ }
422
+ s := string(body)
423
+
424
+ if !strings.Contains(s, "Client Version: "+id.ClientVersion) {
425
+ t.Fatalf("response doesn't contain client version:\n%s", s)
426
+ }
427
+
428
+ if !strings.Contains(s, "Protocol Version: "+id.IpfsVersion) {
429
+ t.Fatalf("response doesn't contain protocol version:\n%s", s)
430
+ }
431
+}