Skip to content

Commit

Permalink
Prevent duplicate profiles (#1062)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Dec 17, 2023
1 parent 6d1db48 commit 4da4b0c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.OptionalInt;
Expand Down Expand Up @@ -213,10 +214,10 @@ public OptionalInt getPriority() {
}

private List<String> getProfile(final ConfigSourceInterceptorContext context) {
List<String> profiles = new ArrayList<>();
Set<String> profiles = new LinkedHashSet<>();
profiles.addAll(getProfiles(context, SMALLRYE_CONFIG_PROFILE_PARENT));
profiles.addAll(getProfiles(context, SMALLRYE_CONFIG_PROFILE));
return profiles;
return new ArrayList<>(profiles);
}

private List<String> getProfiles(final ConfigSourceInterceptorContext context, final String propertyName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -502,6 +503,18 @@ void multipleProfileProperty() {
assertEquals("double", common.getRawValue("triple.prop"));
}

@Test
void duplicatedProfilesActive() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.withSources(config(SMALLRYE_CONFIG_PROFILE, "prod,kubernetes"))
.withSources(config(SMALLRYE_CONFIG_PROFILE_PARENT, "cluster"))
.withSources(config("%kubernetes." + SMALLRYE_CONFIG_PROFILE_PARENT, "cluster"))
.build();

assertIterableEquals(List.of("kubernetes", "prod", "cluster"), config.getProfiles());
}

private static SmallRyeConfig buildConfig(String... keyValues) {
return new SmallRyeConfigBuilder()
.addDefaultInterceptors()
Expand Down

0 comments on commit 4da4b0c

Please sign in to comment.