-
Notifications
You must be signed in to change notification settings - Fork 1
fix: .env 파일을 로드하도록 수정 완료 #8
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
Conversation
|
Summary by CodeRabbit
Summary by CodeRabbit
Walkthrough이번 변경에서는 환경 변수 유틸리티 클래스에서 Dotenv 인스턴스의 초기화 방식을 단순화하여, Changes
Assessment against linked issues
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main/java/org/sopt/makers/global/util/EnvUtil.java(1 hunks)src/test/java/org/sopt/makers/global/util/EnvUtilTest.java(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: sentry-notifier-lambda-ci
src/test/java/org/sopt/makers/global/util/EnvUtilTest.java
[error] 54-54: Test failure: Exception thrown when querying Webhook URL with a non-existent key (org.opentest4j.AssertionFailedError).
[error] 48-48: Test failure: Failed to retrieve Webhook URL from a valid key (org.opentest4j.AssertionFailedError).
[error] 96-96: Test failure: Case-insensitive key recognition failed (org.opentest4j.AssertionFailedError).
[error] 96-96: Test failure: Case-insensitive key recognition failed (org.opentest4j.AssertionFailedError).
[error] 96-96: Test failure: Case-insensitive key recognition failed (org.opentest4j.AssertionFailedError).
[error] 90-90: Test failure: WebhookUrlNotFoundException thrown for case-insensitive key recognition (org.sopt.makers.global.exception.unchecked.WebhookUrlNotFoundException).
[error] 90-90: Test failure: WebhookUrlNotFoundException thrown for case-insensitive key recognition (org.sopt.makers.global.exception.unchecked.WebhookUrlNotFoundException).
[error] 90-90: Test failure: WebhookUrlNotFoundException thrown for case-insensitive key recognition (org.sopt.makers.global.exception.unchecked.WebhookUrlNotFoundException).
🔇 Additional comments (2)
src/main/java/org/sopt/makers/global/util/EnvUtil.java (1)
18-18:Details
❓ Verification inconclusive
Dotenv 구성이 단순화되었습니다.
Dotenv의 초기화 방식이 단순화되어 명시적인 디렉토리 설정 없이 기본 로드 메커니즘을 사용하도록 변경되었습니다. 이 변경으로
.env파일은 클래스패스에서 자동으로 로드될 것입니다.변경된 코드가 제대로 동작하는지 확인하기 위해 다음 스크립트를 실행해보세요:
🏁 Script executed:
#!/bin/bash # .env 파일의 실제 위치 확인 find . -name ".env" -type f | sortLength of output: 34
Dotenv 기본 로드 검증이 필요합니다
현재
find . -name ".env" -type f명령으로.env파일을 찾을 수 없어, 기본 로드 메커니즘이 제대로 동작하는지 확인이 불가능한 상태입니다.
다음 중 하나를 수행해 주세요:
- 실제
.env파일이 저장된 경로를 다시 확인하고 그 위치를 기반으로 테스트- 애플리케이션을 실행해 환경 변수가 정상적으로 로드되는지 직접 검증
src/test/java/org/sopt/makers/global/util/EnvUtilTest.java (1)
25-25: 환경 변수 파일 경로가 테스트 리소스 디렉토리로 변경되었습니다.환경 변수 파일의 경로가
src/main/resources/.env에서src/test/resources/.env로 변경되었습니다. 이는EnvUtil클래스의 Dotenv 로드 방식 변경과 일치하도록 조정한 것입니다.
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.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/test/java/org/sopt/makers/global/util/TestEnvUtil.java (3)
10-15: 클래스 가시성과 Dotenv 구성에 대한 검토이 클래스는 패키지 프라이빗(default visibility)으로 선언되어 있습니다. 이는 의도적인 설계일 수 있지만, 다른 패키지의 테스트에서 재사용하기 어려울 수 있습니다. 또한 Dotenv의 경로가 하드코딩되어 있어 테스트 리소스 구조가 변경될 경우 수정이 필요합니다.
-class TestEnvUtil { +public class TestEnvUtil {또한 Dotenv 경로를 상수로 추출하거나 설정 가능하게 만드는 것을 고려해보세요:
+private static final String TEST_RESOURCES_PATH = "src/test/resources"; private static final Dotenv dotenv = Dotenv.configure() - .directory("src/test/resources") + .directory(TEST_RESOURCES_PATH) .load();
28-47: getWebhookUrl 메서드 관련 제안메서드 구현은 전반적으로 견고하나, 몇 가지 개선 사항이 있습니다:
- 매개변수 검증 로직을 별도의 메서드로 추출하면 코드 가독성이 향상될 것입니다.
- 예외 메시지에 어떤 매개변수가 잘못되었는지 구체적인 정보를 포함하면 디버깅에 도움이 됩니다.
- 환경 변수 키 구성 로직도 별도 메서드로 추출하면 더 명확해질 것입니다.
public static String getWebhookUrl(String service, String team, String stage, String type) { - if (service == null || team == null || stage == null || type == null) { - throw InvalidEnvParameterException.from(ErrorMessage.INVALID_ENV_PARAMETER); - } + validateParameters(service, team, stage, type); String prefix = resolvePrefix(service.toLowerCase()); - String envKey = String.format("%s%s_%s_%s", - prefix, - team.toUpperCase(), - stage.toUpperCase(), - type.toUpperCase()); + String envKey = buildEnvKey(prefix, team, stage, type); String webhookUrl = dotenv.get(envKey); if (webhookUrl == null || webhookUrl.isBlank()) { - throw new WebhookUrlNotFoundException(ErrorMessage.WEBHOOK_URL_NOT_FOUND); + throw new WebhookUrlNotFoundException( + ErrorMessage.WEBHOOK_URL_NOT_FOUND.withArgs(envKey)); } return webhookUrl; } + +private static void validateParameters(String service, String team, String stage, String type) { + if (service == null || team == null || stage == null || type == null) { + throw InvalidEnvParameterException.from(ErrorMessage.INVALID_ENV_PARAMETER); + } +} + +private static String buildEnvKey(String prefix, String team, String stage, String type) { + return String.format("%s%s_%s_%s", + prefix, + team.toUpperCase(), + stage.toUpperCase(), + type.toUpperCase()); +}
49-55: resolvePrefix 메서드에 대한 피드백switch 표현식을 사용한 구현은 깔끔하지만, 새로운 서비스 타입을 추가할 때마다 코드를 수정해야 합니다. 더 확장 가능한 접근 방식을 고려해볼 수 있습니다.
다음과 같이 Map을 사용하여 구현할 수 있습니다:
+private static final Map<String, String> SERVICE_PREFIXES = Map.of( + "slack", SLACK_WEBHOOK_PREFIX, + "discord", DISCORD_WEBHOOK_PREFIX +); private static String resolvePrefix(String service) { - return switch (service) { - case "slack" -> SLACK_WEBHOOK_PREFIX; - case "discord" -> DISCORD_WEBHOOK_PREFIX; - default -> throw new UnsupportedServiceTypeException(ErrorMessage.UNSUPPORTED_SERVICE_TYPE); - }; + String prefix = SERVICE_PREFIXES.get(service); + if (prefix == null) { + throw new UnsupportedServiceTypeException( + ErrorMessage.UNSUPPORTED_SERVICE_TYPE.withArgs(service)); + } + return prefix; }이렇게 하면 지원되는 서비스 목록을 한 곳에서 관리할 수 있고, 새 서비스 추가 시 코드 변경 없이 Map에만 추가하면 됩니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/test/java/org/sopt/makers/global/util/EnvUtilTest.java(6 hunks)src/test/java/org/sopt/makers/global/util/TestEnvUtil.java(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/test/java/org/sopt/makers/global/util/EnvUtilTest.java
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/test/java/org/sopt/makers/global/util/TestEnvUtil.java (3)
src/main/java/org/sopt/makers/global/exception/unchecked/InvalidEnvParameterException.java (1)
InvalidEnvParameterException(5-14)src/main/java/org/sopt/makers/global/exception/unchecked/UnsupportedServiceTypeException.java (1)
UnsupportedServiceTypeException(5-13)src/main/java/org/sopt/makers/global/exception/unchecked/WebhookUrlNotFoundException.java (1)
WebhookUrlNotFoundException(5-13)
Related issue 🛠
Work Description ✏️
JAR 파일에서 .env의 위치 확인 후 해당 경로(루트)에서 읽도록 수정
Trouble Shooting ⚽️
테스트에서 getWebhookUrl 메서드를 호출하며 발생한 문제