mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Improve error reporting
This commit is contained in:
@@ -56,12 +56,12 @@ class ChannelDirectoryServiceTest {
|
||||
setupInMemoryPersistence();
|
||||
Path assetRoot = Files.createTempDirectory("imgfloat-assets-test");
|
||||
Path previewRoot = Files.createTempDirectory("imgfloat-previews-test");
|
||||
AssetStorageService assetStorageService = new AssetStorageService(assetRoot.toString(), previewRoot.toString(), 26214400L);
|
||||
AssetStorageService assetStorageService = new AssetStorageService(assetRoot.toString(), previewRoot.toString());
|
||||
MediaPreviewService mediaPreviewService = new MediaPreviewService();
|
||||
MediaOptimizationService mediaOptimizationService = new MediaOptimizationService(mediaPreviewService);
|
||||
MediaDetectionService mediaDetectionService = new MediaDetectionService();
|
||||
service = new ChannelDirectoryService(channelRepository, assetRepository, messagingTemplate,
|
||||
assetStorageService, mediaDetectionService, mediaOptimizationService, 26214400L);
|
||||
assetStorageService, mediaDetectionService, mediaOptimizationService);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
package dev.kruhlmann.imgfloat;
|
||||
|
||||
import dev.kruhlmann.imgfloat.config.TwitchCredentialsValidator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class TwitchEnvironmentValidationTest {
|
||||
|
||||
@Test
|
||||
void failsToStartWhenTwitchCredentialsMissing() {
|
||||
assertThatThrownBy(() -> new SpringApplicationBuilder(ImgfloatApplication.class)
|
||||
.properties("server.port=0")
|
||||
.run())
|
||||
.hasRootCauseInstanceOf(IllegalArgumentException.class)
|
||||
.hasRootCauseMessage("Could not resolve placeholder 'TWITCH_CLIENT_ID' in value \"${TWITCH_CLIENT_ID}\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadsCredentialsFromDotEnvFile() {
|
||||
ConfigurableApplicationContext context = null;
|
||||
try {
|
||||
context = new SpringApplicationBuilder(ImgfloatApplication.class)
|
||||
.properties(
|
||||
"server.port=0",
|
||||
"spring.config.import=optional:file:src/test/resources/valid.env[.properties]")
|
||||
.run();
|
||||
ConfigurableApplicationContext finalContext = context;
|
||||
assertThatCode(() -> finalContext.getBean(TwitchCredentialsValidator.class))
|
||||
.doesNotThrowAnyException();
|
||||
} finally {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void stripsQuotesAndWhitespaceFromCredentials() {
|
||||
ConfigurableApplicationContext context = null;
|
||||
try {
|
||||
context = new SpringApplicationBuilder(ImgfloatApplication.class)
|
||||
.properties(
|
||||
"server.port=0",
|
||||
"TWITCH_CLIENT_ID=\" quoted-id \"",
|
||||
"TWITCH_CLIENT_SECRET=' quoted-secret '"
|
||||
)
|
||||
.run();
|
||||
|
||||
var clientRegistrationRepository = context.getBean(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository.class);
|
||||
var twitch = clientRegistrationRepository.findByRegistrationId("twitch");
|
||||
|
||||
org.assertj.core.api.Assertions.assertThat(twitch.getClientId()).isEqualTo("quoted-id");
|
||||
org.assertj.core.api.Assertions.assertThat(twitch.getClientSecret()).isEqualTo("quoted-secret");
|
||||
} finally {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class AssetStorageServiceTest {
|
||||
void setUp() throws IOException {
|
||||
assets = Files.createTempDirectory("asset-storage-service");
|
||||
previews = Files.createTempDirectory("preview-storage-service");
|
||||
service = new AssetStorageService(assets.toString(), previews.toString(), 26214400L);
|
||||
service = new AssetStorageService(assets.toString(), previews.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user