mirror of
https://github.com/iflytek/skillhub.git
synced 2026-08-27 11:14:59 +00:00
test(ratelimit): verify environment variable binding
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
This commit is contained in:
parent
a46c0b9bb2
commit
80a7e83a0a
1 changed files with 23 additions and 0 deletions
|
|
@ -2,10 +2,18 @@ package com.iflytek.skillhub.config;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.SystemEnvironmentPropertySource;
|
||||
|
||||
class RateLimitPropertiesTest {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(TestConfiguration.class);
|
||||
|
||||
@Test
|
||||
void enabledByDefaultAndNoOverrides() {
|
||||
RateLimitProperties properties = new RateLimitProperties();
|
||||
|
|
@ -51,4 +59,19 @@ class RateLimitPropertiesTest {
|
|||
// A different category is unaffected.
|
||||
assertThat(properties.authenticatedFor("download", 120)).isEqualTo(120);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindsDocumentedCategoryOverrideFromEnvironmentVariable() {
|
||||
// The *-systemEnvironment suffix activates Spring Boot's environment-variable name adaptation.
|
||||
contextRunner.withInitializer(context -> context.getEnvironment().getPropertySources().addFirst(
|
||||
new SystemEnvironmentPropertySource("test-systemEnvironment", Map.of(
|
||||
"SKILLHUB_RATELIMIT_CATEGORIES_SEARCH_AUTHENTICATED", "120"))))
|
||||
.run(context -> assertThat(context.getBean(RateLimitProperties.class)
|
||||
.authenticatedFor("search", 60)).isEqualTo(120));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(RateLimitProperties.class)
|
||||
static class TestConfiguration {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue