diff --git a/.gitignore b/.gitignore index c8b241f..6dae94f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,7 @@ -target/* \ No newline at end of file +target/* +.direnv +.envrc +.vscode +node_modules +package-lock.json +package.json \ No newline at end of file diff --git a/Makefile b/Makefile index a169791..9371814 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ remote-token=eyJraWQiOiIyYzVkMTJmNC02NmQzLTQxMzYtODJiZC00YWFkN2JiY2Q3YjkiLCJhbGc all: build run build: - mvn clean install + mvn clean package run: docker compose up diff --git a/README.md b/README.md index c68fa6f..b792279 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,28 @@ # Template Micro Integrator for Visual Studio Code This is a sample project for the WSO2 Micro Integrator -Build with Maven: +### Build - mvn clean install +- Build car with Maven: `mvn clean package` +- Run on Docker: `docker-compose up` +- Call the Demo API: `curl -k https://localhost:8243/health` -Run on Docker: +### Test - docker-compose up +HttpYac is used to test the Micro Integrator and the tests are automatically run with `docker compose up`. However you can also manually run the tests with: -Call the Demo API +```bash +docker run -it --rm -v $(pwd)/src/test/httpyac:/app/httpyac httpyac:5.8.2 \ + "httpyac" -a -o short -e docker +``` - curl http://localhost:8280/health +See the +[Test with HttpYac](https://integon.gitlab.io/docs/wiki/wso2/1.0.0/test-with-httpyac.html) +for more details on how this works. + + +### Makefile -# Makefile ## Build make build diff --git a/docker-compose.yml b/docker-compose.yml index df5d6f5..98a20a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,33 @@ version: '3.3' services: mi-template: - image: "wso2/wso2mi:4.1.0" + image: "docker.io/wso2/wso2mi:4.1.0-multiarch" #image: "docker.wso2.com/wso2mi:latest" ports: - "8280:8280" - "8243:8243" - "9191:9191" - "9154:9154" + healthcheck: + test : [ "CMD", "curl", "-f", "http://localhost:9191/healthz" ] + interval : 1s + timeout : 2s + retries : 3 + start_period: 5s + volumes: - ./target/capp:/home/wso2carbon/wso2mi-4.1.0/repository/deployment/server/carbonapps - ./mi-home/conf/deployment.toml:/home/wso2carbon/wso2mi-4.1.0/conf/deployment.toml + + test: + build: + context: . + dockerfile: docker/test/Dockerfile + volumes: + - ./src/test/httpyac:/app/httpyac + command: ["httpyac", "-a", "-o", "short", "-e", "docker-compose" ] + depends_on: + mi-template: + condition: service_healthy + + diff --git a/Dockerfile b/docker/mi/Dockerfile similarity index 100% rename from Dockerfile rename to docker/mi/Dockerfile diff --git a/docker/test/Dockerfile b/docker/test/Dockerfile new file mode 100644 index 0000000..e70d568 --- /dev/null +++ b/docker/test/Dockerfile @@ -0,0 +1,6 @@ +FROM node:16-alpine +USER node +ENV NODE_ENV=production +WORKDIR /app +RUN npm install httpyac@5.8.2 chai@4.3.7 +ENTRYPOINT [ "npx", "httpyac" ] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ebd8d23 --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669900182, + "narHash": "sha256-EKxjHxRJnP1w+2nnm8pq4Uqkqa5McnfPXcO8cG8Mxzc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bcb6dbbe30ce7631e5a0865dff1ab9b63d92977d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7fdf937 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "mi-template-dev-shell"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachSystem + [ + "x86_64-darwin" + "aarch64-darwin" + "x86_64-linux" + ] + (system: + let pkgs = import nixpkgs { inherit system; }; + in + { + devShell = pkgs.mkShell + { + buildInputs = with pkgs; + [ + openjdk11 + nodejs + kustomize + docker + docker-compose + colima + (maven.override { jdk = openjdk11; }) + ]; + }; + } + ); +} diff --git a/src/test/httpyac/.env b/src/test/httpyac/.env new file mode 100644 index 0000000..53663cf --- /dev/null +++ b/src/test/httpyac/.env @@ -0,0 +1 @@ +request_rejectUnauthorized=false \ No newline at end of file diff --git a/src/test/httpyac/env/docker-compose.env b/src/test/httpyac/env/docker-compose.env new file mode 100644 index 0000000..4fc43c4 --- /dev/null +++ b/src/test/httpyac/env/docker-compose.env @@ -0,0 +1 @@ +MI_HOST=mi-template \ No newline at end of file diff --git a/src/test/httpyac/env/docker.env b/src/test/httpyac/env/docker.env new file mode 100644 index 0000000..37e5dab --- /dev/null +++ b/src/test/httpyac/env/docker.env @@ -0,0 +1 @@ +MI_HOST=host.docker.internal \ No newline at end of file diff --git a/src/test/httpyac/env/local.env b/src/test/httpyac/env/local.env new file mode 100644 index 0000000..fcb2373 --- /dev/null +++ b/src/test/httpyac/env/local.env @@ -0,0 +1 @@ +MI_HOST=127.0.0.1 \ No newline at end of file diff --git a/src/test/httpyac/health.http b/src/test/httpyac/health.http new file mode 100644 index 0000000..430b935 --- /dev/null +++ b/src/test/httpyac/health.http @@ -0,0 +1,45 @@ +@host=https://{{MI_HOST}}:8243 + +/* +Simple health test without any dependencies +*/ +GET /health +{{ + test.status(200); + test.hasResponseBody(); +}} + +### + +/* +Health test with header checking without any dependencies +*/ +GET /health +{{ + test.status(200); + test.hasResponseBody(); + test.header("Content-Type", "application/json; charset=UTF-8"); +}} + +### + +/* +Health test with chai dependency for more complex tests. This test does not +work inside the httpYac VSCode extension unless you have chai installed with npm. +In the Docker image, however, chai is already installed and the test will work. +*/ +GET /health +{{ + // standard test without dependencies + test.status(200); + test.hasResponseBody(); + test.header("Content-Type", "application/json; charset=UTF-8"); + + // additional javascript specific test using the specialized chai library + const expect = require('chai').expect; + test('Status should be "UP"', () => { + expect(response.parsedBody.Status).to.equal('UP'); + }); +}} + +