@spalger/kibana
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
58 lines (44 loc) • 1.61 kB
JavaScript
var Ipv4Address = require('ui/utils/Ipv4Address');
var expect = require('expect.js');
describe('Ipv4Address', function () {
it('should throw errors with invalid IP addresses', function () {
expect(function () {
new Ipv4Address();
}).to.throwError();
expect(function () {
new Ipv4Address('');
}).to.throwError();
expect(function () {
new Ipv4Address('hello, world');
}).to.throwError();
expect(function () {
new Ipv4Address('0.0.0');
}).to.throwError();
expect(function () {
new Ipv4Address('256.0.0.0');
}).to.throwError();
expect(function () {
new Ipv4Address('-1.0.0.0');
}).to.throwError();
expect(function () {
new Ipv4Address(Number.MAX_SAFE_INTEGER);
}).to.throwError();
});
it('should allow creation with an integer or string', function () {
expect(new Ipv4Address(2116932386).toString()).to.be(new Ipv4Address('126.45.211.34').toString());
});
it('should correctly calculate the decimal representation of an IP address', function () {
var ipAddress = new Ipv4Address('0.0.0.0');
expect(ipAddress.valueOf()).to.be(0);
ipAddress = new Ipv4Address('0.0.0.1');
expect(ipAddress.valueOf()).to.be(1);
ipAddress = new Ipv4Address('126.45.211.34');
expect(ipAddress.valueOf()).to.be(2116932386);
});
it('toString()', function () {
var ipAddress = new Ipv4Address('0.000.00000.1');
expect(ipAddress.toString()).to.be('0.0.0.1');
ipAddress = new Ipv4Address('123.123.123.123');
expect(ipAddress.toString()).to.be('123.123.123.123');
});
});