Skip to content

Conversation

@zaelgohary
Copy link
Contributor

Sync cross-field validation, return early on any invalid IP, wrap getIPRange in try-catch to handle any remaining errors gracefully, and add unit tests

#4492

…IPRange in try-catch to handle any remaining errors gracefully, add unit tests
Copy link
Contributor

@AhmedHanafy725 AhmedHanafy725 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add how to run these tests

}));

describe("Add IP Range Validation", () => {
// Replicate the validateIPRange function logic for testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replicating the code wouldn't find any issues if the methods used to validate the IPs changed.

vi.mocked(CidrTools.containsCidr).mockImplementation(() => {
throw new Error("Invalid CIDR");
});
const result = gatewayCheck("192.168.1.254", "192.168.1.1/24", undefined, IPType.single);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

192.168.1.254 is in range of 192.168.1.1/24, why it should fail?

@zaelgohary
Copy link
Contributor Author

Please add how to run these tests

From playground path, run npm run test:unit -- tests/components/add_ip.test.ts --run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants