Skip to content

Commit

Permalink
#3: Add mariadb tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldsalec committed Oct 18, 2021
1 parent f0d5dd2 commit 06f49d4
Show file tree
Hide file tree
Showing 56 changed files with 1,431 additions and 4 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/pr-mysql-tests.yml
Expand Up @@ -11,12 +11,16 @@ jobs:
strategy:
matrix:
leia-tests:
# - test: platform-sh-maria-db-10-1-example
# source: examples/mariadb-10.2
- test: platform-sh-maria-db-10-1-example
source: examples/mariadb-10.2
- test: platform-sh-maria-db-10-2-example
source: examples/mariadb-10.2
# - test: platform-sh-maria-db-10-3-example
# source: examples/mariadb-10.3
- test: platform-sh-maria-db-10-3-example
source: examples/mariadb-10.3
- test: platform-sh-maria-db-10-4-example
source: examples/mariadb-10.4
- test: platform-sh-maria-db-10-5-example
source: examples/mariadb-10.5
lando-versions:
- edge
os:
Expand Down
20 changes: 20 additions & 0 deletions examples/mariadb-10.0/.editorconfig
@@ -0,0 +1,20 @@
# Drupal editor configuration normalization
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[composer.{json,lock}]
indent_size = 4

[.platform.app.yaml]
indent_size = 4
11 changes: 11 additions & 0 deletions examples/mariadb-10.0/.gitignore
@@ -0,0 +1,11 @@
vendor
files
data
private
.platform/local

*.sql
*.tar.gz
*.tar

.DS_Store
13 changes: 13 additions & 0 deletions examples/mariadb-10.0/.lando.yml
@@ -0,0 +1,13 @@
name: lando-platformsh-mariadb-10.0
recipe: platformsh
config:
id: DISCONNECTED
excludes:
- vendor
- files
- private

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/platformsh": ./../../
19 changes: 19 additions & 0 deletions examples/mariadb-10.0/.platform.app.yaml
@@ -0,0 +1,19 @@
name: app
type: "php:7.3"
disk: 1024
build:
flavor: composer
web:
locations:
"/":
root: "."
passthru: "/index.php"
relationships:
mariadb: 'mariadb:mysql'
mounts:
'files':
source: local
source_path: files
'private':
source: local
source_path: private
8 changes: 8 additions & 0 deletions examples/mariadb-10.0/.platform/routes.yaml
@@ -0,0 +1,8 @@
# The routes of the project.
#
# Each route describes how an incoming URL is going
# to be processed by Platform.sh.

"https://{default}/":
type: upstream
upstream: "app:http"
3 changes: 3 additions & 0 deletions examples/mariadb-10.0/.platform/services.yaml
@@ -0,0 +1,3 @@
mariadb:
type: mariadb:10.0
disk: 512
64 changes: 64 additions & 0 deletions examples/mariadb-10.0/README.md
@@ -0,0 +1,64 @@
Platform.sh MariaDB 10.0 Example
================================

This example exists to test this plugin's implementation of Platform.sh's `mariadb:10.0` service.

* [Platform.sh MariaDB 10.0](https://docs.platform.sh/configuration/services/mysql.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should poweroff
lando poweroff

# Should start up successfully
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should have the expected platformsh containers and images
docker ps --filter label=com.docker.compose.project=landoplatformshmariadb100 | grep docker.registry.platform.sh/php-7.3 | grep landoplatformshmariadb100_app_1
docker ps --filter label=com.docker.compose.project=landoplatformshmariadb100 | grep docker.registry.platform.sh/mariadb-10.0 | grep landoplatformshmariadb100_mariadb_1

# Should be running all application containers as web
lando ssh -s app -c "id" | grep web

# Should have the platform cli in all application containers
lando ssh -s app -c "platform -V"

# Should be running the correct php version
lando ssh -s app -c "php --version" | grep 7.3.

# Should be running all mariadb containers as app
lando ssh -s mariadb -c "id" | grep app

# Should be running the correct mariadb versions
lando ssh -s mariadb -c "mysql -V" | grep 10.0.

# Should be able to connect to all mariadb relationships
lando mariadb main -e "show tables;"

# Should be able to connect to mysql from the application containers
lando ssh -s app -c "curl -I localhost/mysql.php" | grep HTTP/1.1 | grep "200 OK"
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be able to destroy our app
lando destroy -y

# Should poweroff
lando poweroff
```
15 changes: 15 additions & 0 deletions examples/mariadb-10.0/composer.json
@@ -0,0 +1,15 @@
{
"name": "lando/platformsh-mysql",
"description": "A basic application to test Lando's implementation of platformsh's mysql service.",
"license": "MIT",
"type" : "project",
"require": {
"php": ">7.2",
"platformsh/config-reader": "~2.0"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
60 changes: 60 additions & 0 deletions examples/mariadb-10.0/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/mariadb-10.0/index.php
@@ -0,0 +1 @@
HELLO!
73 changes: 73 additions & 0 deletions examples/mariadb-10.0/mysql.php
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

require __DIR__.'/vendor/autoload.php';

use Platformsh\ConfigReader\Config;

// Create a new config object to ease reading the Platform.sh environment variables.
// You can alternatively use getenv() yourself.
$config = new Config();

// The 'database' relationship is generally the name of primary SQL database of an application.
// That's not required, but much of our default automation code assumes it.
$credentials = $config->credentials('mariadb');

try {
// Connect to the database using PDO. If using some other abstraction layer you would
// inject the values from $database into whatever your abstraction layer asks for.
$dsn = sprintf('mysql:host=%s;port=%d;dbname=%s', $credentials['host'], $credentials['port'], $credentials['path']);
$conn = new \PDO($dsn, $credentials['username'], $credentials['password'], [
// Always use Exception error mode with PDO, as it's more reliable.
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
// So we don't have to mess around with cursors and unbuffered queries by default.
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => TRUE,
// Make sure MySQL returns all matched rows on update queries including
// rows that actually didn't have to be updated because the values didn't
// change. This matches common behavior among other database systems.
\PDO::MYSQL_ATTR_FOUND_ROWS => TRUE,
]);

// Creating a table.
$sql = "CREATE TABLE People (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
city VARCHAR(30) NOT NULL
)";
$conn->query($sql);

// Insert data.
$sql = "INSERT INTO People (name, city) VALUES
('Neil Armstrong', 'Moon'),
('Buzz Aldrin', 'Glen Ridge'),
('Sally Ride', 'La Jolla');";
$conn->query($sql);

// Show table.
$sql = "SELECT * FROM People";
$result = $conn->query($sql);
$result->setFetchMode(\PDO::FETCH_OBJ);

if ($result) {
print <<<TABLE
<table>
<thead>
<tr><th>Name</th><th>City</th></tr>
</thead>
<tbody>
TABLE;
foreach ($result as $record) {
printf("<tr><td>%s</td><td>%s</td></tr>\n", $record->name, $record->city);
}
print "</tbody>\n</table>\n";
}

// Drop table
$sql = "DROP TABLE People";
$conn->query($sql);

} catch (\Exception $e) {
http_response_code(500);
print $e->getMessage();
}
20 changes: 20 additions & 0 deletions examples/mariadb-10.1/.editorconfig
@@ -0,0 +1,20 @@
# Drupal editor configuration normalization
# @see http://editorconfig.org/

# This is the top-most .editorconfig file; do not search in parent directories.
root = true

# All files.
[*]
end_of_line = LF
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[composer.{json,lock}]
indent_size = 4

[.platform.app.yaml]
indent_size = 4
11 changes: 11 additions & 0 deletions examples/mariadb-10.1/.gitignore
@@ -0,0 +1,11 @@
vendor
files
data
private
.platform/local

*.sql
*.tar.gz
*.tar

.DS_Store
10 changes: 10 additions & 0 deletions examples/mariadb-10.1/.lando.yml
@@ -0,0 +1,10 @@
name: lando-platformsh-mariadb-10.1
recipe: platformsh
config:
id: DISCONNECTED


# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/platformsh": ./../../
19 changes: 19 additions & 0 deletions examples/mariadb-10.1/.platform.app.yaml
@@ -0,0 +1,19 @@
name: app
type: "php:7.3"
disk: 1024
build:
flavor: composer
web:
locations:
"/":
root: "."
passthru: "/index.php"
relationships:
mariadb: 'mariadb:mysql'
mounts:
'files':
source: local
source_path: files
'private':
source: local
source_path: private
8 changes: 8 additions & 0 deletions examples/mariadb-10.1/.platform/routes.yaml
@@ -0,0 +1,8 @@
# The routes of the project.
#
# Each route describes how an incoming URL is going
# to be processed by Platform.sh.

"https://{default}/":
type: upstream
upstream: "app:http"
3 changes: 3 additions & 0 deletions examples/mariadb-10.1/.platform/services.yaml
@@ -0,0 +1,3 @@
mariadb:
type: mariadb:10.1
disk: 512

0 comments on commit 06f49d4

Please sign in to comment.