-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathGenerateTokenTest.php
More file actions
42 lines (30 loc) · 1.28 KB
/
GenerateTokenTest.php
File metadata and controls
42 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/generate_token.php';
use PHPUnit\Framework\TestCase;
class GenerateTokenTest extends TestCase
{
public function testGenerateTokenReturnsNonEmptyString(): void
{
$endpoint = getenv('CLUSTER_ENDPOINT');
$region = getenv('REGION') ?: 'us-east-1';
$this->assertNotEmpty($endpoint, 'CLUSTER_ENDPOINT environment variable must be set');
$token = generateToken($endpoint, $region);
$this->assertIsString($token);
$this->assertNotEmpty($token);
}
public function testTokenCanConnectToCluster(): void
{
$endpoint = getenv('CLUSTER_ENDPOINT');
$region = getenv('REGION') ?: 'us-east-1';
$this->assertNotEmpty($endpoint, 'CLUSTER_ENDPOINT environment variable must be set');
$token = generateToken($endpoint, $region);
$dsn = "pgsql:host={$endpoint};port=5432;dbname=postgres;sslmode=verify-full;sslrootcert=system";
$pdo = new PDO($dsn, 'admin', $token);
$stmt = $pdo->query('SELECT 1 AS result');
$result = $stmt->fetchColumn();
$this->assertEquals(1, (int) $result);
}
}