From b975d2dea420223255ed3d490010e1fa4cc38fc2 Mon Sep 17 00:00:00 2001 From: Yuki Adachi Date: Sun, 7 May 2023 08:00:02 +0900 Subject: [PATCH 1/2] Embed dbdb v1.2.12 https://github.com/pj8/dbdb/releases/tag/v1.2.12 --- dbdb/.github/workflows/test.yml | 44 ++++----------------------- dbdb/VERSION | 2 +- dbdb/postgresql/create.sh | 6 ++-- dbdb/redis/create.sh | 3 +- dbdb/tests/postgresql-12-test.sh | 51 ++++++++++++++++++++++++++++++++ dbdb/tests/postgresql-13-test.sh | 51 ++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 44 deletions(-) create mode 100755 dbdb/tests/postgresql-12-test.sh create mode 100755 dbdb/tests/postgresql-13-test.sh diff --git a/dbdb/.github/workflows/test.yml b/dbdb/.github/workflows/test.yml index 2a025ca..edfd556 100644 --- a/dbdb/.github/workflows/test.yml +++ b/dbdb/.github/workflows/test.yml @@ -3,49 +3,15 @@ name: Test on: push jobs: - test-macos: + test: runs-on: ${{ matrix.os }} strategy: matrix: - os: [macos-latest] + os: [macos-latest, ubuntu-latest] + test_script: [mongodb-test.sh, mysql-test.sh, postgresql-12-test.sh, postgresql-13-test.sh, redis-test.sh] steps: - uses: actions/checkout@v3 - - name: Run mongodb test + - name: Run test run: | cd tests - /bin/bash mongodb-test.sh - - name: Run mysql test - run: | - cd tests - /bin/bash mysql-test.sh - - name: Run postgresql test - run: | - cd tests - /bin/bash postgresql-test.sh - - name: Run redis test - run: | - cd tests - /bin/bash redis-test.sh - test-ubuntu: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest] - steps: - - uses: actions/checkout@v3 - - name: Run mongodb test - run: | - cd tests - /bin/bash mongodb-test.sh - - name: Run mysql test - run: | - cd tests - /bin/bash mysql-test.sh - - name: Run postgresql test - run: | - cd tests - /bin/bash postgresql-test.sh - - name: Run redis test - run: | - cd tests - /bin/bash redis-test.sh + /bin/bash ${{ matrix.test_script }} diff --git a/dbdb/VERSION b/dbdb/VERSION index 408f0de..a35de1f 100644 --- a/dbdb/VERSION +++ b/dbdb/VERSION @@ -1 +1 @@ -v1.2.11 +v1.2.12 diff --git a/dbdb/postgresql/create.sh b/dbdb/postgresql/create.sh index 34dd02b..4af3206 100755 --- a/dbdb/postgresql/create.sh +++ b/dbdb/postgresql/create.sh @@ -59,9 +59,9 @@ if [ ! -d $dir/basedir/bin ]; then if [ $os = "linux" ]; then echo "Installing..." 1>&2 cd $dir/basedir - ./configure --prefix=$(pwd) 1>&2 - make 1>&2 - make install 1>&2 + ./configure --prefix=$(pwd) > /dev/null 2>&1 + make > /dev/null 2>&1 + make install > /dev/null 2>&1 rm -fr config contrib doc src fi fi diff --git a/dbdb/redis/create.sh b/dbdb/redis/create.sh index c5a3e84..c7f0702 100755 --- a/dbdb/redis/create.sh +++ b/dbdb/redis/create.sh @@ -55,7 +55,8 @@ extractFile $dir $optFileName if [ ! -e $dir/basedir/src/redis-server ]; then cd $dir/basedir - make 1>&2 + echo "Installing..." 1>&2 + make > /dev/null 2>&1 fi # create redis.conf diff --git a/dbdb/tests/postgresql-12-test.sh b/dbdb/tests/postgresql-12-test.sh new file mode 100755 index 0000000..faabe2d --- /dev/null +++ b/dbdb/tests/postgresql-12-test.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -aeuvx + +. ../lib/functions.sh + +type=postgresql +version=12.4 + +cd ../$type +rm -fr $type-*.tar.gz +cd .. + +date=$(date +%Y%m%d%H%M%S) +md5="md5" +[ "$(getOS)" = "linux" ] && md5="md5sum" +hash=$(echo "dbdb-$date" | $md5 | cut -d ' ' -f 1) + +echo "Test create" +./$type/create.sh dbdb-test-$hash $version random +echo "Test port" +./$type/port.sh dbdb-test-$hash +echo "Test start" +./$type/start.sh dbdb-test-$hash +echo "Test status" +./$type/status.sh dbdb-test-$hash +echo "Test restart" +./$type/restart.sh dbdb-test-$hash +echo "Test stop" +./$type/stop.sh dbdb-test-$hash +echo "Test delete" +./$type/delete.sh dbdb-test-$hash + +echo "Test create" +./$type/create.sh -f json dbdb-test-$hash $version random | jq +echo "Test port" +./$type/port.sh -f json dbdb-test-$hash | jq +echo "Test start" +./$type/start.sh -f json dbdb-test-$hash | jq +echo "Test status" +./$type/status.sh -f json dbdb-test-$hash | jq +echo "Test restart" +./$type/restart.sh -f json dbdb-test-$hash | jq +echo "Test stop" +./$type/stop.sh -f json dbdb-test-$hash | jq +echo "Test delete" +./$type/delete.sh -f json dbdb-test-$hash | jq + +./dbdb.sh +./$type/create-start.sh -f json dbdb-test-$hash $version random | jq +./dbdb.sh -f json | jq +./$type/delete.sh dbdb-test-$hash diff --git a/dbdb/tests/postgresql-13-test.sh b/dbdb/tests/postgresql-13-test.sh new file mode 100755 index 0000000..82f4f0c --- /dev/null +++ b/dbdb/tests/postgresql-13-test.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -aeuvx + +. ../lib/functions.sh + +type=postgresql +version=13.2 + +cd ../$type +rm -fr $type-*.tar.gz +cd .. + +date=$(date +%Y%m%d%H%M%S) +md5="md5" +[ "$(getOS)" = "linux" ] && md5="md5sum" +hash=$(echo "dbdb-$date" | $md5 | cut -d ' ' -f 1) + +echo "Test create" +./$type/create.sh dbdb-test-$hash $version random +echo "Test port" +./$type/port.sh dbdb-test-$hash +echo "Test start" +./$type/start.sh dbdb-test-$hash +echo "Test status" +./$type/status.sh dbdb-test-$hash +echo "Test restart" +./$type/restart.sh dbdb-test-$hash +echo "Test stop" +./$type/stop.sh dbdb-test-$hash +echo "Test delete" +./$type/delete.sh dbdb-test-$hash + +echo "Test create" +./$type/create.sh -f json dbdb-test-$hash $version random | jq +echo "Test port" +./$type/port.sh -f json dbdb-test-$hash | jq +echo "Test start" +./$type/start.sh -f json dbdb-test-$hash | jq +echo "Test status" +./$type/status.sh -f json dbdb-test-$hash | jq +echo "Test restart" +./$type/restart.sh -f json dbdb-test-$hash | jq +echo "Test stop" +./$type/stop.sh -f json dbdb-test-$hash | jq +echo "Test delete" +./$type/delete.sh -f json dbdb-test-$hash | jq + +./dbdb.sh +./$type/create-start.sh -f json dbdb-test-$hash $version random | jq +./dbdb.sh -f json | jq +./$type/delete.sh dbdb-test-$hash From 819679729fa85bb5bb1346d1108c13667b967d8e Mon Sep 17 00:00:00 2001 From: Yuki Adachi Date: Sun, 7 May 2023 08:06:44 +0900 Subject: [PATCH 2/2] Parallel pg tests --- .github/workflows/test.yml | 3 +- ...ostgresqlTest.php => Postgresql12Test.php} | 9 +-- tests/Postgresql13Test.php | 75 +++++++++++++++++++ 3 files changed, 81 insertions(+), 6 deletions(-) rename tests/{PostgresqlTest.php => Postgresql12Test.php} (88%) create mode 100644 tests/Postgresql13Test.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 39ad0fd..391c74b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,8 @@ jobs: test: [ tests/MongodbTest.php, tests/MysqlTest.php, - tests/PostgresqlTest.php, + tests/Postgresql12Test.php, + tests/Postgresql13Test.php, tests/RedisTest.php ] steps: diff --git a/tests/PostgresqlTest.php b/tests/Postgresql12Test.php similarity index 88% rename from tests/PostgresqlTest.php rename to tests/Postgresql12Test.php index 113b97e..7e6b6d1 100644 --- a/tests/PostgresqlTest.php +++ b/tests/Postgresql12Test.php @@ -9,13 +9,12 @@ use DbDbPhp\Composer\Commands\DbDbList; use DbDbPhp\Composer\Commands\DbDbVersion; -class PostgresqlTest extends TestCase +class Postgresql12Test extends TestCase { public function testBasic() { $type = 'postgresql'; - // $oldVersion = '12.4'; // Run only one version of the test because of slow execution in CI - $newVersion = '13.2'; + $version = '12.4'; $application = new Application(); $application->add(new Postgresql()); @@ -43,7 +42,7 @@ public function testBasic() // Create fwrite(STDERR, "Create database $dbName" . PHP_EOL); - $this->assertEquals(0, $dbTester->execute(["action" => "create", "--db-name" => $dbName, "--db-version" => $newVersion, "--db-port" => "random"])); + $this->assertEquals(0, $dbTester->execute(["action" => "create", "--db-name" => $dbName, "--db-version" => $version, "--db-port" => "random"])); // Start fwrite(STDERR, "Start database $dbName" . PHP_EOL); @@ -67,7 +66,7 @@ public function testBasic() // Create and start fwrite(STDERR, "Create and start database $dbName" . PHP_EOL); - $this->assertEquals(0, $dbTester->execute(["action" => "create-start", "--db-name" => $dbName, "--db-version" => $newVersion, "--db-port" => "random"])); + $this->assertEquals(0, $dbTester->execute(["action" => "create-start", "--db-name" => $dbName, "--db-version" => $version, "--db-port" => "random"])); // Delete fwrite(STDERR, "Delete database $dbName" . PHP_EOL); diff --git a/tests/Postgresql13Test.php b/tests/Postgresql13Test.php new file mode 100644 index 0000000..33d79cb --- /dev/null +++ b/tests/Postgresql13Test.php @@ -0,0 +1,75 @@ +add(new Postgresql()); + $application->add(new DbDbList()); + $application->add(new DbDbVersion()); + $application->setAutoExit(false); + + $listTester = new CommandTester($application->find("dbdb:list")); + $versionTester = new CommandTester($application->find("dbdb:version")); + $dbTester = new CommandTester($application->find("dbdb:$type")); + + // Generate random name + $dbName = "dbdb-php-test-$type-" . md5(microtime(true)); + + // Version + fwrite(STDERR, "Show version of dbdb" . PHP_EOL); + $this->assertEquals(0, $versionTester->execute([])); + $this->assertStringContainsString('"dbdb-php"', $versionTester->getDisplay()); + $this->assertStringContainsString('"dbdb"', $versionTester->getDisplay()); + + // List + fwrite(STDERR, "Show databases" . PHP_EOL); + $this->assertEquals(0, $listTester->execute([])); + $this->assertStringContainsString('[]', $listTester->getDisplay()); + + // Create + fwrite(STDERR, "Create database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "create", "--db-name" => $dbName, "--db-version" => $version, "--db-port" => "random"])); + + // Start + fwrite(STDERR, "Start database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "start", "--db-name" => $dbName])); + + // Restart + fwrite(STDERR, "Restart database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "restart", "--db-name" => $dbName])); + + // Port + fwrite(STDERR, "Show port of database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "port", "--db-name" => $dbName])); + + // Stop + fwrite(STDERR, "Stop database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "stop", "--db-name" => $dbName])); + + // Delete + fwrite(STDERR, "Delete database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "delete", "--db-name" => $dbName])); + + // Create and start + fwrite(STDERR, "Create and start database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "create-start", "--db-name" => $dbName, "--db-version" => $version, "--db-port" => "random"])); + + // Delete + fwrite(STDERR, "Delete database $dbName" . PHP_EOL); + $this->assertEquals(0, $dbTester->execute(["action" => "delete", "--db-name" => $dbName])); + } +}