-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Presigned Url 생성 테스트 작성 (#209)
- Loading branch information
1 parent
0e448fb
commit c951802
Showing
3 changed files
with
69 additions
and
7 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
57 changes: 57 additions & 0 deletions
57
src/test/java/com/mallang/common/infra/s3/PresignedUrlServiceTest.java
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,57 @@ | ||
package com.mallang.common.infra.s3; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.testcontainers.containers.localstack.LocalStackContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
import software.amazon.awssdk.services.s3.presigner.S3Presigner.Builder; | ||
|
||
|
||
@Testcontainers | ||
@DisplayName("프리사인즈 URL 서비스 (PresignedUrlService) 은(는)") | ||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
class PresignedUrlServiceTest { | ||
|
||
@Container | ||
public LocalStackContainer localStackContainer = new LocalStackContainer( | ||
DockerImageName.parse("localstack/localstack")) | ||
.withServices(LocalStackContainer.Service.S3); | ||
|
||
@Test | ||
void 이미지_확장자를_받아_이미지_이름을_UUID로_생성_후_프리사인드_URL을_생성하여_반환한다() { | ||
// given | ||
AwsBasicCredentials awsBasicCredentials = AwsBasicCredentials.create( | ||
localStackContainer.getAccessKey(), | ||
localStackContainer.getSecretKey() | ||
); | ||
Builder presignerBuilder = S3Presigner.builder() | ||
.credentialsProvider(StaticCredentialsProvider.create(awsBasicCredentials)) | ||
.region(Region.of(localStackContainer.getRegion())); | ||
PresignedUrlService service = new PresignedUrlService( | ||
presignerBuilder, | ||
new AwsS3Property("mallang-bucket", "images/", 10) | ||
); | ||
|
||
// when | ||
CreatePresignedUrlResponse response = service.create("img"); | ||
|
||
// then | ||
assertThat(response.presignedUrl()).contains( | ||
"https://mallang-bucket.s3.amazonaws.com/", | ||
"images/" + response.imageName(), | ||
".img", | ||
"X-Amz-Expires=" + 60 * 10 | ||
); | ||
} | ||
} |