Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 9f728b1

Browse files
committed
Adding tests for ipv4/ipv6 functionality
1 parent f10469b commit 9f728b1

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

test/server.js

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const assert = require('assert');
22
const net = require('net');
3+
const os = require('os');
34
const helpers = require('../lib/helpers');
45
const consts = require('../lib/constants');
56
const CacheServer = require('../lib/server/server');
@@ -67,6 +68,57 @@ describe("Server common", function() {
6768
});
6869
});
6970

71+
describe("Ipv6", function() {
72+
const ipv6Server = new CacheServer(cache, {port: 0, allowIpv6: true});
73+
74+
before(function () {
75+
var interfaces = os.networkInterfaces();
76+
var ipv6Available = false;
77+
Object.keys(interfaces).forEach(function (interfaceName){
78+
interfaces[interfaceName].forEach(function (address){
79+
if(address.family === "IPv6"){
80+
ipv6Available = true;
81+
}
82+
});
83+
});
84+
85+
if(!ipv6Available){
86+
console.log("Skipping IPv6 tests because IPv6 is not available on this machine");
87+
this.skip();
88+
}
89+
90+
return ipv6Server.start(err => assert(!err, `Cache Server reported error! ${err}`));
91+
});
92+
93+
after(function() {
94+
ipv6Server.stop();
95+
});
96+
97+
it("should bind to ipv6 when allowed", function(done) {
98+
var serverAddress = ipv6Server._server.address();
99+
assert.strictEqual(serverAddress.family, "IPv6");
100+
done();
101+
});
102+
103+
});
104+
describe("Ipv4", function() {
105+
const ipv4Server = new CacheServer(cache, {port: 0, allowIpv6: false});
106+
107+
before(function () {
108+
return ipv4Server.start(err => assert(!err, `Cache Server reported error! ${err}`));
109+
});
110+
111+
after(function() {
112+
ipv4Server.stop();
113+
});
114+
115+
it("should bind to ipv4 when ipv6 not allowed", function(done) {
116+
var serverAddress = ipv4Server._server.address();
117+
assert.strictEqual(serverAddress.family, "IPv4");
118+
done();
119+
});
120+
});
121+
70122
describe("Other", function() {
71123
it("should force close the socket when a quit (q) command is received", function(done) {
72124
client = net.connect({port: server.port}, function (err) {
@@ -92,6 +144,7 @@ describe("Server common", function() {
92144
client.write(helpers.encodeInt32(consts.PROTOCOL_VERSION));
93145
client.write('xx');
94146
});
95-
})
147+
});
96148
})
97-
});
149+
});
150+

0 commit comments

Comments
 (0)