File tree Expand file tree Collapse file tree
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ namespace RESTAPI\Tests;
55use RESTAPI \Core \TestCase ;
66use RESTAPI \Fields \InterfaceField ;
77use RESTAPI \Models \RESTAPISettings ;
8+ use RESTAPI \Models \VirtualIP ;
89
910class 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.
You can’t perform that action at this time.
0 commit comments