@@ -7,135 +7,134 @@ use RESTAPI\Models\HAProxyBackend;
7
7
use RESTAPI \Models \HAProxyBackendACL ;
8
8
use RESTAPI \Models \HAProxyBackendAction ;
9
9
10
- class APIModelsHAProxyBackendTestCase extends TestCase
11
- {
12
- public array $ required_packages = ["pfSense-pkg-haproxy " ];
13
-
10
+ class APIModelsHAProxyBackendTestCase extends TestCase {
11
+ public array $ required_packages = ['pfSense-pkg-haproxy ' ];
12
+
14
13
/**
15
14
* Ensure that the HAProxyBackend model can be created, updated, and deleted.
16
15
*/
17
16
public function test_crud (): void {
18
17
# Create a new HAProxyBackend model
19
18
$ backend = new HAProxyBackend (
20
- name: " example_backend " ,
21
- balance: "" ,
19
+ name: ' example_backend ' ,
20
+ balance: '' ,
22
21
acls: [
23
22
[
24
- " name " => " example_acl " ,
25
- " expression " => " host_starts_with " ,
26
- " value " => " example " ,
27
- " casesensitive " => false ,
28
- " not " => false
29
- ]
23
+ ' name ' => ' example_acl ' ,
24
+ ' expression ' => ' host_starts_with ' ,
25
+ ' value ' => ' example ' ,
26
+ ' casesensitive ' => false ,
27
+ ' not ' => false ,
28
+ ],
30
29
],
31
30
actions: [
32
31
[
33
- " action " => " http-response_lua " ,
34
- " acl " => " example_acl " ,
35
- " lua_function " => " example function "
36
- ]
32
+ ' action ' => ' http-response_lua ' ,
33
+ ' acl ' => ' example_acl ' ,
34
+ ' lua_function ' => ' example function ' ,
35
+ ],
37
36
],
38
- check_type: " HTTP " ,
37
+ check_type: ' HTTP ' ,
39
38
log_health_checks: false ,
40
- httpcheck_method: " OPTIONS " ,
41
- monitor_uri: "" ,
42
- monitor_httpversion: "" ,
39
+ httpcheck_method: ' OPTIONS ' ,
40
+ monitor_uri: '' ,
41
+ monitor_httpversion: '' ,
43
42
agent_checks: false ,
44
- agent_port: "" ,
43
+ agent_port: '' ,
45
44
persist_cookie_enabled: false ,
46
- persist_cookie_name: "" ,
47
- persist_cookie_mode: " passive " ,
45
+ persist_cookie_name: '' ,
46
+ persist_cookie_mode: ' passive ' ,
48
47
haproxy_cookie_domains: [],
49
- haproxy_cookie_dynamic_cookie_key: "" ,
50
- persist_sticky_type: " none " ,
51
- persist_stick_expire: "" ,
52
- persist_stick_tablesize: "" ,
53
- persist_stick_cookiename: "" ,
54
- email_level: "" ,
55
- email_to: "" ,
48
+ haproxy_cookie_dynamic_cookie_key: '' ,
49
+ persist_sticky_type: ' none ' ,
50
+ persist_stick_expire: '' ,
51
+ persist_stick_tablesize: '' ,
52
+ persist_stick_cookiename: '' ,
53
+ email_level: '' ,
54
+ email_to: '' ,
56
55
stats_enabled: true ,
57
- stats_uri: " / " ,
58
- stats_scope: [ " . " ],
59
- stats_realm: "" ,
60
- stats_username: "" ,
61
- stats_admin: "" ,
62
- stats_node: " NODE1 " ,
63
- stats_desc: "" ,
56
+ stats_uri: ' / ' ,
57
+ stats_scope: [' . ' ],
58
+ stats_realm: '' ,
59
+ stats_username: '' ,
60
+ stats_admin: '' ,
61
+ stats_node: ' NODE1 ' ,
62
+ stats_desc: '' ,
64
63
stats_refresh: 10 ,
65
64
cookie_attribute_secure: false ,
66
- advanced: "" ,
67
- advanced_backend: "" ,
65
+ advanced: '' ,
66
+ advanced_backend: '' ,
68
67
transparent_clientip: true ,
69
- transparent_interface: " lan "
68
+ transparent_interface: ' lan ' ,
70
69
);
71
70
$ backend ->create ();
72
-
71
+
73
72
# Ensure the model was created
74
73
$ read_backend = HAProxyBackend::query (id: $ backend ->id );
75
74
$ this ->assert_is_true ($ read_backend ->exists ());
76
75
$ read_backend = $ read_backend ->first ();
77
- $ this ->assert_equals ($ read_backend ->name ->value , " example_backend " );
78
- $ this ->assert_equals ($ read_backend ->balance ->value , "" );
79
- $ this ->assert_equals ($ read_backend ->check_type ->value , " HTTP " );
76
+ $ this ->assert_equals ($ read_backend ->name ->value , ' example_backend ' );
77
+ $ this ->assert_equals ($ read_backend ->balance ->value , '' );
78
+ $ this ->assert_equals ($ read_backend ->check_type ->value , ' HTTP ' );
80
79
$ this ->assert_equals ($ read_backend ->log_health_checks ->value , false );
81
- $ this ->assert_equals ($ read_backend ->httpcheck_method ->value , " OPTIONS " );
82
- $ this ->assert_equals ($ read_backend ->monitor_uri ->value , "" );
83
- $ this ->assert_equals ($ read_backend ->monitor_httpversion ->value , "" );
84
- $ this ->assert_is_empty ($ read_backend ->monitor_username ->value , "" );
85
- $ this ->assert_is_empty ($ read_backend ->monitor_domain ->value , "" );
80
+ $ this ->assert_equals ($ read_backend ->httpcheck_method ->value , ' OPTIONS ' );
81
+ $ this ->assert_equals ($ read_backend ->monitor_uri ->value , '' );
82
+ $ this ->assert_equals ($ read_backend ->monitor_httpversion ->value , '' );
83
+ $ this ->assert_is_empty ($ read_backend ->monitor_username ->value , '' );
84
+ $ this ->assert_is_empty ($ read_backend ->monitor_domain ->value , '' );
86
85
$ this ->assert_equals ($ read_backend ->agent_checks ->value , false );
87
- $ this ->assert_is_empty ($ read_backend ->agent_port ->value , "" );
86
+ $ this ->assert_is_empty ($ read_backend ->agent_port ->value , '' );
88
87
$ this ->assert_is_empty ($ read_backend ->persist_cookie_enabled ->value , false );
89
- $ this ->assert_is_empty ($ read_backend ->persist_cookie_name ->value , "" );
90
- $ this ->assert_is_empty ($ read_backend ->persist_cookie_mode ->value , " passive " );
91
- $ this ->assert_is_empty ($ read_backend ->haproxy_cookie_dynamic_cookie_key ->value , "" );
92
- $ this ->assert_equals ($ read_backend ->persist_sticky_type ->value , " none " );
93
- $ this ->assert_is_empty ($ read_backend ->persist_stick_expire ->value , "" );
94
- $ this ->assert_is_empty ($ read_backend ->persist_stick_tablesize ->value , "" );
95
- $ this ->assert_is_empty ($ read_backend ->persist_stick_cookiename ->value , "" );
96
- $ this ->assert_is_empty ($ read_backend ->email_level ->value , "" );
97
- $ this ->assert_is_empty ($ read_backend ->email_to ->value , "" );
88
+ $ this ->assert_is_empty ($ read_backend ->persist_cookie_name ->value , '' );
89
+ $ this ->assert_is_empty ($ read_backend ->persist_cookie_mode ->value , ' passive ' );
90
+ $ this ->assert_is_empty ($ read_backend ->haproxy_cookie_dynamic_cookie_key ->value , '' );
91
+ $ this ->assert_equals ($ read_backend ->persist_sticky_type ->value , ' none ' );
92
+ $ this ->assert_is_empty ($ read_backend ->persist_stick_expire ->value , '' );
93
+ $ this ->assert_is_empty ($ read_backend ->persist_stick_tablesize ->value , '' );
94
+ $ this ->assert_is_empty ($ read_backend ->persist_stick_cookiename ->value , '' );
95
+ $ this ->assert_is_empty ($ read_backend ->email_level ->value , '' );
96
+ $ this ->assert_is_empty ($ read_backend ->email_to ->value , '' );
98
97
$ this ->assert_equals ($ read_backend ->stats_enabled ->value , true );
99
- $ this ->assert_equals ($ read_backend ->stats_uri ->value , " / " );
100
- $ this ->assert_equals ($ read_backend ->stats_scope ->value , [ " . " ]);
101
- $ this ->assert_is_empty ($ read_backend ->stats_realm ->value , "" );
102
- $ this ->assert_is_empty ($ read_backend ->stats_username ->value , "" );
103
- $ this ->assert_is_empty ($ read_backend ->stats_admin ->value , "" );
104
- $ this ->assert_equals ($ read_backend ->stats_node ->value , " NODE1 " );
105
- $ this ->assert_is_empty ($ read_backend ->stats_desc ->value , "" );
98
+ $ this ->assert_equals ($ read_backend ->stats_uri ->value , ' / ' );
99
+ $ this ->assert_equals ($ read_backend ->stats_scope ->value , [' . ' ]);
100
+ $ this ->assert_is_empty ($ read_backend ->stats_realm ->value , '' );
101
+ $ this ->assert_is_empty ($ read_backend ->stats_username ->value , '' );
102
+ $ this ->assert_is_empty ($ read_backend ->stats_admin ->value , '' );
103
+ $ this ->assert_equals ($ read_backend ->stats_node ->value , ' NODE1 ' );
104
+ $ this ->assert_is_empty ($ read_backend ->stats_desc ->value , '' );
106
105
$ this ->assert_equals ($ read_backend ->stats_refresh ->value , 10 );
107
106
$ this ->assert_equals ($ read_backend ->cookie_attribute_secure ->value , false );
108
- $ this ->assert_is_empty ($ read_backend ->advanced ->value , "" );
109
- $ this ->assert_is_empty ($ read_backend ->advanced_backend ->value , "" );
107
+ $ this ->assert_is_empty ($ read_backend ->advanced ->value , '' );
108
+ $ this ->assert_is_empty ($ read_backend ->advanced_backend ->value , '' );
110
109
$ this ->assert_equals ($ read_backend ->transparent_clientip ->value , true );
111
- $ this ->assert_equals ($ read_backend ->transparent_interface ->value , " lan " );
112
-
110
+ $ this ->assert_equals ($ read_backend ->transparent_interface ->value , ' lan ' );
111
+
113
112
# Ensure the HAProxyBackendACL model was created
114
113
$ this ->assert_is_true (HAProxyBackendACL::query (parent_id: $ backend ->id , id: 0 )->exists ());
115
114
$ this ->assert_equals ($ read_backend ->acls ->value , [
116
115
[
117
- " parent_id " => $ backend ->id ,
118
- " id " => 0 ,
119
- " name " => " example_acl " ,
120
- " expression " => " host_starts_with " ,
121
- " value " => " example " ,
122
- " casesensitive " => false ,
123
- " not " => false
124
- ]
116
+ ' parent_id ' => $ backend ->id ,
117
+ ' id ' => 0 ,
118
+ ' name ' => ' example_acl ' ,
119
+ ' expression ' => ' host_starts_with ' ,
120
+ ' value ' => ' example ' ,
121
+ ' casesensitive ' => false ,
122
+ ' not ' => false ,
123
+ ],
125
124
]);
126
-
125
+
127
126
# Ensure the HAProxyBackendAction model was created
128
127
$ this ->assert_is_true (HAProxyBackendAction::query (parent_id: $ backend ->id , id: 0 )->exists ());
129
- $ this ->assert_equals ($ read_backend ->actions ->value [0 ][" action " ], " http-response_lua " );
130
- $ this ->assert_equals ($ read_backend ->actions ->value [0 ][" acl " ], " example_acl " );
131
- $ this ->assert_equals ($ read_backend ->actions ->value [0 ][" lua_function " ], " example function " );
132
-
128
+ $ this ->assert_equals ($ read_backend ->actions ->value [0 ][' action ' ], ' http-response_lua ' );
129
+ $ this ->assert_equals ($ read_backend ->actions ->value [0 ][' acl ' ], ' example_acl ' );
130
+ $ this ->assert_equals ($ read_backend ->actions ->value [0 ][' lua_function ' ], ' example function ' );
131
+
133
132
# Update the HAProxyBackend model
134
- $ backend ->balance ->value = " roundrobin " ;
133
+ $ backend ->balance ->value = ' roundrobin ' ;
135
134
$ backend ->update ();
136
135
$ read_backend = HAProxyBackend::query (id: $ backend ->id )->first ();
137
- $ this ->assert_equals ($ read_backend ->balance ->value , " roundrobin " );
138
-
136
+ $ this ->assert_equals ($ read_backend ->balance ->value , ' roundrobin ' );
137
+
139
138
# Delete the HAProxyBackend model
140
139
$ backend ->delete ();
141
140
$ this ->assert_is_false (HAProxyBackend::query (id: $ backend ->id )->exists ());
0 commit comments