Skip to content

Commit

Permalink
add support for running test env with local apps
Browse files Browse the repository at this point in the history
  • Loading branch information
mucsi96 committed Nov 4, 2023
1 parent e4d75ab commit a7dba32
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 77 deletions.
65 changes: 46 additions & 19 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
{
"configurations": [
{
"type": "java",
"name": "TestApplication",
"request": "launch",
"mainClass": "io.github.mucsi96.workout.test.TestApplication",
"projectName": "test"
},
{
"type": "java",
"name": "Spring Boot-TrainingLogApplication<training-log>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "mucsi96.traininglog.TrainingLogApplication",
"projectName": "training-log",
"args": "--spring.profiles.active=local",
"envFile": "${workspaceFolder}/.env"
}
]
"configurations": [
{
"type": "java",
"name": "TestApplication",
"request": "launch",
"mainClass": "io.github.mucsi96.workout.test.TestApplication",
"projectName": "test"
},
{
"type": "java",
"name": "Spring Boot-TrainingLogApplication<training-log>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "mucsi96.traininglog.TrainingLogApplication",
"projectName": "training-log",
"args": "--spring.profiles.active=local",
"envFile": "${workspaceFolder}/.env"
},
{
"type": "java",
"name": "Run server with test env",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "mucsi96.traininglog.TrainingLogApplication",
"projectName": "training-log",
"args": "--spring.profiles.active=prod",
"env": {
"POSTGRES_HOSTNAME": "test-db",
"POSTGRES_PORT": 5432,
"POSTGRES_DB": "training-log",
"POSTGRES_PASSWORD": "postgres",
"POSTGRES_USER": "postgres",
"SPRING_ACTUATOR_PORT": 8082,
"SPRING_ADMIN_SERVER_HOST": "localhost",
"SPRING_ADMIN_SERVER_PORT": 9090,
"WEBDRIVER_API_URI": "http://chrome:4444/chrome/wd/hub",
"WITHINGS_ACCOUNTS_URI": "http://mock-withings:8080/withings",
"WITHINGS_API_URI": "http://mock-withings:8080/withings",
"WITHINGS_CLIENT_ID": "withings-client-id",
"WITHINGS_CLIENT_SECRET": "withings-client-secret",
"STRAVA_API_URI": "http://mock-strava:8080/strava",
"STRAVA_CLIENT_ID": "strava-client-id",
"STRAVA_CLIENT_SECRET": "strava-client-secret"
}
}
]
}
39 changes: 39 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Start client with test env",
"command": "ng",
"args": ["serve", "--host", "0.0.0.0", "--configuration", "production"],
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/client"
},
"problemMatcher": []
},
{
"type": "shell",
"command": "ng",
Expand Down Expand Up @@ -101,6 +112,34 @@
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Start e2e environment with local apps",
"command": "node",
"args": [
"docker-compose.js",
"|",
"docker",
"compose",
"--file",
"-",
"up",
"--force-recreate",
"--build",
"--remove-orphans",
"--wait",
"--pull",
"always"
],
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/test",
"env": {
"WITH_LOCAL_APPS": "true"
}
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Stop e2e environment",
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/http-interceptors/oauth-login-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const oAuthLoginInterceptor: HttpInterceptorFn = (
return next(req).pipe(
catchError((error, caught) => {
if (error.error?._links?.oauth2Login?.href) {
location.assign(error.error._links.oauth2Login.href);
// location.assign(error.error._links.oauth2Login.href);
console.log('Redirecting to', error.error._links.oauth2Login.href)
return caught;
}

Expand Down
84 changes: 44 additions & 40 deletions test/docker-compose.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const os = require("os");
const arch = os.arch();
const withLocalApps = !!process.env.WITH_LOCAL_APPS;
const dockerNetwork = process.env.DOCKER_NETWORK;
const workspaceRoot = process.env.WORKSPACE_ROOT ?? "..";

Expand All @@ -25,53 +26,56 @@ const config = {
},
ports: ["9734:5432"],
},
client: {
image: "mucsi96/training-log-pro-client",
healthcheck: {
test: ["CMD", "health-check"],
interval: "10s",
timeout: "30s",
retries: 5,
start_period: "1s",
},
},
server: {
image: "mucsi96/training-log-pro-server",
environment: {
POSTGRES_HOSTNAME: "test-db",
POSTGRES_PORT: 5432,
POSTGRES_DB: "training-log",
POSTGRES_PASSWORD: "postgres",
POSTGRES_USER: "postgres",
SPRING_ACTUATOR_PORT: 8082,
SPRING_ADMIN_SERVER_HOST: "localhost",
SPRING_ADMIN_SERVER_PORT: 9090,
WEBDRIVER_API_URI: "http://chrome:4444/chrome/wd/hub",
WITHINGS_ACCOUNTS_URI: "http://mock-withings:8080/withings",
WITHINGS_API_URI: "http://mock-withings:8080/withings",
WITHINGS_CLIENT_ID: "withings-client-id",
WITHINGS_CLIENT_SECRET: "withings-client-secret",
STRAVA_API_URI: "http://mock-strava:8080/strava",
STRAVA_CLIENT_ID: "strava-client-id",
STRAVA_CLIENT_SECRET: "strava-client-secret",
},
healthcheck: {
test: ["CMD", "health-check"],
interval: "10s",
timeout: "30s",
retries: 5,
start_period: "1s",
...(!withLocalApps && {
client: {
image: "mucsi96/training-log-pro-client",
healthcheck: {
test: ["CMD", "health-check"],
interval: "10s",
timeout: "30s",
retries: 5,
start_period: "1s",
},
},
depends_on: {
chrome: {
condition: "service_healthy",
server: {
image: "mucsi96/training-log-pro-server",
environment: {
POSTGRES_HOSTNAME: "test-db",
POSTGRES_PORT: 5432,
POSTGRES_DB: "training-log",
POSTGRES_PASSWORD: "postgres",
POSTGRES_USER: "postgres",
SPRING_ACTUATOR_PORT: 8082,
SPRING_ADMIN_SERVER_HOST: "localhost",
SPRING_ADMIN_SERVER_PORT: 9090,
WEBDRIVER_API_URI: "http://chrome:4444/chrome/wd/hub",
WITHINGS_ACCOUNTS_URI: "http://mock-withings:8080/withings",
WITHINGS_API_URI: "http://mock-withings:8080/withings",
WITHINGS_CLIENT_ID: "withings-client-id",
WITHINGS_CLIENT_SECRET: "withings-client-secret",
STRAVA_API_URI: "http://mock-strava:8080/strava",
STRAVA_CLIENT_ID: "strava-client-id",
STRAVA_CLIENT_SECRET: "strava-client-secret",
},
healthcheck: {
test: ["CMD", "health-check"],
interval: "10s",
timeout: "30s",
retries: 5,
start_period: "1s",
},
depends_on: {
chrome: {
condition: "service_healthy",
},
},
},
},
}),
traefik_dynamic_conf: {
build: "./reverse_proxy",
environment: {
DOCKER_NETWORK: process.env.DOCKER_NETWORK,
WITH_LOCAL_APPS: process.env.WITH_LOCAL_APPS,
},
},
"reverse-proxy": {
Expand Down
17 changes: 7 additions & 10 deletions test/mock_strava/get_access_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ async function get_access_token(request, response) {
});
return response.end(
JSON.stringify({
status: 0,
body: {
token_type: "Bearer",
expires_at: 1568775134,
expires_in: 21600,
refresh_token: "test-refresh-token",
access_token: "test-access-token",
athlete: {
id: 2323,
},
token_type: "Bearer",
expires_at: Date.now() / 1000 + 21600,
expires_in: 21600,
refresh_token: "test-refresh-token",
access_token: "test-access-token",
athlete: {
id: 2323,
},
})
);
Expand Down
14 changes: 7 additions & 7 deletions test/reverse_proxy/traefik_dynamic_conf.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const { createServer } = require("http");
const PORT = 8080;
const server = createServer();

const entrypoint = process.env.DOCKER_NETWORKE
const withLocalApps = !!process.env.WITH_LOCAL_APPS;
const entrypoint = process.env.DOCKER_NETWORK && !withLocalApps
? "http://reverse-proxy"
: "http://localhost:9780";

console.log('Configuration:', { withLocalApps, entrypoint })

const routers = {
client: {
entryPoints: ["web"],
Expand Down Expand Up @@ -84,7 +86,7 @@ const services = {
loadBalancer: {
servers: [
{
url: "http://client:80",
url: withLocalApps ? "http://app:4200" : "http://client:80",
},
],
},
Expand All @@ -93,7 +95,7 @@ const services = {
loadBalancer: {
servers: [
{
url: "http://server:8080",
url: withLocalApps ? "http://app:8080" : "http://server:8080",
},
],
},
Expand Down Expand Up @@ -137,8 +139,6 @@ const services = {
};

server.on("request", async (request, response) => {
console.log(request.url);

response.end(
JSON.stringify({
http: {
Expand All @@ -154,5 +154,5 @@ process.on("SIGINT", () => server.close(() => process.exit()));
process.on("SIGTERM", () => server.close(() => process.exit()));

server.listen(PORT, () => {
console.log(`starting server at port ${PORT}`);
console.log(`starting server on port ${PORT}`);
});

0 comments on commit a7dba32

Please sign in to comment.