From 14acb12566ddd27bd42ca4c9ef928c8d23cbf8ad Mon Sep 17 00:00:00 2001 From: Julien Loizelet Date: Tue, 8 Aug 2023 10:01:59 +0900 Subject: [PATCH] feat(mongosh): Add mongosh command (#12) * feat(mongosh): Add mongosh command * test(mongosh): Add test for mongosh tool --- commands/mongo/mongosh | 11 +++++++++++ docker-compose.mongo.yaml | 8 ++++++-- install.yaml | 1 + tests/test.bats | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100755 commands/mongo/mongosh diff --git a/commands/mongo/mongosh b/commands/mongo/mongosh new file mode 100755 index 0000000..10141fa --- /dev/null +++ b/commands/mongo/mongosh @@ -0,0 +1,11 @@ +#!/bin/bash +#ddev-generated +# Remove the line above if you don't want this file to be overwritten when you run +# ddev get ddev/ddev-mongo +# +# This file comes from https://github.com/ddev/ddev-mongo +# +## Description: Run mongosh command +## Usage: mongosh +## Example: "ddev mongosh "mongodb://mongo:27017" +mongosh "$@" diff --git a/docker-compose.mongo.yaml b/docker-compose.mongo.yaml index 5ef5812..be3c85f 100644 --- a/docker-compose.mongo.yaml +++ b/docker-compose.mongo.yaml @@ -1,6 +1,9 @@ #ddev-generated -version: '3.6' - +# Remove the line above if you don't want this file to be overwritten when you run +# ddev get ddev/ddev-mongo +# +# This file comes from https://github.com/ddev/ddev-mongo +# services: mongo: container_name: ddev-${DDEV_SITENAME}-mongo @@ -11,6 +14,7 @@ services: target: "/data/db" volume: nocopy: true + - ".:/mnt/ddev_config" restart: "no" expose: - "27017" diff --git a/install.yaml b/install.yaml index ba18342..e83c183 100644 --- a/install.yaml +++ b/install.yaml @@ -7,4 +7,5 @@ pre_install_actions: # list of files and directories listed that are copied into project .ddev directory project_files: +- commands/mongo/mongosh - docker-compose.mongo.yaml diff --git a/tests/test.bats b/tests/test.bats index a3757b1..dea708b 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -29,6 +29,16 @@ teardown() { out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user") [ "${out}" = "db" ] (ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1) + # Test mongosh + result=$(ddev mongosh "mongodb://db:db@mongo:27017/test?authSource=admin" --quiet --eval '"printjson(db.getUsers())"' --json | grep "ok" | sed 's/: 1/ /g' | sed 's/ //g' | tr ' \n' '#') + if [[ $result == "ok#" ]] + then + echo "# Mongosh OK" >&3 + else + echo "# Mongosh KO" + echo "$result" + exit 1 + fi } @test "install from release" { @@ -41,4 +51,14 @@ teardown() { out=$(curl -s ${PROJNAME}.ddev.site:9091/db/admin/expArr/system.users | jq -r ".[0].user") [ "${out}" = "db" ] (ddev exec php -i | grep mongodb.debug) || (echo "# php mongodb extension not found" >&3 || exit 1) + # Test mongosh + result=$(ddev mongosh "mongodb://db:db@mongo:27017/test?authSource=admin" --quiet --eval '"printjson(db.getUsers())"' --json | grep "ok" | sed 's/: 1/ /g' | sed 's/ //g' | tr ' \n' '#') + if [[ $result == "ok#" ]] + then + echo "# Mongosh OK" >&3 + else + echo "# Mongosh KO" + echo "$result" + exit 1 + fi }