Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions commands/host/1x-token-setup
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
50 changes: 28 additions & 22 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
#!/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}"
ddev config --project-name=${PROJNAME}
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 )
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
[ "${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" ]
}