Skip to content

Commit

Permalink
feat: #98 Getting partial mocl URL paths
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
  • Loading branch information
lbroudoux committed Feb 11, 2025
1 parent ac40c4c commit 5a73fb4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/microcks-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe("MicrocksContainer", () => {
let baseGrpcUrl = container.getGrpcMockEndpoint();
expect("grpc://" + container.getHost() + ":" + container.getMappedPort(9090)).toBe(baseGrpcUrl);

let baseWsPath = container.getSoapMockEndpointPath("Pastries Service", "1.0");
expect("/soap/Pastries Service/1.0").toBe(baseWsPath);

let baseApiPath = container.getRestMockEndpointPath("API Pastries", "0.0.1");
expect("/rest/API Pastries/0.0.1").toBe(baseApiPath);

let baseGraphPath = container.getGraphQLMockEndpointPath("Pastries Graph", "1");
expect("/graphql/Pastries Graph/1").toBe(baseGraphPath);

// Check available services loaded including snapshot.
var services = await fetch(container.getHttpEndpoint() + "/api/services");
expect(services.status).toBe(200);
Expand Down
30 changes: 30 additions & 0 deletions src/microcks-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
return `http://${this.getHost()}:${this.httpPort}/soap/${service}/${version}`;
}

/**
* Get the exposed mock endpoint path for a SOAP service.
* @param {String} service The name of Service/API
* @param {String} version The version of Service/API
* @returns A usable endpoint to interact with Microcks mocks - starts with '/'.
*/
public getSoapMockEndpointPath(service: string, version: string): string {
return `/soap/${service}/${version}`;
}

/**
* Get the exposed mock endpoint for a REST API.
* @param {String} service The name of Service/API
Expand All @@ -327,6 +337,16 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
return `http://${this.getHost()}:${this.httpPort}/rest/${service}/${version}`;
}

/**
* Get the exposed mock endpoint path for a REST API.
* @param {String} service The name of Service/API
* @param {String} version The version of Service/API
* @returns A usable endpoint to interact with Microcks mocks - starts with '/'.
*/
public getRestMockEndpointPath(service: string, version: string): string {
return `/rest/${service}/${version}`;
}

/**
* Get the exposed mock endpoint for a GraphQL API.
* @param {String} service The name of Service/API
Expand All @@ -337,6 +357,16 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
return `http://${this.getHost()}:${this.httpPort}/graphql/${service}/${version}`;
}

/**
* Get the exposed mock endpoint path for a GraphQL API.
* @param {String} service The name of Service/API
* @param {String} version The version of Service/API
* @returns A usable endpoint to interact with Microcks mocks - starts with '/'.
*/
public getGraphQLMockEndpointPath(service: string, version: string): string {
return `/graphql/${service}/${version}`;
}

/**
* Get the exposed mock endpoint for a gRPC API.
* @returns A usable endpoint to interact with Microcks mocks
Expand Down
16 changes: 11 additions & 5 deletions src/microcks-containers-ensemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import {
} from "./microcks-async-minion-container";

export class MicrocksContainersEnsemble {
static readonly MICROCKS_CONTAINER_ALIAS = "microcks";
static readonly POSTMAN_CONTAINER_ALIAS = "postman";
static readonly MICROCKS_ASYNC_MINION_CONTAINER_ALIAS = "microcks-async-minion";

private network: StartedNetwork;
private microcksContainer: MicrocksContainer;
private postmanContainer?: GenericContainer;
Expand All @@ -31,11 +35,13 @@ export class MicrocksContainersEnsemble {

this.microcksContainer = new MicrocksContainer(image)
.withNetwork(this.network)
.withNetworkAliases("microcks")
.withNetworkAliases(MicrocksContainersEnsemble.MICROCKS_CONTAINER_ALIAS)
.withEnvironment({
POSTMAN_RUNNER_URL: "http://postman:3000",
TEST_CALLBACK_URL: "http://microcks:8080",
ASYNC_MINION_URL: "http://microcks-async-minion:" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT,
POSTMAN_RUNNER_URL: "http://" + MicrocksContainersEnsemble.POSTMAN_CONTAINER_ALIAS + ":3000",
TEST_CALLBACK_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_CONTAINER_ALIAS
+ ":" + MicrocksContainer.MICROCKS_HTTP_PORT,
ASYNC_MINION_URL: "http://" + MicrocksContainersEnsemble.MICROCKS_ASYNC_MINION_CONTAINER_ALIAS
+ ":" + MicrocksAsyncMinionContainer.MICROCKS_ASYNC_MINION_HTTP_PORT,
});
}

Expand All @@ -47,7 +53,7 @@ export class MicrocksContainersEnsemble {
public withPostman(image = "quay.io/microcks/microcks-postman-runtime:latest"): this {
this.postmanContainer = new GenericContainer(image)
.withNetwork(this.network)
.withNetworkAliases("postman")
.withNetworkAliases(MicrocksContainersEnsemble.POSTMAN_CONTAINER_ALIAS)
.withWaitStrategy(Wait.forLogMessage(/.*postman-runtime wrapper listening on port.*/, 1));
return this;
}
Expand Down

0 comments on commit 5a73fb4

Please sign in to comment.