-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #5
- Loading branch information
Showing
9 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { afterEach, describe, expect, it } from "@jest/globals"; | ||
import { MinioExtension } from "../../src"; | ||
|
||
describe("MinioExtension", () => { | ||
afterEach(async () => { | ||
if (global.MINIO_CONTAINER) { | ||
await global.MINIO_CONTAINER.stop(); | ||
global.MINIO_CONTAINER = undefined; | ||
} | ||
}); | ||
|
||
describe("startMinioContainer", () => { | ||
it("should start the minio container", async () => { | ||
await MinioExtension.startMinioSearchContainer( | ||
"minioadmin", | ||
"keyboard cat", | ||
); | ||
|
||
expect(global.MINIO_CONTAINER).toBeDefined(); | ||
|
||
await global.MINIO_CONTAINER.stop(); | ||
}, 60_000); | ||
}); | ||
|
||
describe("stopMinioContainer", () => { | ||
it("should stop the minio container", async () => { | ||
await MinioExtension.startMinioSearchContainer( | ||
"minioadmin", | ||
"keyboard cat", | ||
); | ||
await MinioExtension.stopMinioSearchContainer(); | ||
|
||
expect(global.MINIO_CONTAINER).toBeUndefined(); | ||
}, 60_000); | ||
|
||
it("should throw error when container is not previously started", () => { | ||
expect(MinioExtension.stopMinioSearchContainer()).rejects.toEqual( | ||
Error( | ||
"IllegalStateException: Minio container has not been previously started", | ||
), | ||
); | ||
|
||
expect(global.MINIO_CONTAINER).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe("getMinioPort", () => { | ||
it("should return the mapped port for the started container", async () => { | ||
await MinioExtension.startMinioSearchContainer( | ||
"minioadmin", | ||
"keyboard cat", | ||
); | ||
|
||
const port = MinioExtension.getMinioPort(); | ||
expect(port).toBeGreaterThan(0); | ||
}, 60_000); | ||
|
||
it("should throw error when container is not previously started", () => { | ||
expect(() => MinioExtension.getMinioPort()).toThrow( | ||
"IllegalStateException: Minio container has not been previously started", | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { MongoExtension } from "./mongo/mongo-extension"; | ||
export { PostgresExtension } from "./postgres/postgres-extension"; | ||
export { ElasticSearchExtension } from "./elasticsearch/elastic-search-extension"; | ||
export { MinioExtension } from "./minio/minio-extension"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { KiwiPreconditions } from "@kiwiproject/kiwi-js"; | ||
import { GenericContainer, Wait } from "testcontainers"; | ||
|
||
async function startMinioSearchContainer(accessKey: string, secretKey: string) { | ||
global.MINIO_CONTAINER = await new GenericContainer( | ||
"quay.io/minio/minio:latest", | ||
) | ||
.withEnvironment({ | ||
MINIO_BROWSER: "off", | ||
MINIO_ROOT_USER: accessKey, | ||
MINIO_ROOT_PASSWORD: secretKey, | ||
}) | ||
.withExposedPorts(9000) | ||
.withWaitStrategy( | ||
Wait.forAll([Wait.forListeningPorts(), Wait.forLogMessage(/1 Online/)]), | ||
) | ||
.withTmpFs({ "/data": "rw,noexec,nosuid" }) | ||
.withCommand(["server", "/data"]) | ||
.start(); | ||
} | ||
|
||
async function stopMinioSearchContainer() { | ||
KiwiPreconditions.checkState( | ||
global.MINIO_CONTAINER !== undefined, | ||
"Minio container has not been previously started", | ||
); | ||
await global.MINIO_CONTAINER.stop(); | ||
global.MINIO_CONTAINER = undefined; | ||
} | ||
|
||
function getMinioPort(): number { | ||
KiwiPreconditions.checkState( | ||
global.MINIO_CONTAINER !== undefined, | ||
"Minio container has not been previously started", | ||
); | ||
|
||
return global.MINIO_CONTAINER.getMappedPort(9000); | ||
} | ||
|
||
export const MinioExtension = { | ||
startMinioSearchContainer, | ||
stopMinioSearchContainer, | ||
getMinioPort, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters