refactor(cdn): CDN URL 변환 함수를 공통화한다
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.common.domain
|
||||||
|
|
||||||
|
fun String?.toCdnUrl(cloudFrontHost: String): String? {
|
||||||
|
if (isNullOrBlank()) return null
|
||||||
|
if (startsWith("https://") || startsWith("http://")) return this
|
||||||
|
return "$cloudFrontHost/$this"
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.common.domain
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class CdnUrlExtensionsTest {
|
||||||
|
private val cloudFrontHost = "https://cdn.test"
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("CDN URL 변환은 null과 blank를 null로 반환한다")
|
||||||
|
fun shouldReturnNullForNullOrBlankPath() {
|
||||||
|
assertEquals(null, null.toCdnUrl(cloudFrontHost))
|
||||||
|
assertEquals(null, "".toCdnUrl(cloudFrontHost))
|
||||||
|
assertEquals(null, " ".toCdnUrl(cloudFrontHost))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("CDN URL 변환은 절대 URL을 그대로 반환한다")
|
||||||
|
fun shouldKeepAbsoluteUrl() {
|
||||||
|
assertEquals(
|
||||||
|
"https://image.test/profile.png",
|
||||||
|
"https://image.test/profile.png".toCdnUrl(cloudFrontHost)
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"http://image.test/profile.png",
|
||||||
|
"http://image.test/profile.png".toCdnUrl(cloudFrontHost)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("CDN URL 변환은 상대 path 앞에 CloudFront host를 붙인다")
|
||||||
|
fun shouldPrependCloudFrontHostToRelativePath() {
|
||||||
|
assertEquals(
|
||||||
|
"https://cdn.test/profile/default-profile.png",
|
||||||
|
"profile/default-profile.png".toCdnUrl(cloudFrontHost)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user