diff --git a/commands/host/1x-token-setup b/commands/host/1x-token-setup index 600f015..4009c47 100644 --- a/commands/host/1x-token-setup +++ b/commands/host/1x-token-setup @@ -49,13 +49,15 @@ fi # If it is set now, prompt the user to confirm. if [ ! -z "$PERSONAL_ACCESS_TOKEN" ]; then - echo "Please note we've determined this as your 1xinternet gitlab token to be: $PERSONAL_ACCESS_TOKEN" - read -p "Please confirm to proceed with this token (Y/n): " -n 1 -r REPLY - REPLY=${REPLY:-Y} - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - echo "Operation cancelled." - exit 1 - fi + echo "Please note we've determined your 1xinternet gitlab token is: $PERSONAL_ACCESS_TOKEN" + if [ -z "$DDEV_NON_INTERACTIVE" ] || [ "$DDEV_NON_INTERACTIVE" = "0" ]; then + read -p "Please confirm to proceed with this token (Y/n): " -n 1 -r REPLY + REPLY=${REPLY:-Y} + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Operation cancelled." + exit 1 + fi + fi fi # If still not set, prompt the user @@ -72,7 +74,12 @@ fi # Setup token for NPM # Remove old token if exists to replace with new one, or just append # A simple append might create duplicates, so let's try to be a bit smarter or just append as requested -sed -i '/\/\/git.1xinternet.de\/api\/v4\/packages\/npm\/:_authToken=/d' ~/.ddev/homeadditions/.npmrc +# Make this work on MacOS and Linux >.< +if [[ $OSTYPE == darwin* ]]; then + sed -i '' '/\/\/git.1xinternet.de\/api\/v4\/packages\/npm\/:_authToken=/d' ~/.ddev/homeadditions/.npmrc +else + sed -i '/\/\/git.1xinternet.de\/api\/v4\/packages\/npm\/:_authToken=/d' ~/.ddev/homeadditions/.npmrc +fi echo "//git.1xinternet.de/api/v4/packages/npm/:_authToken=${PERSONAL_ACCESS_TOKEN}" >> ~/.ddev/homeadditions/.npmrc # Configure NPM in homeadditions so the container picks it up. diff --git a/tests/test.bats b/tests/test.bats index b41afac..d12855b 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,9 +1,23 @@ +#!/usr/bin/env bats + +# Bats is a testing framework for Bash +# Documentation https://bats-core.readthedocs.io/en/stable/ +# Bats libraries documentation https://github.com/ztombol/bats-docs + +# For local tests, install bats-core, bats-assert, bats-file, bats-support +# And run this in the add-on root directory: +# bats ./tests/test.bats +# To exclude release tests: +# bats ./tests/test.bats --filter-tags '!release' +# For debugging: +# bats ./tests/test.bats --show-output-of-passing-tests --verbose-run --print-output-on-failure + setup() { set -eu -o pipefail export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export TESTDIR=~/tmp/test-addon-template mkdir -p $TESTDIR - export PROJNAME=test-addon-template + export PROJNAME=test-ddev-onex export DDEV_NON_INTERACTIVE=true ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true cd "${TESTDIR}" @@ -11,12 +25,6 @@ setup() { ddev start -y >/dev/null } -health_checks() { - # Do something useful here that verifies the add-on - # ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch" - ddev exec "curl -s https://localhost:443/" -} - teardown() { set -eu -o pipefail cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) @@ -24,21 +32,19 @@ teardown() { [ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR} } -@test "install from directory" { +@test "1x-token-setup" { set -eu -o pipefail - cd ${TESTDIR} + cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 ddev get ${DIR} - ddev restart - health_checks -} - -@test "install from release" { - set -eu -o pipefail - cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 ) - echo "# ddev get ddev/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 - ddev get ddev/ddev-addon-template - ddev restart >/dev/null - health_checks -} - + DDEV_NON_INTERACTIVE=true PERSONAL_ACCESS_TOKEN=123 ddev 1x-token-setup + run ddev exec "npm config get @dxp:registry" + [ "$status" -eq 0 ] + [ "$output" = "https://git.1xinternet.de/api/v4/groups/392/-/packages/npm/" ] + run ddev exec "npm config get @1xINTERNET:registry" + [ "$status" -eq 0 ] + [ "$output" = "https://git.1xinternet.de/api/v4/projects/1121/packages/npm/" ] + run ddev exec "grep '=123' ~/.npmrc" + [ "$status" -eq 0 ] + [ "$output" = "//git.1xinternet.de/api/v4/packages/npm/:_authToken=123" ] + } \ No newline at end of file