Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import java.util.Set;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
import software.amazon.awssdk.services.ssm.SsmClient;
import software.amazon.awssdk.services.ssm.model.ParameterMetadata;
Expand Down Expand Up @@ -56,13 +54,6 @@ protected EnvironmentRepositoryFixture fixture() {
return this.fixture;
}

@Override
@Test
@Disabled("TODO-issue: The default profile is always included, even when another profile is active")
public void activeProfileExcludesDefaultProfileFiles() throws Exception {
super.activeProfileExcludesDefaultProfileFiles();
}

static class Fixture implements EnvironmentRepositoryFixture {

private final AwsParameterStoreEnvironmentProperties properties = new AwsParameterStoreEnvironmentProperties();
Expand Down Expand Up @@ -92,7 +83,7 @@ public EnvironmentRepository repository() {

@Override
public Set<Capability> capabilities() {
return EnumSet.of(Capability.DISTINCT_DEFAULT_PROFILE);
return EnumSet.of(Capability.DISTINCT_DEFAULT_PROFILE, Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public EnvironmentRepository repository() {

@Override
public Set<Capability> capabilities() {
return EnumSet.allOf(Capability.class);
return EnumSet.complementOf(EnumSet.of(Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import java.util.Set;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse;
Expand Down Expand Up @@ -58,13 +56,6 @@ protected EnvironmentRepositoryFixture fixture() {
return this.fixture;
}

@Override
@Test
@Disabled("TODO-issue: The default profile is always included, even when another profile is active")
public void activeProfileExcludesDefaultProfileFiles() throws Exception {
super.activeProfileExcludesDefaultProfileFiles();
}

static class Fixture implements EnvironmentRepositoryFixture {

private final AwsSecretsManagerEnvironmentProperties properties = new AwsSecretsManagerEnvironmentProperties();
Expand Down Expand Up @@ -113,7 +104,7 @@ public EnvironmentRepository repository() {
@Override
public Set<Capability> capabilities() {
return EnumSet.of(Capability.LABELS, Capability.MULTIPLE_LABELS, Capability.MULTIPLE_APPLICATIONS,
Capability.DISTINCT_DEFAULT_PROFILE);
Capability.DISTINCT_DEFAULT_PROFILE, Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ public enum Capability {
*/
DISTINCT_DEFAULT_PROFILE,

/**
* Configuration for the {@code default} profile is applied even when another profile
* is active, as a layer shared by all profiles. Spring Boot only applies it when no
* other profile is active, so this is a deliberate, documented difference. Only
* meaningful together with {@link #DISTINCT_DEFAULT_PROFILE}.
*/
DEFAULT_PROFILE_ALWAYS_ACTIVE,

/**
* A {@code .properties} and a {@code .yml} file with the same name can exist at the
* same location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.cloud.config.server.environment.compliance.ConfigFile.Format;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
Expand Down Expand Up @@ -100,6 +101,7 @@ public void defaultProfileResolvesDefaultProfileFilesFirst() throws Exception {
@Test
public void activeProfileExcludesDefaultProfileFiles() throws Exception {
assumeCapabilities(Capability.DISTINCT_DEFAULT_PROFILE);
assumeNoCapability(Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE);
store("orders", null);
store("application", null);
store("orders", "default");
Expand All @@ -108,6 +110,19 @@ public void activeProfileExcludesDefaultProfileFiles() throws Exception {
assertPrecedence(findOne("orders", "dev", null), "orders-dev", "orders", "application");
}

@Test
public void defaultProfileFilesAreAppliedWhenAnotherProfileIsActive() throws Exception {
assumeCapabilities(Capability.DISTINCT_DEFAULT_PROFILE, Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE);
store("orders", null);
store("application", null);
store("orders", "default");
store("application", "default");
store("orders", "dev");

assertPrecedence(findOne("orders", "dev", null), "orders-dev", "orders-default", "application-default",
"orders", "application");
}

@Test
public void profileSpecificFilesTakePrecedenceOverFilesWithoutProfile() throws Exception {
store("orders", null);
Expand Down Expand Up @@ -314,6 +329,14 @@ protected Environment findOne(String application, String profile, String label)
return fixture().repository().findOne(application, profile, label);
}

/**
* Skip the current scenario if the fixture supports the capability.
* @param capability the capability that makes the scenario not applicable
*/
protected void assumeNoCapability(Capability capability) {
assumeFalse(fixture().capabilities().contains(capability), () -> "Fixture has capability " + capability);
}

/**
* Skip the current scenario unless the fixture supports all the capabilities.
* @param capabilities the required capabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void store(ConfigFile file) throws IOException {

@Override
public Set<Capability> capabilities() {
return EnumSet.allOf(Capability.class);
return EnumSet.complementOf(EnumSet.of(Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private Path realDir() throws IOException {

@Override
public Set<Capability> capabilities() {
return EnumSet.allOf(Capability.class);
return EnumSet.complementOf(EnumSet.of(Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private Path realDir() throws IOException {

@Override
public Set<Capability> capabilities() {
return EnumSet.allOf(Capability.class);
return EnumSet.complementOf(EnumSet.of(Capability.DEFAULT_PROFILE_ALWAYS_ACTIVE));
}

}
Expand Down
Loading