diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e84b5cfe..5c172d50 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -71,7 +71,7 @@ jobs: - name: Build application run: docker build -t leto-modelizer-api . - name: Run application - run: docker compose up -d + run: docker compose up -f docker-compose-e2e.yml -d env: GITHUB_CLIENT_ID: test GITHUB_CLIENT_SECRET: test diff --git a/docker-compose-e2e.yml b/docker-compose-e2e.yml new file mode 100644 index 00000000..b58f5676 --- /dev/null +++ b/docker-compose-e2e.yml @@ -0,0 +1,54 @@ +services: + libraries: + image: nginx:latest + ports: + - "8000:80" + volumes: + - ./src/test/resources/libraries:/usr/share/nginx/html:ro + - ./nginx_lib_dev.conf:/etc/nginx/conf.d/default.conf:ro + restart: always + ai: + build: ./src/test/resources/ai + ports: + - "8001:80" + volumes: + - ./src/test/resources/ai:/var/www/html + restart: always + db: + image: cockroachdb/cockroach:v23.1.15 + command: start-single-node --certs-dir=/certs --advertise-addr=db + volumes: + - ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql + - ./cockroach-certs:/certs + ports: + - "26257:26257" + - "8081:8080" + restart: always + api: + restart: always + image: leto-modelizer-api:latest + environment: + DATABASE_HOST: db:26257 + AI_HOST: http://ai/api/ + GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID} + GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET} + LIBRARY_HOST_WHITELIST: http://libraries/ + SUPER_ADMINISTRATOR_LOGIN: ${SUPER_ADMINISTRATOR_LOGIN} + POSTGRES_DB: ${POSTGRES_DB:-leto_db} + POSTGRES_USER: ${POSTGRES_USER:-leto_admin} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password} + DATABASE_NAME: ${DATABASE_NAME:-leto_db} + DATABASE_USER: ${DATABASE_USER:-leto_admin} + DATABASE_PASSWORD: ${DATABASE_PASSWORD:-password} + SSL_KEY_STORE: ${SSL_KEY_STORE:-classpath:keystore.jks} + SSL_KEY_STORE_PASSWORD: ${SSL_KEY_STORE_PASSWORD:-password} + SSL_KEY_PASSWORD: ${SSL_KEY_PASSWORD:-password} + LETO_MODELIZER_URL: ${LETO_MODELIZER_URL:-http://localhost:8080/} + LETO_ADMIN_URL: ${LETO_ADMIN_URL:-http://localhost:9000/} + CSRF_TOKEN_TIMEOUT: ${CSRF_TOKEN_TIMEOUT:-3600} + USER_SESSION_TIMEOUT: ${USER_SESSION_TIMEOUT:-3600} + + ports: + - "8443:8443" + depends_on: + - db diff --git a/src/test/java/com/ditrit/letomodelizerapi/cucumber/StepDefinitions.java b/src/test/java/com/ditrit/letomodelizerapi/cucumber/StepDefinitions.java index 526be2c2..0a44cd5f 100644 --- a/src/test/java/com/ditrit/letomodelizerapi/cucumber/StepDefinitions.java +++ b/src/test/java/com/ditrit/letomodelizerapi/cucumber/StepDefinitions.java @@ -359,6 +359,11 @@ public void expectResponseTypeIs(String type) { } } + @Then("I expect response is {string}") + public void expectResponseIsEqualsTo(String value) { + assertEquals(json.toString(), value); + } + @Then("I expect response resources value is {string}") public void expectResponseIs(String value) { assertEquals(resources.toString(), value); diff --git a/src/test/resources/ai/diagram_terrator-plugin.json b/src/test/resources/ai/diagram_terrator-plugin.json index 7f014551..fefc7b49 100644 --- a/src/test/resources/ai/diagram_terrator-plugin.json +++ b/src/test/resources/ai/diagram_terrator-plugin.json @@ -1,4 +1 @@ -[{ - "name": "main.tf", - "content": "provider \"aws\" {\n region = \"us-west-2\"\n}\n\nresource \"aws_instance\" \"example\" {\n ami = \"ami-0c55b159cbfafe1f0\"\n instance_type = \"t2.micro\"\n}" -}] \ No newline at end of file +[{"name":"main.tf","content":"provider \"aws\" {}"}] \ No newline at end of file diff --git a/src/test/resources/ai/index.php b/src/test/resources/ai/index.php index f8b84a78..32266ea5 100644 --- a/src/test/resources/ai/index.php +++ b/src/test/resources/ai/index.php @@ -11,8 +11,8 @@ error_log($type); error_log(file_get_contents('php://input')); -if ($type && isset($requestBody['plugin'])) { - $fileName = "{$type}_{$requestBody['plugin']}.json"; +if ($type && isset($requestBody['pluginName'])) { + $fileName = "{$type}_{$requestBody['pluginName']}.json"; error_log($fileName); if (file_exists($fileName)) { diff --git a/src/test/resources/features/AI.feature b/src/test/resources/features/AI.feature new file mode 100644 index 00000000..00602c70 --- /dev/null +++ b/src/test/resources/features/AI.feature @@ -0,0 +1,12 @@ +Feature: ai feature + + Scenario: Should return 201 on a valid ai diagram creation + Given I initialize the admin user + + When I request "/ai" with method "POST" with json + | key | value | + | plugin | terrator-plugin | + | type | diagram | + | description | Test diagram creation | + Then I expect "201" as status code + And I expect response is '[{"name":"main.tf","content":"provider \\"aws\\" {}"}]'