New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding MinIO module #7440
Adding MinIO module #7440
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. We will talk about the module tomorrow. I just left some suggestions for general review. No changes should be applied until further notice.
modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java
Outdated
Show resolved
Hide resolved
modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java
Outdated
Show resolved
Hide resolved
modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java
Outdated
Show resolved
Hide resolved
@frozenwizard Please, proceed making the changes. We discussed this Today and we will be hosting the module. Thanks again! |
@frozenwizard I forgot to ask but can you some docs, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add additional test switching another credentials and verify those were set in the container
MinIOContainer container = new MinIOContainer("minio/minio:latest"); | ||
container.start(); | ||
|
||
MinioClient minioClient = MinioClient | ||
.builder() | ||
.endpoint(container.getS3URL()) | ||
.credentials(container.getUserName(), container.getPassword()) | ||
.build(); | ||
|
||
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build()); | ||
|
||
BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build(); | ||
|
||
assertThat(minioClient.bucketExists(existsArgs)).isTrue(); | ||
|
||
URL file = this.getClass().getResource("/object_to_upload.txt"); | ||
assertThat(file).isNotNull(); | ||
ObjectWriteResponse upload = minioClient.uploadObject( | ||
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build() | ||
); | ||
|
||
StatObjectResponse objectStat = minioClient.statObject( | ||
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build() | ||
); | ||
|
||
assertThat(objectStat.object()).isEqualTo("my-objectname"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace latest
with a specific version
MinIOContainer container = new MinIOContainer("minio/minio:latest"); | |
container.start(); | |
MinioClient minioClient = MinioClient | |
.builder() | |
.endpoint(container.getS3URL()) | |
.credentials(container.getUserName(), container.getPassword()) | |
.build(); | |
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build()); | |
BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build(); | |
assertThat(minioClient.bucketExists(existsArgs)).isTrue(); | |
URL file = this.getClass().getResource("/object_to_upload.txt"); | |
assertThat(file).isNotNull(); | |
ObjectWriteResponse upload = minioClient.uploadObject( | |
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build() | |
); | |
StatObjectResponse objectStat = minioClient.statObject( | |
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build() | |
); | |
assertThat(objectStat.object()).isEqualTo("my-objectname"); | |
try(MinIOContainer container = new MinIOContainer("minio/minio:latest")) { | |
container.start(); | |
MinioClient minioClient = MinioClient | |
.builder() | |
.endpoint(container.getS3URL()) | |
.credentials(container.getUserName(), container.getPassword()) | |
.build(); | |
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build()); | |
BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build(); | |
assertThat(minioClient.bucketExists(existsArgs)).isTrue(); | |
URL file = this.getClass().getResource("/object_to_upload.txt"); | |
assertThat(file).isNotNull(); | |
ObjectWriteResponse upload = minioClient.uploadObject( | |
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build() | |
); | |
StatObjectResponse objectStat = minioClient.statObject( | |
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build() | |
); | |
assertThat(objectStat.object()).isEqualTo("my-objectname"); | |
} |
* <p> | ||
* Exposed ports: 9000,9001 | ||
*/ | ||
@Slf4j |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Slf4j |
* Constructs a MinIO container from the dockerImageName | ||
* @param dockerImageName the full image name to use | ||
*/ | ||
public MinIOContainer(@NonNull final String dockerImageName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public MinIOContainer(@NonNull final String dockerImageName) { | |
public MinIOContainer(final String dockerImageName) { |
|
||
URL file = this.getClass().getResource("/object_to_upload.txt"); | ||
assertThat(file).isNotNull(); | ||
ObjectWriteResponse upload = minioClient.uploadObject( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upload is not being used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general if an upload fails it throws an exception. If we get the upload object back then it was a success. I can make it more clear with a comment or remove the variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing the variable would be fine
Sure where would they go? |
docs can be added here and then update the mkdocs.yml in the root directory |
Thanks for your contribution, @frozenwizard ! I've made some changes to keep aligned with the image. Module will be release as part of the next release. |
This adds the MinIO container.