File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * HealthPingTest.php
5+ *
6+ * Tests for the v1 liveness (ping) and health-check endpoints.
7+ */
8+
9+ namespace LibreNMS \Tests \Feature \Api \V1 ;
10+
11+ use App \Models \User ;
12+ use Illuminate \Foundation \Testing \DatabaseTransactions ;
13+ use Laravel \Sanctum \Sanctum ;
14+ use LibreNMS \Tests \DBTestCase ;
15+
16+ final class HealthPingTest extends DBTestCase
17+ {
18+ use DatabaseTransactions;
19+
20+ public function testPingIsPublicAndReturnsOk (): void
21+ {
22+ $ this ->getJson ('/api/v1/ping ' )
23+ ->assertOk ()
24+ ->assertExactJson (['status ' => 'ok ' ]);
25+ }
26+
27+ public function testHealthRequiresAuthentication (): void
28+ {
29+ $ this ->getJson ('/api/v1/health ' )
30+ ->assertUnauthorized ();
31+ }
32+
33+ public function testHealthReturnsOkWhenSubsystemsAreUp (): void
34+ {
35+ /** @var User $user */
36+ $ user = User::factory ()->create ();
37+ Sanctum::actingAs ($ user );
38+
39+ $ this ->getJson ('/api/v1/health ' )
40+ ->assertOk ()
41+ ->assertJson ([
42+ 'status ' => 'ok ' ,
43+ 'checks ' => [
44+ 'database ' => ['ok ' => true ],
45+ 'cache ' => ['ok ' => true ],
46+ ],
47+ ])
48+ ->assertJsonStructure ([
49+ 'status ' ,
50+ 'checks ' => [
51+ 'database ' => ['ok ' ],
52+ 'cache ' => ['ok ' ],
53+ ],
54+ ]);
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments