mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-08-19 04:50:35 -07:00
test(NetworkConfig): fully cover NetworkConfig.js
This commit is contained in:
parent
91ecf577c7
commit
4bc2a251cf
2 changed files with 32 additions and 2 deletions
30
frontend/__tests__/unit/utils/NetworkConfig.test.js
Normal file
30
frontend/__tests__/unit/utils/NetworkConfig.test.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import * as NetworkConfig from "utils/NetworkConfig";
|
||||||
|
|
||||||
|
jest.spyOn(Math, "random").mockReturnValue(0.5);
|
||||||
|
jest.spyOn(Date, "now").mockImplementation(() => 1487076708000);
|
||||||
|
|
||||||
|
describe("NetworkConfig", () => {
|
||||||
|
it("getRandomInt()", () => {
|
||||||
|
expect(NetworkConfig.getRandomInt(1, 10)).toBe(5);
|
||||||
|
expect(NetworkConfig.getRandomInt(2, 2)).toBe(2);
|
||||||
|
expect(NetworkConfig.getRandomInt("test", 10)).toBe(NaN);
|
||||||
|
expect(NetworkConfig.getRandomInt(1, "test")).toBe(NaN);
|
||||||
|
expect(NetworkConfig.getRandomInt("test", "test")).toBe(NaN);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("generateNetworkConfig()", () => {
|
||||||
|
expect(NetworkConfig.generateNetworkConfig()).toStrictEqual({
|
||||||
|
config: {
|
||||||
|
name: "new-net-08000",
|
||||||
|
private: true,
|
||||||
|
v6AssignMode: { "6plane": false, rfc4193: false, zt: false },
|
||||||
|
v4AssignMode: { zt: true },
|
||||||
|
routes: [{ flags: 0, metric: 0, target: "172.30.127.0/24", via: null }],
|
||||||
|
ipAssignmentPools: [
|
||||||
|
{ ipRangeEnd: "172.30.127.254", ipRangeStart: "172.30.127.1" },
|
||||||
|
],
|
||||||
|
enableBroadcast: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
export function generateNetworkConfig() {
|
export function generateNetworkConfig() {
|
||||||
const randSubnetPart = getRandomInt(0, 254).toString();
|
const randSubnetPart = getRandomInt(0, 254).toString();
|
||||||
const randNamePart = new Date().getTime();
|
const randNamePart = new Date(Date.now()).getTime();
|
||||||
return {
|
return {
|
||||||
config: {
|
config: {
|
||||||
name: "new-net-" + randNamePart.toString().substring(8),
|
name: "new-net-" + randNamePart.toString().substring(8),
|
||||||
|
@ -26,7 +26,7 @@ export function generateNetworkConfig() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomInt(min, max) {
|
export function getRandomInt(min, max) {
|
||||||
min = Math.ceil(min);
|
min = Math.ceil(min);
|
||||||
max = Math.floor(max);
|
max = Math.floor(max);
|
||||||
return Math.floor(Math.random() * (max - min)) + min;
|
return Math.floor(Math.random() * (max - min)) + min;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue