Skip to content

Commit 8de8bb2

Browse files
committed
Fix: 파일 컨트롤러 테스트 수정
문제 - 컨트롤러 테스트에서 S3Mock에 사용하는 포트를 점유하는 문제 발생 -> 서비스 테스트에서 S3Mock을 생성하지 못함 해결 - 컨트롤러 테스트가 끝나면 S3Mock의 포트를 해체 시켜 해당 문제 해결
1 parent 5c12d79 commit 8de8bb2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/test/java/com/back/domain/file/config/S3MockConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class S3MockConfig {
2121

2222
@Bean
2323
public S3Mock s3Mock() {
24-
return new S3Mock.Builder().withPort(0).withInMemoryBackend().build();
24+
return new S3Mock.Builder().withPort(8001).withInMemoryBackend().build();
2525
}
2626

2727
@Bean

src/test/java/com/back/domain/file/controller/FileControllerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.back.domain.user.entity.UserStatus;
99
import com.back.domain.user.repository.UserRepository;
1010
import com.back.fixture.TestJwtTokenProvider;
11+
import io.findify.s3mock.S3Mock;
12+
import org.junit.jupiter.api.AfterEach;
1113
import org.junit.jupiter.api.DisplayName;
1214
import org.junit.jupiter.api.Test;
1315
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +39,9 @@ class FileControllerTest {
3739
@Autowired
3840
private MockMvc mvc;
3941

42+
@Autowired
43+
private S3Mock s3Mock;
44+
4045
@Autowired
4146
private UserRepository userRepository;
4247

@@ -57,6 +62,11 @@ private String generateAccessToken(User user) {
5762
);
5863
}
5964

65+
@AfterEach
66+
public void tearDown() {
67+
s3Mock.stop();
68+
}
69+
6070
@Test
6171
@DisplayName("파일 업로드 성공")
6272
void uploadFile_success() throws Exception {

0 commit comments

Comments
 (0)