diff --git a/Dockerfile b/Dockerfile index d938868b..ecb321ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:18.04 WORKDIR /usr/src/app -RUN apt-get update && apt-get install -y wget git vim +RUN apt-get update && apt-get install -y wget git vim make # Install node using nvm RUN mkdir -p /usr/src/.nvm diff --git a/Makefile b/Makefile index 9fe8b1a2..e3a0eb54 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,14 @@ -.PHONY: build test +.PHONY: build test run build: docker-compose up --build --remove-orphans test: - docker exec -it $$CONTAINER /bin/bash -c "npm install request --no-save && npm test" \ No newline at end of file + @[ "${CONTAINER}" ] && \ + (docker exec -it $$CONTAINER /bin/bash -c "npm install request --no-save && npm test") || \ + (npm install request --no-save && npm test) + +run: + @[ "${CONTAINER}" ] && \ + (docker exec -it $$CONTAINER /bin/bash -c 'cd /usr/src/app/node-sdk-test/ && node test.js') || \ + (cd /usr/src/app/node-sdk-test/ && node test.js) \ No newline at end of file diff --git a/README.md b/README.md index 18ee628e..103a94ac 100644 --- a/README.md +++ b/README.md @@ -147,5 +147,10 @@ export PLIVO_API_PROD_HOST= 5. The sdk directory will be mounted as a volume in the container. So any changes in the sdk code will also be reflected inside the container. However, when any change is made, the dependencies for the test program need to be re-installed. To do that: * Either restart the docker container * Or Run the `setup_sdk.sh` script -6. To run unit tests, run `make test CONTAINER=` in host, where `` is the docker container id created in 2. -(The docker container should be running) \ No newline at end of file +6. To run test code, run `make run CONTAINER=` in host. +7. To run unit tests, run `make test CONTAINER=` in host. +> `` is the docker container id created in 2. +(The docker container should be running) + +> Test code and unit tests can also be run within the container using +`make run` and `make test` respectively. (`CONTAINER` argument should be omitted when running from the container) \ No newline at end of file diff --git a/setup_sdk.sh b/setup_sdk.sh index a1dd08d7..67868d69 100755 --- a/setup_sdk.sh +++ b/setup_sdk.sh @@ -39,13 +39,17 @@ npm init -y npm install $package rm $package -echo -e "\n\nSDK setup complete!" -echo "To test your changes:" -echo -e "\t1. Add your test code in /$testDir/test.js on host (or /usr/src/app/$testDir/test.js in the container)" -echo -e "\t2. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC" -echo -e "\t3. Navigate to the test directory: $GREEN cd /usr/src/app/$testDir$NC" -echo -e "\t4. Run your test file: $GREEN node test.js$NC" -echo -e "\t5. For running unit tests, run on host: $GREEN make test CONTAINER=$HOSTNAME$NC" +echo -e "\n\nSDK setup complete! You can test changes either on host or inside the docker container:" +echo -e "\ta. To test your changes ON HOST:" +echo -e "\t\t1. Add your test code in /$testDir/test.js" +echo -e "\t\t2. Run your test file using: $GREEN make run CONTAINER=$HOSTNAME$NC" +echo -e "\t\t3. Run unit tests using: $GREEN make test CONTAINER=$HOSTNAME$NC" +echo +echo -e "\tb. To test your changes INSIDE CONTAINER:" +echo -e "\t\t1. Run a terminal in the container using: $GREEN docker exec -it $HOSTNAME /bin/bash$NC" +echo -e "\t\t2. Add your test code in /usr/src/app/$testDir/test.js" +echo -e "\t\t3. Run your test file using: $GREEN make run$NC" +echo -e "\t\t4. Run unit tests using: $GREEN make test$NC" # To keep the container running post setup /bin/bash \ No newline at end of file