Search in subdirectories of main config repo
... in addition to top level. That way users can organize their config files, e.g. by subsystem. Subdirectories have *higher* precedence than the top level. Users configure which subdirectories to search through spring.cloud.config.server.git.searchPaths (array or String, so csv in config file, default empty). Fixes gh-36
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.config.server;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.config.Environment;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private File basedir = new File("target/config");
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
if (basedir.exists()) {
|
||||
FileUtils.delete(basedir, FileUtils.RECURSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanilla() throws IOException {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo();
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
|
||||
.properties("spring.cloud.config.server.git.uri=" + uri).run();
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nested() throws IOException {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
|
||||
context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(false)
|
||||
.properties("spring.cloud.config.server.git.uri=" + uri,
|
||||
"spring.cloud.config.server.git.searchPaths=sub").run();
|
||||
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ PropertyPlaceholderAutoConfiguration.class, ConfigServerConfiguration.class })
|
||||
protected static class TestConfiguration {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
import org.junit.Before;
|
||||
@@ -57,6 +58,18 @@ public class JGitEnvironmentRepositoryTests {
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nested() throws IOException {
|
||||
String uri = ConfigServerTestUtils.prepareLocalRepo("another-config-repo");
|
||||
repository.setUri(uri);
|
||||
repository.setSearchPaths(new String[] {"sub"});
|
||||
repository.findOne("bar", "staging", "master");
|
||||
Environment environment = repository.findOne("bar", "staging", "master");
|
||||
assertEquals(2, environment.getPropertySources().size());
|
||||
assertEquals(repository.getUri() + "/sub/application.yml", environment
|
||||
.getPropertySources().get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void branch() {
|
||||
repository.setBasedir(basedir);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
foo: bar
|
||||
@@ -0,0 +1 @@
|
||||
Move application.yml to subdir
|
||||
@@ -0,0 +1,2 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge branch 'raw' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f not-for-merge tag 'foo' of dsyer@localhost:/home/dsyer/dev/platform/config/spring-platform-config-server/target/test-classes/config-repo
|
||||
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
@@ -0,0 +1,5 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
logallrefupdates = true
|
||||
[branch "raw"]
|
||||
@@ -0,0 +1,3 @@
|
||||
1 1
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
1
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer <dsyer@pivotal.io> 1415902155 +0000 checkout: moving from raw to master
|
||||
9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 c4bd92016dc14b9fe376d9c3f7af1c9d22d44ee4 Dave Syer <dsyer@pivotal.io> 1415902338 +0000 commit: Move application.yml to subdir
|
||||
@@ -0,0 +1,2 @@
|
||||
0000000000000000000000000000000000000000 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 Dave Syer <dsyer@gopivotal.com> 1406860776 -0700 branch: Created from 9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0
|
||||
9f01fb972bc9617e4ea59f5c8ee3ceb5ff515cd0 c4bd92016dc14b9fe376d9c3f7af1c9d22d44ee4 Dave Syer <dsyer@pivotal.io> 1415902338 +0000 commit: Move application.yml to subdir
|
||||
@@ -0,0 +1 @@
|
||||
0000000000000000000000000000000000000000 7df4a26d5437d9d4090cd5809967f870444cde8f Dave Syer <dsyer@gopivotal.com> 1406860717 -0700
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
x+)JMU01f040031QH,(<28><>LN,<2C><><EFBFBD>ӫ<EFBFBD><D3AB>ah<61>xH<78>S<EFBFBD>O<EFBFBD>}jI<6A><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><07><01>x<12>
|
||||
@@ -0,0 +1,2 @@
|
||||
x<01><>1
|
||||
1E<>s<EFBFBD><73><05>$<24><>
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
c4bd92016dc14b9fe376d9c3f7af1c9d22d44ee4
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
@@ -0,0 +1 @@
|
||||
7df4a26d5437d9d4090cd5809967f870444cde8f
|
||||
@@ -0,0 +1,2 @@
|
||||
info:
|
||||
foo: bar
|
||||
Reference in New Issue
Block a user