Skip to content

Commit

Permalink
fixup!test: rework to share principles with redis sample - fix 2
Browse files Browse the repository at this point in the history
  • Loading branch information
o-orand committed Oct 2, 2024
1 parent b362ba3 commit 32dea18
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-using-cnb-buildpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
SERVICE_PORT: 27017 # Default value: 27017
SERVICE_USERNAME: '22032e25-4aba-417f-a394-8bbd78d920cd'
SERVICE_PASSWORD: 'StbQ4EovUpwQjD0cT1Hr7PKBG'
DATABASE_NAME: my-mongo-db
DATABASE_NAME: my-sample-mongo-db
DEBUG: 0

jobs:
Expand Down
4 changes: 2 additions & 2 deletions local.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ export CNB_IMAGE_NAME=mongodb-cnb-app
export SERVICE_NAME=mongodb
export SERVICE_HEALTH_CMD=mongo
export SERVICE_PORT=27001
export DATABASE_NAME=myCollection
export DATABASE_NAME=my-sample-mongo-db
export SERVICE_IMAGE="mongo:7.0.14"
export SERVICE_HOST="dynamically_generated"
export SERVICE_PASSWORD=my-passwwwwwwwword15;
export SERVICE_USERNAME='22032e25-4aba-417f-a394-8bbd78d920cd'
export SERVICE_PASSWORD='StbQ4EovUpwQjD0cT1Hr7PKBG'
#export DEBUG=0
#export DEBUG=0
9 changes: 6 additions & 3 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ service_container_name="$(docker ps -f "ancestor=$SERVICE_IMAGE" --format "{{.Na
CONTAINER_APP_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $container_name)
echo "CONTAINER_APP_IP: $CONTAINER_APP_IP"

if [ "$DEBUG" -eq 1 ]; then
if [ "$DEBUG" = "1" ]; then
echo "----------------- $container_name --------------------"
docker inspect -f '{{json .NetworkSettings}}' $container_name

Expand All @@ -36,6 +36,9 @@ if nc -vz 127.0.0.1 "${SERVICE_PORT}";then echo "port ${SERVICE_PORT} available"
#echo "Checking redis server 127.0.0.1 : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h 127.0.0.1 -p ${SERVICE_PORT} --no-auth-warning ping)"
#echo "Checking redis server $SERVICE_HOST : PING ==> $(redis-cli -a ${SERVICE_PASSWORD} -h ${SERVICE_HOST} -p ${SERVICE_PORT} --no-auth-warning ping)"

echo mongosh \'mongodb://$SERVICE_USERNAME:$SERVICE_PASSWORD@$SERVICE_HOST:$SERVICE_PORT/$DATABASE_NAME\' --apiVersion 1


function check_service() {
type="$1"
cmd="$2"
Expand All @@ -60,13 +63,13 @@ function check_service() {
export APP="http://127.0.0.1:8080"
set +e
exit_status=0
create_service_output="$(check_service "Create" "curl -sSLf -X POST $APP/myCollection -d bar")"
create_service_output="$(check_service "Create" "curl -sSLf -X POST $APP/myCollection -d ''")"
create_service=$?

#get_service_output="$(check_service "Get" "curl -sSLf -X GET $APP/foo" )"
#get_service=$?

delete_service_output="$(check_service "Delete" "curl -sSLf DELETE $APP/myCollection")"
delete_service_output="$(check_service "Delete" "curl -sSLf DELETE $APP/myCollection -d ''")"
delete_service=$?
set -e

Expand Down
11 changes: 9 additions & 2 deletions setup-prerequisite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
set -e
echo "Processing $0"

service_container_id=$(docker run -d --rm -p $SERVICE_PORT:$SERVICE_PORT \
service_container_id=$(docker run -d --rm -p "$SERVICE_PORT:27017" \
-e MONGO_INITDB_ROOT_USERNAME="$SERVICE_USERNAME" \
-e MONGO_INITDB_ROOT_PASSWORD="$SERVICE_PASSWORD" \
-e MONGO_INITDB_DATABASE="$DATABASE_NAME" \
--name "$SERVICE_NAME-service" \
--health-cmd "$SERVICE_HEALTH_CMD" \
--health-interval 10s --health-timeout 5s --health-retries 5 \
${SERVICE_IMAGE})
${SERVICE_IMAGE} --tlsMode disabled)
echo "Waiting for $SERVICE_NAME-service"
sleep 2
if [ -z "$service_container_id" ];then
echo "ERROR: failed to start container '$SERVICE_NAME-service' using $SERVICE_IMAGE"
else
echo "'$SERVICE_NAME-service' is running $SERVICE_IMAGE"
fi
service_container_name="$(docker ps -f "ancestor=$SERVICE_IMAGE" --format "{{.Names}}")"
SERVICE_CONTAINER_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$service_container_name")
echo "$SERVICE_CONTAINER_IP: $SERVICE_CONTAINER_IP"
Expand Down
2 changes: 1 addition & 1 deletion vcap-services-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"database":"${DATABASE_NAME}",
"hostname":"${SERVICE_HOST}:${SERVICE_PORT}",
"password":"${SERVICE_PASSWORD}",
"uri":"mongodb://${SERVICE_USERNAME}:${SERVICE_PASSWORD}@${SERVICE_HOST}:${SERVICE_PORT}/${DATABASE_NAME}?replicaSet=rs0",
"uri":"mongodb://${SERVICE_USERNAME}:${SERVICE_PASSWORD}@${SERVICE_HOST}:${SERVICE_PORT}/${DATABASE_NAME}",
"username":"${SERVICE_USERNAME}"
},
"instance_guid":"cc252ef5-2541-49fd-8a57-fe73957905a5",
Expand Down

0 comments on commit 32dea18

Please sign in to comment.