Skip to content

Commit 03c2d67

Browse files
committed
A few unit tests, I'm not sure if they are gonna work on Travis.
1 parent e674b59 commit 03c2d67

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

test/ntp-client_test.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,35 @@
2121
(function (exports) {
2222
"use strict";
2323

24-
var ntp_client = require('../lib/ntp-client.js');
24+
var ntpClient = require('../lib/ntp-client.js');
2525

2626
exports.setUp = function (done) {
2727
// setup here
2828
done();
2929
};
3030

31-
exports.noop = function (test) {
32-
test.ok(true);
33-
test.done();
31+
exports.works = function (test) {
32+
ntpClient.ntpReplyTimeout = 5000; // Reducing timeout to avoid warnings.
33+
34+
ntpClient.getNetworkTime(ntpClient.defaultNtpServer, ntpClient.defaultNtpPort, function (err, date) {
35+
var now = new Date();
36+
test.ok(err === null);
37+
test.ok(date !== null);
38+
39+
test.equal(now.getDate(), date.getDate()); // I'm pretty sure the date things will be OK
40+
test.equal(now.getMonth(), date.getMonth());
41+
test.equal(now.getYear(), date.getYear());
42+
43+
// For the hours and minute parts, really depends if testing machine is synched
44+
test.equal(now.getHours(), date.getHours());
45+
});
46+
47+
// I'm pretty sure there is no NTP Server listening at google.com
48+
ntpClient.getNetworkTime("google.com", 123, function (err, date) {
49+
test.ok(err !== null);
50+
test.ok(date === null);
51+
test.equal(err, "Timeout waiting for NTP response.");
52+
test.done();
53+
});
3454
};
3555
}(exports));

0 commit comments

Comments
 (0)