mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Add test coverage
This commit is contained in:
19
pom.xml
19
pom.xml
@@ -140,6 +140,25 @@
|
|||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.11</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import jakarta.persistence.JoinColumn;
|
|||||||
import jakarta.persistence.PrePersist;
|
import jakarta.persistence.PrePersist;
|
||||||
import jakarta.persistence.PreUpdate;
|
import jakarta.persistence.PreUpdate;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|||||||
@@ -1586,6 +1586,12 @@ button:disabled:hover {
|
|||||||
|
|
||||||
.asset-row .meta {
|
.asset-row .meta {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.asset-row strong {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.asset-item .meta {
|
.asset-item .meta {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package dev.kruhlmann.imgfloat.config;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
class SystemEnvironmentValidatorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validateSkipsWhenBootstrappedForTests() {
|
||||||
|
Environment environment = new MockEnvironment().withProperty(
|
||||||
|
"org.springframework.boot.test.context.SpringBootTestContextBootstrapper",
|
||||||
|
"true"
|
||||||
|
);
|
||||||
|
SystemEnvironmentValidator validator = new SystemEnvironmentValidator(environment);
|
||||||
|
|
||||||
|
assertThatCode(validator::validate).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validateThrowsWhenRequiredFieldsMissing() {
|
||||||
|
Environment environment = new MockEnvironment();
|
||||||
|
SystemEnvironmentValidator validator = new SystemEnvironmentValidator(environment);
|
||||||
|
setRequiredFields(validator);
|
||||||
|
ReflectionTestUtils.setField(validator, "twitchClientId", "");
|
||||||
|
|
||||||
|
assertThatThrownBy(validator::validate)
|
||||||
|
.isInstanceOf(IllegalStateException.class)
|
||||||
|
.hasMessageContaining("TWITCH_CLIENT_ID");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validateAcceptsAllRequiredFields() {
|
||||||
|
Environment environment = new MockEnvironment();
|
||||||
|
SystemEnvironmentValidator validator = new SystemEnvironmentValidator(environment);
|
||||||
|
setRequiredFields(validator);
|
||||||
|
|
||||||
|
assertThatCode(validator::validate).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRequiredFields(SystemEnvironmentValidator validator) {
|
||||||
|
ReflectionTestUtils.setField(validator, "twitchClientId", "client-id");
|
||||||
|
ReflectionTestUtils.setField(validator, "twitchClientSecret", "client-secret");
|
||||||
|
ReflectionTestUtils.setField(validator, "springMaxFileSize", "10MB");
|
||||||
|
ReflectionTestUtils.setField(validator, "springMaxRequestSize", "12MB");
|
||||||
|
ReflectionTestUtils.setField(validator, "assetsPath", "/tmp/assets");
|
||||||
|
ReflectionTestUtils.setField(validator, "previewsPath", "/tmp/previews");
|
||||||
|
ReflectionTestUtils.setField(validator, "dbPath", "/tmp/db");
|
||||||
|
ReflectionTestUtils.setField(validator, "initialSysadmin", "admin");
|
||||||
|
ReflectionTestUtils.setField(validator, "githubOwner", "owner");
|
||||||
|
ReflectionTestUtils.setField(validator, "githubRepo", "repo");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package dev.kruhlmann.imgfloat.util;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class LogSanitizerTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sanitizeReturnsNullForNullInput() {
|
||||||
|
assertThat(LogSanitizer.sanitize(null)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sanitizeReplacesNewlinesWithUnderscores() {
|
||||||
|
assertThat(LogSanitizer.sanitize("alpha\nBravo\r\ncharlie")).isEqualTo("alpha_Bravo_charlie");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sanitizeLeavesStringsWithoutNewlinesUntouched() {
|
||||||
|
assertThat(LogSanitizer.sanitize("no-newlines-here")).isEqualTo("no-newlines-here");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user