Skip to content

Commit b61ddf4

Browse files
test(InterfaceField): add test to ensure vips are correctly present in choices
1 parent 658702f commit b61ddf4

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIFieldsInterfaceFieldTestCase.inc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace RESTAPI\Tests;
55
use RESTAPI\Core\TestCase;
66
use RESTAPI\Fields\InterfaceField;
77
use RESTAPI\Models\RESTAPISettings;
8+
use RESTAPI\Models\VirtualIP;
89

910
class APIFieldsInterfaceFieldTestCase extends TestCase {
1011
# TODO: Needs Tests to ensure CARP interfaces and interface groups become available choices when the
@@ -78,6 +79,30 @@ class APIFieldsInterfaceFieldTestCase extends TestCase {
7879
$this->assert_is_true(in_array('openvpn', $test_field->choices));
7980
}
8081

82+
/**
83+
* Checks that the InterfaceField's `allow_carp_interface` parameter allows CARP interfaces to become choices.
84+
*/
85+
public function test_get_interface_choices_with_allow_carp_interface(): void {
86+
# First, create a carp virtual IP to test with
87+
$vip = new VirtualIP(
88+
interface: "lan",
89+
mode: "carp",
90+
subnet: "127.0.0.99",
91+
subnet_bits: 32,
92+
vhid: 99,
93+
password: "test"
94+
);
95+
$vip->create();
96+
97+
# Ensure the virtual IP is now a valid choice when `allow_carp_interface` is enabled
98+
$test_field = new InterfaceField(allow_carp_interface: true);
99+
$test_field->set_choices_from_callable();
100+
$this->assert_is_true(in_array("_vip{$vip->uniqid->value}", $test_field->choices));
101+
102+
# Cleanup
103+
$vip->delete();
104+
}
105+
81106
/**
82107
* Checks that the InterfaceField's to_internal() method correctly translates representation values to their
83108
* internal values.

0 commit comments

Comments
 (0)