Skip to content

Commit

Permalink
Add unit test for the hostname option
Browse files Browse the repository at this point in the history
  • Loading branch information
padraic-padraic authored and erossignon committed Jul 15, 2020
1 parent 232361e commit 8525018
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { nodesets } from "node-opcua-nodesets";
import { getFullyQualifiedDomainName } from "node-opcua-hostname";
import { OPCUAServer } from "..";

//const os = require("os");

// tslint:disable:no-var-requires
const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("OPCUAServerEndpoint#addEndpointDescription multiple hostname", () => {
Expand Down Expand Up @@ -42,3 +45,75 @@ describe("OPCUAServerEndpoint#addEndpointDescription multiple hostname", () => {
server.dispose();
});
});
describe("OPCUAServerEndpoint#addEndpointDescription default hostname", () => {

it("should default to using the machine hostname as the hostname", async () => {

// Given a server with no explicit hostname
const server = new OPCUAServer({
port: 2011,

nodeset_filename: [ nodesets.standard ],

});

await server.start();

let defaultHostname = getFullyQualifiedDomainName();
let defaultHostnameRegex = RegExp(defaultHostname);

// When we count the exposed endpoint
let matchingDefault = 0;

for (const e of server.endpoints) {
for (const ed of e.endpointDescriptions()) {
// console.log("", ed.endpointUrl);
if (ed.endpointUrl!.match(defaultHostnameRegex)) {
matchingDefault++;
}
}
}

matchingDefault.should.eql(7, "we should have 7 endpoints matching the machine hostname");

await server.shutdown();

server.dispose();
});
});
describe("OPCUAServerEndpoint#addEndpointDescription custom hostname", () => {

it("should be possible to create endpoints on multiple host names", async () => {

let myHostname = 'my.test.website';

// Given a server with two host names
let server = new OPCUAServer({
hostname: myHostname,
port: 2011,

nodeset_filename: [ nodesets.standard ],

});

await server.start();

// When we count the exposed endpoint
let matchingHostname = 0;

for (const e of server.endpoints) {
for (const ed of e.endpointDescriptions()) {
// console.log("", ed.endpointUrl);
if (ed.endpointUrl!.match(/my.test.website/)) {
matchingHostname++;
}
}
}

matchingHostname.should.eql(7, "we should have 7 endpoints matches the custom hostname");

await server.shutdown();

server.dispose();
});
});

0 comments on commit 8525018

Please sign in to comment.